ListBucketsResultDeserializer.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * Copyright (C) Alibaba Cloud Computing
  3. * All rights reserved.
  4. *
  5. * 版权所有 (C)阿里云计算有限公司
  6. */
  7. using System.IO;
  8. using System.Collections.Generic;
  9. using Aliyun.OSS.Common.Communication;
  10. using Aliyun.OSS.Model;
  11. namespace Aliyun.OSS.Transform
  12. {
  13. internal class ListBucketsResultDeserializer : ResponseDeserializer<ListBucketsResult, ListAllMyBucketsResult>
  14. {
  15. public ListBucketsResultDeserializer(IDeserializer<Stream, ListAllMyBucketsResult> contentDeserializer)
  16. : base(contentDeserializer)
  17. { }
  18. public override ListBucketsResult Deserialize(ServiceResponse xmlStream)
  19. {
  20. var model = ContentDeserializer.Deserialize(xmlStream.Content);
  21. var result = new ListBucketsResult {Prefix = model.Prefix, Marker = model.Marker};
  22. if (model.MaxKeys.HasValue)
  23. result.MaxKeys = model.MaxKeys.Value;
  24. if (model.IsTruncated.HasValue)
  25. result.IsTruncated = model.IsTruncated.Value;
  26. result.NextMaker = model.NextMarker;
  27. var selectedBuckets = new List<Bucket>();
  28. foreach (var e in model.Buckets)
  29. {
  30. var newBucket = new Bucket(e.Name)
  31. {
  32. Location = e.Location,
  33. Owner = new Owner(model.Owner.Id, model.Owner.DisplayName),
  34. CreationDate = e.CreationDate
  35. };
  36. selectedBuckets.Add(newBucket);
  37. }
  38. result.Buckets = selectedBuckets;
  39. return result;
  40. }
  41. }
  42. }