LifecycleConfiguration.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Xml.Serialization;
  4. using System.Text;
  5. namespace COSXML.Model.Tag
  6. {
  7. [XmlRoot("LifecycleConfiguration")]
  8. public sealed class LifecycleConfiguration
  9. {
  10. /// <summary>
  11. /// 规则描述
  12. /// <see href="Rule"/>
  13. /// </summary>
  14. [XmlElement("Rule")]
  15. public List<Rule> rules;
  16. public string GetInfo()
  17. {
  18. StringBuilder stringBuilder = new StringBuilder("{LifecycleConfiguration:\n");
  19. if (rules != null)
  20. {
  21. foreach (Rule rule in rules)
  22. {
  23. if (rule != null)
  24. {
  25. stringBuilder.Append(rule.GetInfo()).Append("\n");
  26. }
  27. }
  28. }
  29. stringBuilder.Append("}");
  30. return stringBuilder.ToString();
  31. }
  32. public sealed class Rule
  33. {
  34. /// <summary>
  35. /// 用于唯一标识规则,长度不能超过 255 个字符
  36. /// </summary>
  37. [XmlElement("ID")]
  38. public string id;
  39. /// <summary>
  40. /// Filter 用于描述规则影响的 Object 集合
  41. /// <see href="Filter"/>
  42. /// </summary>
  43. [XmlElement("Filter")]
  44. public Filter filter;
  45. /// <summary>
  46. /// 指明规则是否启用,枚举值:Enabled,Disabled
  47. /// </summary>
  48. [XmlElement("Status")]
  49. public string status;
  50. /// <summary>
  51. /// 规则转换属性,对象何时转换为 Standard_IA 或 Archive
  52. /// <see href="Transition"/>
  53. /// </summary>
  54. [XmlElement("Transition")]
  55. public Transition transition;
  56. /// <summary>
  57. /// 规则过期属性
  58. /// <see href="Expiration"/>
  59. /// </summary>
  60. [XmlElement("Expiration")]
  61. public Expiration expiration;
  62. /// <summary>
  63. /// 指明非当前版本对象何时过期
  64. /// <see href="NoncurrentVersionExpiration"/>
  65. /// </summary>
  66. [XmlElement("NoncurrentVersionExpiration")]
  67. public NoncurrentVersionExpiration noncurrentVersionExpiration;
  68. /// <summary>
  69. /// 指明非当前版本对象何时转换为 STANDARD_IA 或 ARCHIVE
  70. /// <see href="NoncurrentVersionTransition"/>
  71. /// </summary>
  72. [XmlElement("NoncurrentVersionTransition")]
  73. public NoncurrentVersionTransition noncurrentVersionTransition;
  74. /// <summary>
  75. /// 设置允许分片上传保持运行的最长时间
  76. /// <see href="AbortIncompleteMultiUpload"/>
  77. /// </summary>
  78. [XmlElement("AbortIncompleteMultipartUpload")]
  79. public AbortIncompleteMultiUpload abortIncompleteMultiUpload;
  80. public string GetInfo()
  81. {
  82. StringBuilder stringBuilder = new StringBuilder("{Rule:\n");
  83. stringBuilder.Append("Id:").Append(id).Append("\n");
  84. if (filter != null)
  85. {
  86. stringBuilder.Append(filter.GetInfo()).Append("\n");
  87. }
  88. stringBuilder.Append("Status:").Append(status).Append("\n");
  89. if (transition != null)
  90. {
  91. stringBuilder.Append(transition.GetInfo()).Append("\n");
  92. }
  93. if (expiration != null)
  94. {
  95. stringBuilder.Append(expiration.GetInfo()).Append("\n");
  96. }
  97. if (noncurrentVersionExpiration != null)
  98. {
  99. stringBuilder.Append(noncurrentVersionExpiration.GetInfo()).Append("\n");
  100. }
  101. if (noncurrentVersionTransition != null)
  102. {
  103. stringBuilder.Append(noncurrentVersionTransition.GetInfo()).Append("\n");
  104. }
  105. if (abortIncompleteMultiUpload != null)
  106. {
  107. stringBuilder.Append(abortIncompleteMultiUpload.GetInfo()).Append("\n");
  108. }
  109. stringBuilder.Append("}");
  110. return stringBuilder.ToString();
  111. }
  112. }
  113. public sealed class Filter
  114. {
  115. /// <summary>
  116. /// 指定规则所适用的前缀。匹配前缀的对象受该规则影响,Prefix 最多只能有一个
  117. /// </summary>
  118. [XmlElement("Prefix")]
  119. public string prefix;
  120. [XmlElement("And")]
  121. public FilterAnd filterAnd;
  122. public string GetInfo()
  123. {
  124. StringBuilder stringBuilder = new StringBuilder("{Filter:\n");
  125. stringBuilder.Append("Prefix:").Append(prefix).Append("\n");
  126. if (filterAnd != null)
  127. {
  128. stringBuilder.Append(filterAnd.GetInfo()).Append("\n");
  129. }
  130. stringBuilder.Append("}");
  131. return stringBuilder.ToString();
  132. }
  133. }
  134. public sealed class FilterAnd
  135. {
  136. [XmlElement("Prefix")]
  137. public string prefix;
  138. [XmlElement("Tag")]
  139. public List<Tagging.Tag> tags;
  140. public string GetInfo()
  141. {
  142. StringBuilder stringBuilder = new StringBuilder("{And:\n");
  143. stringBuilder.Append("Prefix:").Append(prefix).Append("\n");
  144. stringBuilder.Append("}");
  145. return stringBuilder.ToString();
  146. }
  147. }
  148. public sealed class Transition
  149. {
  150. /// <summary>
  151. /// 指明规则对应的动作在对象最后的修改日期过后多少天操作
  152. /// </summary>
  153. [XmlElement("Days")]
  154. public int days;
  155. /// <summary>
  156. /// 指明规则对应的动作在何时操作
  157. /// </summary>
  158. [XmlElement("Date")]
  159. public string date;
  160. /// <summary>
  161. /// 指定 Object 转储到的目标存储类型,枚举值: STANDARD_IA, ARCHIVE
  162. /// <see href="COSXML.Common.CosStorageClass"/>
  163. /// </summary>
  164. [XmlElement("StorageClass")]
  165. public string storageClass;
  166. public string GetInfo()
  167. {
  168. StringBuilder stringBuilder = new StringBuilder("{Transition:\n");
  169. stringBuilder.Append("Days:").Append(days).Append("\n");
  170. stringBuilder.Append("Date:").Append(date).Append("\n");
  171. stringBuilder.Append("StorageClass:").Append(storageClass).Append("\n");
  172. stringBuilder.Append("}");
  173. return stringBuilder.ToString();
  174. }
  175. public bool ShouldSerializedays()
  176. {
  177. return days > 0;
  178. }
  179. }
  180. public sealed class Expiration
  181. {
  182. /// <summary>
  183. /// 指明规则对应的动作在何时操作
  184. /// </summary>
  185. [XmlElement("Date")]
  186. public string date;
  187. /// <summary>
  188. /// 指明规则对应的动作在对象最后的修改日期过后多少天操作
  189. /// </summary>
  190. [XmlElement("Days")]
  191. public int days;
  192. /// <summary>
  193. /// 删除过期对象删除标记,取值为 true,false
  194. /// </summary>
  195. [XmlElement("ExpiredObjectDeleteMarker")]
  196. public bool expiredObjectDeleteMarker;
  197. public string GetInfo()
  198. {
  199. StringBuilder stringBuilder = new StringBuilder("{Expiration:\n");
  200. stringBuilder.Append("Days:").Append(days).Append("\n");
  201. stringBuilder.Append("Date:").Append(date).Append("\n");
  202. stringBuilder.Append("ExpiredObjectDeleteMarker:").Append(expiredObjectDeleteMarker).Append("\n");
  203. stringBuilder.Append("}");
  204. return stringBuilder.ToString();
  205. }
  206. public bool ShouldSerializedays()
  207. {
  208. return days > 0;
  209. }
  210. public bool ShouldSerializeexpiredObjectDeleteMarker()
  211. {
  212. return expiredObjectDeleteMarker;
  213. }
  214. }
  215. public sealed class NoncurrentVersionExpiration
  216. {
  217. /// <summary>
  218. /// 指明规则对应的动作在对象变成非当前版本多少天后执行
  219. /// </summary>
  220. [XmlElement("NoncurrentDays")]
  221. public int noncurrentDays;
  222. public string GetInfo()
  223. {
  224. StringBuilder stringBuilder = new StringBuilder("{NoncurrentVersionExpiration:\n");
  225. stringBuilder.Append("NoncurrentDays:").Append(noncurrentDays).Append("\n");
  226. stringBuilder.Append("}");
  227. return stringBuilder.ToString();
  228. }
  229. }
  230. public sealed class NoncurrentVersionTransition
  231. {
  232. /// <summary>
  233. /// 指明规则对应的动作在对象变成非当前版本多少天后执行
  234. /// </summary>
  235. [XmlElement("NoncurrentDays")]
  236. public int noncurrentDays;
  237. /// <summary>
  238. /// 指定 Object 转储到的目标存储类型
  239. /// <see href="COSXML.Common.CosStorageClass"/>
  240. /// </summary>
  241. [XmlElement("StorageClass")]
  242. public string storageClass;
  243. public string GetInfo()
  244. {
  245. StringBuilder stringBuilder = new StringBuilder("{NoncurrentVersionTransition:\n");
  246. stringBuilder.Append("NoncurrentDays:").Append(noncurrentDays).Append("\n");
  247. stringBuilder.Append("StorageClass:").Append(storageClass).Append("\n");
  248. stringBuilder.Append("}");
  249. return stringBuilder.ToString();
  250. }
  251. }
  252. public sealed class AbortIncompleteMultiUpload
  253. {
  254. /// <summary>
  255. /// 指明分片上传开始后多少天内必须完成上传
  256. /// </summary>
  257. [XmlElement("DaysAfterInitiation")]
  258. public int daysAfterInitiation;
  259. public string GetInfo()
  260. {
  261. StringBuilder stringBuilder = new StringBuilder("{AbortIncompleteMultiUpload:\n");
  262. stringBuilder.Append("DaysAfterInitiation:").Append(daysAfterInitiation).Append("\n");
  263. stringBuilder.Append("}");
  264. return stringBuilder.ToString();
  265. }
  266. }
  267. }
  268. }