DeleteObjectsRequest.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright (C) Alibaba Cloud Computing
  3. * All rights reserved.
  4. *
  5. * 版权所有 (C)阿里云计算有限公司
  6. */
  7. using System;
  8. using System.Collections.Generic;
  9. using Aliyun.OSS.Util;
  10. namespace Aliyun.OSS
  11. {
  12. /// <summary>
  13. /// 指定完成Delete Multiple Objects的请求参数。
  14. /// </summary>
  15. public class DeleteObjectsRequest
  16. {
  17. private readonly IList<string> _keys = new List<string>();
  18. private string _encodingType;
  19. /// <summary>
  20. /// 获取或者设置<see cref="OssObject" />所在<see cref="Bucket" />的名称。
  21. /// </summary>
  22. public string BucketName { get; private set; }
  23. /// <summary>
  24. /// 获取或设置请求结果的返回模式(详细模式或静默模式)。
  25. /// </summary>
  26. public bool Quiet { get; private set; }
  27. /// <summary>
  28. /// 获取或者设置需要删除的key列表。
  29. /// </summary>
  30. public IList<string> Keys
  31. {
  32. get { return _keys; }
  33. }
  34. /// <summary>
  35. /// 获取或者设置encoding-type的值,默认是url。
  36. /// </summary>
  37. public string EncodingType
  38. {
  39. get
  40. {
  41. return _encodingType ?? HttpUtils.UrlEncodingType;
  42. }
  43. set
  44. {
  45. _encodingType = value;
  46. }
  47. }
  48. /// <summary>
  49. /// 使用静默方式的构造函数。
  50. /// </summary>
  51. /// <param name="bucketName"><see cref="OssObject"/></param>
  52. /// <param name="keys">预删除的Object列表</param>
  53. public DeleteObjectsRequest(string bucketName, IList<string> keys)
  54. : this(bucketName, keys, true)
  55. { }
  56. /// <summary>
  57. /// 使用指定的请求结果返回模式的构造函数。
  58. /// </summary>
  59. /// <param name="bucketName"><see cref="OssObject"/></param>
  60. /// <param name="keys">预删除的Object列表</param>
  61. /// <param name="quiet">true表示静默模式,false表示详细模式</param>
  62. public DeleteObjectsRequest(string bucketName, IList<string> keys, bool quiet)
  63. {
  64. if (keys == null)
  65. throw new ArgumentException("The list of keys to be deleted should not be null");
  66. if (keys.Count <= 0)
  67. throw new ArgumentException("No any keys specified.");
  68. if (keys.Count > OssUtils.DeleteObjectsUpperLimit)
  69. throw new ArgumentException("Count of objects to be deleted exceeds upper limit");
  70. BucketName = bucketName;
  71. foreach (var key in keys)
  72. {
  73. OssUtils.CheckObjectKey(key);
  74. Keys.Add(key);
  75. }
  76. Quiet = quiet;
  77. }
  78. }
  79. }