ListBucketsCommand.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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.Globalization;
  10. using Aliyun.OSS.Common.Communication;
  11. using Aliyun.OSS.Transform;
  12. using Aliyun.OSS.Util;
  13. namespace Aliyun.OSS.Commands
  14. {
  15. internal class ListBucketsCommand : OssCommand<ListBucketsResult>
  16. {
  17. private readonly ListBucketsRequest _request;
  18. protected override IDictionary<string, string> Parameters
  19. {
  20. get
  21. {
  22. var parameters = base.Parameters;
  23. if (_request != null)
  24. Populate(_request, parameters);
  25. return parameters;
  26. }
  27. }
  28. private static void Populate(ListBucketsRequest request, IDictionary<string, string> parameters)
  29. {
  30. if (request.Prefix != null)
  31. {
  32. parameters[RequestParameters.PREFIX] = request.Prefix;
  33. }
  34. if (request.Marker != null)
  35. {
  36. parameters[RequestParameters.MARKER] = request.Marker;
  37. }
  38. if (request.MaxKeys.HasValue)
  39. {
  40. parameters[RequestParameters.MAX_KEYS] = request.MaxKeys.Value.ToString(CultureInfo.InvariantCulture);
  41. }
  42. }
  43. private ListBucketsCommand(IServiceClient client, Uri endpoint, ExecutionContext context,
  44. IDeserializer<ServiceResponse, ListBucketsResult> deserializeMethod,
  45. ListBucketsRequest request)
  46. : base(client, endpoint, context, deserializeMethod)
  47. {
  48. _request = request;
  49. }
  50. public static ListBucketsCommand Create(IServiceClient client, Uri endpoint, ExecutionContext context,
  51. ListBucketsRequest request)
  52. {
  53. return new ListBucketsCommand(client, endpoint, context,
  54. DeserializerFactory.GetFactory().CreateListBucketResultDeserializer(), request);
  55. }
  56. }
  57. }