BucketRequest.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using COSXML.CosException;
  5. using COSXML.Common;
  6. namespace COSXML.Model.Bucket
  7. {
  8. public abstract class BucketRequest : CosRequest
  9. {
  10. /// <summary>
  11. /// cos 存储桶,即 Bucket
  12. /// </summary>
  13. protected string bucket;
  14. /// <summary>
  15. /// Bucket 所在的地域
  16. /// </summary>
  17. protected string region;
  18. public BucketRequest(string bucket)
  19. {
  20. this.bucket = bucket;
  21. this.path = "/";
  22. }
  23. /// <summary>
  24. /// Bucket 名称, "BucketName-APPID"
  25. /// </summary>
  26. public string Bucket
  27. {
  28. get
  29. {
  30. return this.bucket;
  31. }
  32. set { this.bucket = value; }
  33. }
  34. public string Region
  35. {
  36. get
  37. {
  38. return this.region;
  39. }
  40. set { this.region = value; }
  41. }
  42. public override Network.RequestBody GetRequestBody()
  43. {
  44. return null;
  45. }
  46. public override string GetHost()
  47. {
  48. StringBuilder hostBuilder = new StringBuilder();
  49. if (!String.IsNullOrEmpty(serviceConfig.host))
  50. {
  51. hostBuilder.Append(serviceConfig.host);
  52. }
  53. else
  54. {
  55. hostBuilder.Append(bucket);
  56. if (!String.IsNullOrEmpty(appid) && !bucket.EndsWith("-" + appid))
  57. {
  58. hostBuilder.Append("-")
  59. .Append(appid);
  60. }
  61. if (serviceConfig.endpointSuffix != null)
  62. {
  63. hostBuilder.Append(".")
  64. .Append(serviceConfig.endpointSuffix);
  65. }
  66. else
  67. {
  68. hostBuilder.Append(".cos.")
  69. .Append(region)
  70. .Append(".myqcloud.com");
  71. }
  72. }
  73. return hostBuilder.ToString();
  74. }
  75. public override void CheckParameters()
  76. {
  77. if (requestUrlWithSign != null)
  78. {
  79. return;
  80. }
  81. //if (appid == null)
  82. //{
  83. // throw new CosClientException((int)CosClientError.INVALID_ARGUMENT, "appid is null");
  84. //}
  85. if (bucket == null)
  86. {
  87. throw new CosClientException((int)CosClientError.InvalidArgument, "bucket is null");
  88. }
  89. // if (region == null)
  90. // {
  91. // throw new CosClientException((int)CosClientError.INVALID_ARGUMENT, "region is null");
  92. // }
  93. }
  94. }
  95. }