PutBucketLoggingRequest.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using COSXML.Common;
  2. using COSXML.Model.Tag;
  3. using COSXML.Network;
  4. using COSXML.CosException;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Text;
  8. namespace COSXML.Model.Bucket
  9. {
  10. public sealed class PutBucketLoggingRequest : BucketRequest
  11. {
  12. private BucketLoggingStatus bucketLoggingStatus;
  13. public PutBucketLoggingRequest(string bucket) : base(bucket)
  14. {
  15. this.method = CosRequestMethod.PUT;
  16. this.queryParameters.Add("logging", null);
  17. this.bucketLoggingStatus = new BucketLoggingStatus();
  18. }
  19. public void SetTarget(string targetBucket, string targetPrefix = "")
  20. {
  21. if (targetBucket == null || targetBucket == "")
  22. {
  23. throw new CosClientException((int)CosClientError.InvalidArgument,
  24. "targetBucket is null or empty");
  25. }
  26. // 可选参数,传 null 填入空白
  27. if (targetPrefix == null)
  28. {
  29. targetPrefix = "";
  30. }
  31. if (bucketLoggingStatus.loggingEnabled == null)
  32. {
  33. bucketLoggingStatus.loggingEnabled = new BucketLoggingStatus.LoggingEnabled();
  34. }
  35. bucketLoggingStatus.loggingEnabled.targetBucket = targetBucket;
  36. bucketLoggingStatus.loggingEnabled.targetPrefix = targetPrefix;
  37. }
  38. public override Network.RequestBody GetRequestBody()
  39. {
  40. return GetXmlRequestBody(bucketLoggingStatus);
  41. }
  42. }
  43. }