SetBucketCorsCommand.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 System.IO;
  10. using Aliyun.OSS.Common.Communication;
  11. using Aliyun.OSS.Util;
  12. using Aliyun.OSS.Transform;
  13. namespace Aliyun.OSS.Commands
  14. {
  15. internal class SetBucketCorsCommand : OssCommand
  16. {
  17. private readonly string _bucketName;
  18. private readonly SetBucketCorsRequest _setBucketCorsRequest;
  19. protected override HttpMethod Method
  20. {
  21. get { return HttpMethod.Put; }
  22. }
  23. protected override string Bucket
  24. {
  25. get
  26. {
  27. return _bucketName;
  28. }
  29. }
  30. protected override Stream Content
  31. {
  32. get
  33. {
  34. return SerializerFactory.GetFactory().CreateSetBucketCorsRequestSerializer()
  35. .Serialize(_setBucketCorsRequest);
  36. }
  37. }
  38. private SetBucketCorsCommand(IServiceClient client, Uri endpoint, ExecutionContext context,
  39. string bucketName, SetBucketCorsRequest setBucketCorsRequest)
  40. : base(client, endpoint, context)
  41. {
  42. OssUtils.CheckBucketName(bucketName);
  43. _bucketName = bucketName;
  44. _setBucketCorsRequest = setBucketCorsRequest;
  45. }
  46. public static SetBucketCorsCommand Create(IServiceClient client, Uri endpoint,
  47. ExecutionContext context,
  48. string bucketName, SetBucketCorsRequest setBucketCorsRequest)
  49. {
  50. return new SetBucketCorsCommand(client, endpoint, context, bucketName, setBucketCorsRequest);
  51. }
  52. protected override IDictionary<string, string> Parameters
  53. {
  54. get
  55. {
  56. return new Dictionary<string, string>()
  57. {
  58. { RequestParameters.SUBRESOURCE_CORS, null }
  59. };
  60. }
  61. }
  62. }
  63. }