CIRequest.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using COSXML.CosException;
  5. using COSXML.Common;
  6. using COSXML.Utils;
  7. using COSXML.Network;
  8. namespace COSXML.Model.Object
  9. {
  10. public class CIRequest : CosRequest
  11. {
  12. /// <summary>
  13. /// 存储桶名称(Bucket)
  14. /// <see href="https://cloud.tencent.com/document/product/436/7751"/>
  15. /// </summary>
  16. protected string bucket;
  17. public CIRequest()
  18. {
  19. }
  20. public CIRequest(string bucket)
  21. {
  22. this.bucket = bucket;
  23. }
  24. /// <summary>
  25. /// Bucket 所在的地域
  26. /// </summary>
  27. protected string region;
  28. public void SetRequestPath(string path)
  29. {
  30. this.path = path;
  31. }
  32. /// <summary>
  33. /// Object 所属的 Bucket
  34. /// </summary>
  35. public string Bucket
  36. {
  37. get
  38. {
  39. return this.bucket;
  40. }
  41. set { this.bucket = value; }
  42. }
  43. /// <summary>
  44. /// Bucket 所在的地域
  45. /// </summary>
  46. public string Region
  47. {
  48. get
  49. {
  50. return this.region;
  51. }
  52. set { this.region = value; }
  53. }
  54. public override Network.RequestBody GetRequestBody()
  55. {
  56. return null;
  57. }
  58. public override string GetHost()
  59. {
  60. StringBuilder hostBuilder = new StringBuilder();
  61. if (!String.IsNullOrEmpty(serviceConfig.host))
  62. {
  63. hostBuilder.Append(serviceConfig.host);
  64. }
  65. else if (String.IsNullOrEmpty(bucket))
  66. {
  67. hostBuilder.Append("ci.").Append(region).Append(".myqcloud.com");
  68. }
  69. else
  70. {
  71. hostBuilder.Append(bucket);
  72. if (!String.IsNullOrEmpty(appid) && !bucket.EndsWith("-" + appid))
  73. {
  74. hostBuilder.Append("-")
  75. .Append(appid);
  76. }
  77. hostBuilder.Append(".ci.")
  78. .Append(region)
  79. .Append(".myqcloud.com");
  80. }
  81. return hostBuilder.ToString();
  82. }
  83. public override void CheckParameters()
  84. {
  85. if (requestUrlWithSign != null)
  86. {
  87. return;
  88. }
  89. //if (appid == null)
  90. //{
  91. // throw new CosClientException((int)CosClientError.INVALID_ARGUMENT, "appid is null");
  92. //}
  93. // if (region == null || region.Length < 1)
  94. // {
  95. // throw new CosClientException((int)CosClientError.INVALID_ARGUMENT, "region is null");
  96. // }
  97. if (path == null || path.Length < 1)
  98. {
  99. throw new CosClientException((int)CosClientError.InvalidArgument, "cosPath(null or empty)is invalid");
  100. }
  101. }
  102. protected virtual void InternalUpdateQueryParameters()
  103. {
  104. }
  105. protected virtual void InteranlUpdateHeaders()
  106. {
  107. }
  108. public override Dictionary<string, string> GetRequestParamters()
  109. {
  110. InternalUpdateQueryParameters();
  111. return base.GetRequestParamters();
  112. }
  113. }
  114. }