GetObjectCommand.cs 2.2 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 GetObjectCommand : OssCommand<OssObject>
  15. {
  16. private readonly GetObjectRequest _getObjectRequest;
  17. protected override string Bucket
  18. {
  19. get { return _getObjectRequest.BucketName; }
  20. }
  21. protected override string Key
  22. {
  23. get { return _getObjectRequest.Key; }
  24. }
  25. protected override IDictionary<string, string> Headers
  26. {
  27. get
  28. {
  29. var headers = new Dictionary<string, string>();
  30. _getObjectRequest.Populate(headers);
  31. return headers;
  32. }
  33. }
  34. protected override IDictionary<string, string> Parameters
  35. {
  36. get
  37. {
  38. var parameters = base.Parameters;
  39. _getObjectRequest.ResponseHeaders.Populate(parameters);
  40. return parameters;
  41. }
  42. }
  43. protected override bool LeaveResponseOpen
  44. {
  45. get { return true; }
  46. }
  47. private GetObjectCommand(IServiceClient client, Uri endpoint, ExecutionContext context,
  48. IDeserializer<ServiceResponse, OssObject> deserializer,
  49. GetObjectRequest getObjectRequest)
  50. : base(client, endpoint, context, deserializer)
  51. {
  52. _getObjectRequest = getObjectRequest;
  53. }
  54. public static GetObjectCommand Create(IServiceClient client, Uri endpoint, ExecutionContext context,
  55. GetObjectRequest getObjectRequest)
  56. {
  57. OssUtils.CheckBucketName(getObjectRequest.BucketName);
  58. OssUtils.CheckObjectKey(getObjectRequest.Key);
  59. return new GetObjectCommand(client, endpoint, context,
  60. DeserializerFactory.GetFactory().CreateGetObjectResultDeserializer(getObjectRequest),
  61. getObjectRequest);
  62. }
  63. }
  64. }