PutBucketInventoryRequest.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using COSXML.Common;
  2. using COSXML.Model.Tag;
  3. using COSXML.Network;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Text;
  7. namespace COSXML.Model.Bucket
  8. {
  9. public sealed class PutBucketInventoryRequest : BucketRequest
  10. {
  11. private InventoryConfiguration inventoryConfiguration;
  12. public PutBucketInventoryRequest(string bucket, string id) : base(bucket)
  13. {
  14. this.method = CosRequestMethod.PUT;
  15. this.queryParameters.Add("inventory", null);
  16. this.queryParameters.Add("id", id);
  17. inventoryConfiguration = new InventoryConfiguration();
  18. inventoryConfiguration.isEnabled = true;
  19. inventoryConfiguration.id = id;
  20. inventoryConfiguration.schedule = new InventoryConfiguration.Schedule();
  21. inventoryConfiguration.destination = new InventoryConfiguration.Destination();
  22. inventoryConfiguration.destination.cosBucketDestination = new InventoryConfiguration.COSBucketDestination();
  23. }
  24. public void IsEnable(bool isEnabled)
  25. {
  26. inventoryConfiguration.isEnabled = isEnabled;
  27. }
  28. public void SetFilter(string prefix)
  29. {
  30. if (!String.IsNullOrEmpty(prefix))
  31. {
  32. inventoryConfiguration.filter = new InventoryConfiguration.Filter();
  33. inventoryConfiguration.filter.prefix = prefix;
  34. }
  35. }
  36. public void SetDestination(string format, string accountId, string bucket, string region, string prefix)
  37. {
  38. if (format != null)
  39. {
  40. inventoryConfiguration.destination.cosBucketDestination.format = format;
  41. }
  42. if (accountId != null)
  43. {
  44. inventoryConfiguration.destination.cosBucketDestination.accountId = accountId;
  45. }
  46. if (bucket != null && region != null)
  47. {
  48. inventoryConfiguration.destination.cosBucketDestination.bucket = "qcs::cos:" + region
  49. + "::" + bucket;
  50. }
  51. if (prefix != null)
  52. {
  53. inventoryConfiguration.destination.cosBucketDestination.prefix = prefix;
  54. }
  55. }
  56. public void EnableSSE()
  57. {
  58. inventoryConfiguration.destination.cosBucketDestination.encryption = new InventoryConfiguration.Encryption();
  59. //默认不填
  60. //默认不填
  61. inventoryConfiguration.destination.cosBucketDestination.encryption.sSECOS = "";
  62. }
  63. public void SetScheduleFrequency(String frequency)
  64. {
  65. if (frequency != null)
  66. {
  67. inventoryConfiguration.schedule.frequency = frequency;
  68. }
  69. }
  70. public void SetOptionalFields(string field)
  71. {
  72. if (field != null)
  73. {
  74. if (inventoryConfiguration.optionalFields == null)
  75. {
  76. inventoryConfiguration.optionalFields = new InventoryConfiguration.OptionalFields();
  77. inventoryConfiguration.optionalFields.fields = new List<string>(6);
  78. }
  79. inventoryConfiguration.optionalFields.fields.Add(field);
  80. }
  81. }
  82. public void SetIncludedObjectVersions(string includedObjectVersions)
  83. {
  84. if (includedObjectVersions != null)
  85. {
  86. inventoryConfiguration.includedObjectVersions = includedObjectVersions;
  87. }
  88. }
  89. public override Network.RequestBody GetRequestBody()
  90. {
  91. return GetXmlRequestBody(inventoryConfiguration);
  92. }
  93. }
  94. }