ListBucket.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Xml.Serialization;
  4. using System.Text;
  5. namespace COSXML.Model.Tag
  6. {
  7. /// <summary>
  8. /// 保存 Get Bucket 请求结果的所有信息
  9. /// <see href="https://cloud.tencent.com/document/product/436/7734#.E8.AF.B7.E6.B1.82.E7.A4.BA.E4.BE.8B"/>
  10. /// </summary>
  11. [XmlRoot("ListBucketResult")]
  12. public sealed class ListBucket
  13. {
  14. /// <summary>
  15. /// Bucket 的名称
  16. /// </summary>
  17. [XmlElement("Name")]
  18. public string name;
  19. /// <summary>
  20. /// 编码格式
  21. /// </summary>
  22. [XmlElement("EncodingType")]
  23. public string encodingType;
  24. /// <summary>
  25. /// 前缀匹配,用来规定响应请求返回的文件前缀地址
  26. /// </summary>
  27. [XmlElement("Prefix")]
  28. public string prefix;
  29. /// <summary>
  30. /// 默认以 UTF-8 二进制顺序列出条目,所有列出条目从 marker 开始
  31. /// </summary>
  32. [XmlElement("Marker")]
  33. public string marker;
  34. /// <summary>
  35. /// 单次响应请求内返回结果的最大的条目数量
  36. /// </summary>
  37. [XmlElement("MaxKeys")]
  38. public int maxKeys;
  39. /// <summary>
  40. /// 响应请求条目是否被截断,布尔值:true,false
  41. /// </summary>
  42. [XmlElement("IsTruncated")]
  43. public bool isTruncated;
  44. /// <summary>
  45. /// 假如返回条目被截断,则返回 NextMarker 就是下一个条目的起点
  46. /// </summary>
  47. [XmlElement("NextMarker")]
  48. public string nextMarker;
  49. /// <summary>
  50. /// 对象元数据信息列表
  51. /// <see href="Contents"/>
  52. /// </summary>
  53. [XmlElement("Contents")]
  54. public List<Contents> contentsList;
  55. /// <summary>
  56. /// 将 Prefix 到 delimiter 之间的相同路径归为一类,定义为 Common Prefix
  57. /// <see href="CommonPrefixes"/>
  58. /// </summary>
  59. [XmlElement("CommonPrefixes")]
  60. public List<CommonPrefixes> commonPrefixesList;
  61. [XmlElement("Delimiter")]
  62. public string delimiter;
  63. public string GetInfo()
  64. {
  65. StringBuilder stringBuilder = new StringBuilder("{ListBucket:\n");
  66. stringBuilder.Append("Name:").Append(name).Append("\n");
  67. stringBuilder.Append("Encoding-Type:").Append(encodingType).Append("\n");
  68. stringBuilder.Append("Prefix:").Append(prefix).Append("\n");
  69. stringBuilder.Append("Marker:").Append(marker).Append("\n");
  70. stringBuilder.Append("MaxKeys:").Append(maxKeys).Append("\n");
  71. stringBuilder.Append("IsTruncated:").Append(isTruncated).Append("\n");
  72. stringBuilder.Append("NextMarker:").Append(nextMarker).Append("\n");
  73. if (contentsList != null)
  74. {
  75. foreach (Contents contents in contentsList)
  76. {
  77. if (contents != null)
  78. {
  79. stringBuilder.Append(contents.GetInfo()).Append("\n");
  80. }
  81. }
  82. }
  83. if (commonPrefixesList != null)
  84. {
  85. foreach (CommonPrefixes commonPrefixes in commonPrefixesList)
  86. {
  87. if (commonPrefixes != null)
  88. {
  89. stringBuilder.Append(commonPrefixes.GetInfo()).Append("\n");
  90. }
  91. }
  92. }
  93. stringBuilder.Append("Delimiter:").Append(delimiter).Append("\n");
  94. stringBuilder.Append("}");
  95. return stringBuilder.ToString();
  96. }
  97. public sealed class Contents
  98. {
  99. /// <summary>
  100. /// Object 的 Key
  101. /// </summary>
  102. [XmlElement("Key")]
  103. public string key;
  104. /// <summary>
  105. /// Object 最后被修改时间
  106. /// </summary>
  107. [XmlElement("LastModified")]
  108. public string lastModified;
  109. /// <summary>
  110. /// 文件的 eTag
  111. /// </summary>
  112. [XmlElement("ETag")]
  113. public string eTag;
  114. /// <summary>
  115. /// 文件大小,单位是 Byte
  116. /// </summary>
  117. [XmlElement("Size")]
  118. public long size;
  119. /// <summary>
  120. /// Bucket 持有者信息
  121. /// <see href="Owner"/>
  122. /// </summary>
  123. [XmlElement("Owner")]
  124. public Owner owner;
  125. /// <summary>
  126. /// Object 的存储级别,枚举值:STANDARD,STANDARD_IA,ARCHIVE
  127. /// <see href="COSXML.Common.CosStorageClass"/>
  128. /// </summary>
  129. [XmlElement("StorageClass")]
  130. public string storageClass;
  131. public string GetInfo()
  132. {
  133. StringBuilder stringBuilder = new StringBuilder("{Contents:\n");
  134. stringBuilder.Append("Key:").Append(key).Append("\n");
  135. stringBuilder.Append("LastModified:").Append(lastModified).Append("\n");
  136. stringBuilder.Append("ETag:").Append(eTag).Append("\n");
  137. stringBuilder.Append("Size:").Append(size).Append("\n");
  138. if (owner != null)
  139. {
  140. stringBuilder.Append(owner.GetInfo()).Append("\n");
  141. }
  142. stringBuilder.Append("StorageClass:").Append(storageClass).Append("\n");
  143. stringBuilder.Append("}");
  144. return stringBuilder.ToString();
  145. }
  146. }
  147. public sealed class CommonPrefixes
  148. {
  149. /// <summary>
  150. /// 单条 Common 的前缀
  151. /// </summary>
  152. [XmlElement("Prefix")]
  153. public string prefix;
  154. public string GetInfo()
  155. {
  156. StringBuilder stringBuilder = new StringBuilder("{CommonPrefixes:\n");
  157. stringBuilder.Append("Prefix:").Append(prefix).Append("\n");
  158. stringBuilder.Append("}");
  159. return stringBuilder.ToString();
  160. }
  161. }
  162. public sealed class Owner
  163. {
  164. /// <summary>
  165. /// Bucket 的 AppID
  166. /// </summary>
  167. [XmlElement("ID")]
  168. public string id;
  169. public string GetInfo()
  170. {
  171. StringBuilder stringBuilder = new StringBuilder("{Owner:\n");
  172. stringBuilder.Append("Id:").Append(id).Append("\n");
  173. stringBuilder.Append("}");
  174. return stringBuilder.ToString();
  175. }
  176. }
  177. }
  178. }