SetBucketLoggingCommand.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright (C) Alibaba Cloud Computing
  3. * All rights reserved.
  4. *
  5. * 版权所有 (C)阿里云计算有限公司
  6. */
  7. using System;
  8. using System.IO;
  9. using System.Collections.Generic;
  10. using Aliyun.OSS.Common.Communication;
  11. using Aliyun.OSS.Util;
  12. using Aliyun.OSS.Transform;
  13. namespace Aliyun.OSS.Commands
  14. {
  15. internal class SetBucketLoggingCommand : OssCommand
  16. {
  17. private readonly string _bucketName;
  18. private readonly SetBucketLoggingRequest _setBucketLoggingRequest;
  19. protected override HttpMethod Method
  20. {
  21. get { return HttpMethod.Put; }
  22. }
  23. protected override string Bucket
  24. {
  25. get { return _bucketName; }
  26. }
  27. private SetBucketLoggingCommand(IServiceClient client, Uri endpoint, ExecutionContext context,
  28. string bucketName, SetBucketLoggingRequest setBucketLoggingRequest)
  29. : base(client, endpoint, context)
  30. {
  31. OssUtils.CheckBucketName(setBucketLoggingRequest.BucketName);
  32. OssUtils.CheckBucketName(setBucketLoggingRequest.TargetBucket);
  33. if (!OssUtils.IsLoggingPrefixValid(setBucketLoggingRequest.TargetPrefix))
  34. throw new ArgumentException("Invalid logging prefix " + setBucketLoggingRequest.TargetPrefix);
  35. _bucketName = bucketName;
  36. _setBucketLoggingRequest = setBucketLoggingRequest;
  37. }
  38. public static SetBucketLoggingCommand Create(IServiceClient client, Uri endpoint, ExecutionContext context,
  39. string bucketName, SetBucketLoggingRequest setBucketLoggingRequest)
  40. {
  41. return new SetBucketLoggingCommand(client, endpoint, context, bucketName, setBucketLoggingRequest);
  42. }
  43. protected override IDictionary<string, string> Parameters
  44. {
  45. get
  46. {
  47. return new Dictionary<string, string>()
  48. {
  49. { RequestParameters.SUBRESOURCE_LOGGING, null }
  50. };
  51. }
  52. }
  53. protected override Stream Content
  54. {
  55. get
  56. {
  57. return SerializerFactory.GetFactory().CreateSetBucketLoggingRequestSerializer()
  58. .Serialize(_setBucketLoggingRequest);
  59. }
  60. }
  61. }
  62. }