ListObjectsResponseDeserializer.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright (C) Alibaba Cloud Computing
  3. * All rights reserved.
  4. *
  5. * 版权所有 (C)阿里云计算有限公司
  6. */
  7. using System.IO;
  8. using Aliyun.OSS.Common.Communication;
  9. using Aliyun.OSS.Model;
  10. using Aliyun.OSS.Util;
  11. namespace Aliyun.OSS.Transform
  12. {
  13. internal class ListObjectsResponseDeserializer : ResponseDeserializer<ObjectListing, ListBucketResult>
  14. {
  15. public ListObjectsResponseDeserializer(IDeserializer<Stream, ListBucketResult> contentDeserializer)
  16. : base(contentDeserializer)
  17. { }
  18. public override ObjectListing Deserialize(ServiceResponse xmlStream)
  19. {
  20. var listBucketResult = ContentDeserializer.Deserialize(xmlStream.Content);
  21. string encodeType = listBucketResult.EncodingType == null ?
  22. string.Empty : listBucketResult.EncodingType.ToLowerInvariant();
  23. var objectList = new ObjectListing(listBucketResult.Name)
  24. {
  25. Delimiter = Decode(listBucketResult.Delimiter, encodeType),
  26. IsTruncated = listBucketResult.IsTruncated,
  27. Marker = Decode(listBucketResult.Marker, encodeType),
  28. MaxKeys = listBucketResult.MaxKeys,
  29. NextMarker = Decode(listBucketResult.NextMarker, encodeType),
  30. Prefix = Decode(listBucketResult.Prefix, encodeType)
  31. };
  32. if (listBucketResult.Contents != null)
  33. {
  34. foreach(var contents in listBucketResult.Contents)
  35. {
  36. var summary = new OssObjectSummary
  37. {
  38. BucketName = listBucketResult.Name,
  39. Key = Decode(contents.Key, encodeType),
  40. LastModified = contents.LastModified,
  41. ETag = contents.ETag != null ? OssUtils.TrimQuotes(contents.ETag) : string.Empty,
  42. Size = contents.Size,
  43. StorageClass = contents.StorageClass,
  44. Owner = contents.Owner != null ?
  45. new Owner(contents.Owner.Id, contents.Owner.DisplayName) : null
  46. };
  47. objectList.AddObjectSummary(summary);
  48. }
  49. }
  50. if (listBucketResult.CommonPrefixes != null)
  51. {
  52. foreach(var commonPrefixes in listBucketResult.CommonPrefixes)
  53. {
  54. if (commonPrefixes.Prefix != null)
  55. {
  56. foreach(var prefix in commonPrefixes.Prefix)
  57. {
  58. objectList.AddCommonPrefix(Decode(prefix, encodeType));
  59. }
  60. }
  61. }
  62. }
  63. return objectList;
  64. }
  65. }
  66. }