DeleteObjectsCommand.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (C) Alibaba Cloud Computing
  3. * All rights reserved.
  4. *
  5. * 版权所有 (C)阿里云计算有限公司
  6. */
  7. using System;
  8. using System.IO;
  9. using System.Collections.Generic;
  10. using Aliyun.OSS.Transform;
  11. using Aliyun.OSS.Common.Communication;
  12. using Aliyun.OSS.Util;
  13. namespace Aliyun.OSS.Commands
  14. {
  15. internal class DeleteObjectsCommand : OssCommand<DeleteObjectsResult>
  16. {
  17. private readonly DeleteObjectsRequest _deleteObjectsRequest;
  18. protected override string Bucket
  19. {
  20. get { return _deleteObjectsRequest.BucketName; }
  21. }
  22. protected override HttpMethod Method
  23. {
  24. get { return HttpMethod.Post; }
  25. }
  26. protected override IDictionary<string, string> Parameters
  27. {
  28. get
  29. {
  30. var parameters = new Dictionary<string, string>();
  31. parameters[RequestParameters.SUBRESOURCE_DELETE] = null;
  32. parameters[RequestParameters.ENCODING_TYPE] = _deleteObjectsRequest.EncodingType;
  33. return parameters;
  34. }
  35. }
  36. protected override Stream Content
  37. {
  38. get
  39. {
  40. return SerializerFactory.GetFactory().CreateDeleteObjectsRequestSerializer()
  41. .Serialize(_deleteObjectsRequest);
  42. }
  43. }
  44. protected override IDictionary<string, string> Headers
  45. {
  46. get
  47. {
  48. var headers = new Dictionary<string, string>();
  49. headers[HttpHeaders.ContentLength] = Content.Length.ToString();
  50. headers[HttpHeaders.ContentMd5] = OssUtils.ComputeContentMd5(Content, Content.Length);
  51. return headers;
  52. }
  53. }
  54. private DeleteObjectsCommand(IServiceClient client, Uri endpoint, ExecutionContext context,
  55. IDeserializer<ServiceResponse, DeleteObjectsResult> deserializeMethod,
  56. DeleteObjectsRequest deleteObjectsRequest)
  57. : base(client, endpoint, context, deserializeMethod)
  58. {
  59. _deleteObjectsRequest = deleteObjectsRequest;
  60. }
  61. public static DeleteObjectsCommand Create(IServiceClient client, Uri endpoint, ExecutionContext context,
  62. DeleteObjectsRequest deleteObjectsRequest)
  63. {
  64. OssUtils.CheckBucketName(deleteObjectsRequest.BucketName);
  65. return new DeleteObjectsCommand(client, endpoint, context,
  66. DeserializerFactory.GetFactory().CreateDeleteObjectsResultDeserializer(),
  67. deleteObjectsRequest);
  68. }
  69. }
  70. }