RestoreObjectRequest.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using COSXML.Model.Tag;
  5. using COSXML.Common;
  6. using COSXML.Network;
  7. namespace COSXML.Model.Object
  8. {
  9. /// <summary>
  10. /// 对一个通过 COS 归档为 archive 类型的对象进行恢复
  11. /// <see href="https://cloud.tencent.com/document/product/436/12633"/>
  12. /// </summary>
  13. public sealed class RestoreObjectRequest : ObjectRequest
  14. {
  15. /// <summary>
  16. /// 用于恢复数据的配置
  17. /// <see href="Model.Tag.RestoreConfigure"/>
  18. /// </summary>
  19. private RestoreConfigure restoreConfigure;
  20. public RestoreObjectRequest(string bucket, string key)
  21. : base(bucket, key)
  22. {
  23. this.method = CosRequestMethod.POST;
  24. this.queryParameters.Add("restore", null);
  25. restoreConfigure = new RestoreConfigure();
  26. restoreConfigure.casJobParameters = new RestoreConfigure.CASJobParameters();
  27. }
  28. /// <summary>
  29. /// 设置临时副本的过期时间
  30. /// </summary>
  31. /// <param name="days"></param>
  32. public void SetExpireDays(int days)
  33. {
  34. if (days < 0)
  35. {
  36. days = 0;
  37. }
  38. restoreConfigure.days = days;
  39. }
  40. /// <summary>
  41. /// 恢复数据时,Tier 可以指定为 CAS 支持的三种恢复类型,分别为 Expedited、Standard、Bulk
  42. /// <see href="Model.Tag.RestoreConfigure.Tier"/>
  43. /// </summary>
  44. /// <param name="tier"></param>
  45. public void SetTier(RestoreConfigure.Tier tier)
  46. {
  47. restoreConfigure.casJobParameters.tier = tier;
  48. }
  49. public void SetVersionId(string versionId)
  50. {
  51. if (versionId != null)
  52. {
  53. SetQueryParameter(CosRequestHeaderKey.VERSION_ID, versionId);
  54. }
  55. }
  56. public override Network.RequestBody GetRequestBody()
  57. {
  58. return GetXmlRequestBody(restoreConfigure);
  59. }
  60. }
  61. }