CopyObjectCommand.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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.Common.Communication;
  10. using Aliyun.OSS.Util;
  11. using Aliyun.OSS.Transform;
  12. namespace Aliyun.OSS.Commands
  13. {
  14. internal class CopyObjectCommand : OssCommand<CopyObjectResult>
  15. {
  16. private readonly CopyObjectRequest _copyObjectRequset;
  17. protected override string Bucket
  18. {
  19. get
  20. {
  21. return _copyObjectRequset.DestinationBucketName;
  22. }
  23. }
  24. protected override string Key
  25. {
  26. get
  27. {
  28. return _copyObjectRequset.DestinationKey;
  29. }
  30. }
  31. protected override HttpMethod Method
  32. {
  33. get { return HttpMethod.Put; }
  34. }
  35. protected override IDictionary<string, string> Headers
  36. {
  37. get
  38. {
  39. var headers = new Dictionary<string, string>();
  40. _copyObjectRequset.Populate(headers);
  41. return headers;
  42. }
  43. }
  44. private CopyObjectCommand(IServiceClient client, Uri endpoint, ExecutionContext context,
  45. IDeserializer<ServiceResponse, CopyObjectResult> deserializer,
  46. CopyObjectRequest copyObjectRequest)
  47. : base(client, endpoint, context, deserializer)
  48. {
  49. _copyObjectRequset = copyObjectRequest;
  50. }
  51. public static CopyObjectCommand Create(IServiceClient client, Uri endpoint,
  52. ExecutionContext context, CopyObjectRequest copyObjectRequest)
  53. {
  54. OssUtils.CheckBucketName(copyObjectRequest.SourceBucketName);
  55. OssUtils.CheckObjectKey(copyObjectRequest.SourceKey);
  56. OssUtils.CheckBucketName(copyObjectRequest.DestinationBucketName);
  57. OssUtils.CheckObjectKey(copyObjectRequest.DestinationKey);
  58. return new CopyObjectCommand(client, endpoint, context,
  59. DeserializerFactory.GetFactory().CreateCopyObjectResultDeserializer(),
  60. copyObjectRequest);
  61. }
  62. }
  63. }