ListPartsResultDeserializer.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright (C) Alibaba Cloud Computing
  3. * All rights reserved.
  4. *
  5. * 版权所有 (C)阿里云计算有限公司
  6. */
  7. using System;
  8. using System.IO;
  9. using Aliyun.OSS.Common.Communication;
  10. using Aliyun.OSS.Model;
  11. using Aliyun.OSS.Util;
  12. namespace Aliyun.OSS.Transform
  13. {
  14. internal class ListPartsResponseDeserializer : ResponseDeserializer<PartListing, ListPartsResult>
  15. {
  16. public ListPartsResponseDeserializer(IDeserializer<Stream, ListPartsResult> contentDeserializer)
  17. : base(contentDeserializer)
  18. { }
  19. public override PartListing Deserialize(ServiceResponse xmlStream)
  20. {
  21. var listPartResult = ContentDeserializer.Deserialize(xmlStream.Content);
  22. var partListing = new PartListing
  23. {
  24. BucketName = listPartResult.Bucket,
  25. Key = listPartResult.EncodingType.ToLowerInvariant().Equals(HttpUtils.UrlEncodingType) ? HttpUtils.DecodeUri(listPartResult.Key) : listPartResult.Key,
  26. MaxParts = listPartResult.MaxParts,
  27. NextPartNumberMarker = listPartResult.NextPartNumberMarker.Length == 0 ?
  28. 0 : Convert.ToInt32(listPartResult.NextPartNumberMarker),
  29. PartNumberMarker = listPartResult.PartNumberMarker,
  30. UploadId = listPartResult.UploadId,
  31. IsTruncated = listPartResult.IsTruncated
  32. };
  33. if (listPartResult.PartResults != null)
  34. {
  35. foreach (var partResult in listPartResult.PartResults)
  36. {
  37. var part = new Part
  38. {
  39. ETag = partResult.ETag != null ? OssUtils.TrimQuotes(partResult.ETag) : string.Empty,
  40. LastModified = partResult.LastModified,
  41. PartNumber = partResult.PartNumber,
  42. Size = partResult.Size
  43. };
  44. partListing.AddPart(part);
  45. }
  46. }
  47. return partListing;
  48. }
  49. }
  50. }