DeserializerFactory.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * Copyright (C) Alibaba Cloud Computing
  3. * All rights reserved.
  4. *
  5. * 版权所有 (C)阿里云计算有限公司
  6. */
  7. using System.Collections.Generic;
  8. using System.Diagnostics.CodeAnalysis;
  9. using System.IO;
  10. using Aliyun.OSS.Common.Communication;
  11. using Aliyun.OSS.Model;
  12. namespace Aliyun.OSS.Transform
  13. {
  14. internal abstract class DeserializerFactory
  15. {
  16. public static DeserializerFactory GetFactory()
  17. {
  18. return GetFactory(null);
  19. }
  20. public static DeserializerFactory GetFactory(string contentType)
  21. {
  22. // Use XML for default.
  23. if (contentType == null)
  24. contentType = "text/xml";
  25. if (contentType.Contains("xml"))
  26. return new XmlDeserializerFactory();
  27. return null;
  28. }
  29. protected abstract IDeserializer<Stream, T> CreateContentDeserializer<T>();
  30. public IDeserializer<ServiceResponse, ErrorResult> CreateErrorResultDeserializer()
  31. {
  32. return new SimpleResponseDeserializer<ErrorResult>(CreateContentDeserializer<ErrorResult>());
  33. }
  34. public IDeserializer<ServiceResponse, ListBucketsResult> CreateListBucketResultDeserializer()
  35. {
  36. return new ListBucketsResultDeserializer(CreateContentDeserializer<ListAllMyBucketsResult>());
  37. }
  38. public IDeserializer<ServiceResponse, AccessControlList> CreateGetAclResultDeserializer()
  39. {
  40. return new GetAclResponseDeserializer(CreateContentDeserializer<AccessControlPolicy>());
  41. }
  42. public IDeserializer<ServiceResponse, IList<CORSRule>> CreateGetCorsResultDeserializer()
  43. {
  44. return new GetCorsResponseDeserializer(CreateContentDeserializer<SetBucketCorsRequestModel>());
  45. }
  46. public IDeserializer<ServiceResponse, BucketLoggingResult> CreateGetBucketLoggingResultDeserializer()
  47. {
  48. return new GetBucketLoggingResultDeserializer(CreateContentDeserializer<SetBucketLoggingRequestModel>());
  49. }
  50. public IDeserializer<ServiceResponse, BucketWebsiteResult> CreateGetBucketWebSiteResultDeserializer()
  51. {
  52. return new GetBucketWebSiteResultDeserializer(CreateContentDeserializer<SetBucketWebsiteRequestModel>());
  53. }
  54. [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
  55. public IDeserializer<ServiceResponse, PutObjectResult> CreatePutObjectReusltDeserializer()
  56. {
  57. return new PutObjectResponseDeserializer();
  58. }
  59. [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
  60. public IDeserializer<ServiceResponse, AppendObjectResult> CreateAppendObjectReusltDeserializer()
  61. {
  62. return new AppendObjectResponseDeserializer();
  63. }
  64. [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
  65. public IDeserializer<ServiceResponse, OssObject> CreateGetObjectResultDeserializer(GetObjectRequest request)
  66. {
  67. return new GetObjectResponseDeserializer(request);
  68. }
  69. [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
  70. public IDeserializer<ServiceResponse, ObjectMetadata> CreateGetObjectMetadataResultDeserializer()
  71. {
  72. return new GetObjectMetadataResponseDeserializer();
  73. }
  74. public IDeserializer<ServiceResponse, ObjectListing> CreateListObjectsResultDeserializer()
  75. {
  76. return new ListObjectsResponseDeserializer(CreateContentDeserializer<ListBucketResult>());
  77. }
  78. public IDeserializer<ServiceResponse, MultipartUploadListing> CreateListMultipartUploadsResultDeserializer()
  79. {
  80. return new ListMultipartUploadsResponseDeserializer(CreateContentDeserializer<ListMultipartUploadsResult>());
  81. }
  82. public IDeserializer<ServiceResponse, InitiateMultipartUploadResult> CreateInitiateMultipartUploadResultDeserializer()
  83. {
  84. return new InitiateMultipartUploadResultDeserializer(CreateContentDeserializer<InitiateMultipartResult>());
  85. }
  86. public IDeserializer<ServiceResponse, UploadPartResult> CreateUploadPartResultDeserializer(int partNumber)
  87. {
  88. return new UploadPartResultDeserializer(partNumber);
  89. }
  90. public IDeserializer<ServiceResponse, UploadPartCopyResult> CreateUploadPartCopyResultDeserializer(int partNumber)
  91. {
  92. return new UploadPartCopyResultDeserializer(CreateContentDeserializer<UploadPartCopyRequestModel>(), partNumber);
  93. }
  94. public IDeserializer<ServiceResponse, PartListing> CreateListPartsResultDeserializer()
  95. {
  96. return new ListPartsResponseDeserializer(CreateContentDeserializer<ListPartsResult>());
  97. }
  98. public IDeserializer<ServiceResponse, CompleteMultipartUploadResult> CreateCompleteUploadResultDeserializer()
  99. {
  100. return new CompleteMultipartUploadResultDeserializer(CreateContentDeserializer<CompleteMultipartUploadResultModel>());
  101. }
  102. public IDeserializer<ServiceResponse, CopyObjectResult> CreateCopyObjectResultDeserializer()
  103. {
  104. return new CopyObjectResultDeserializer(CreateContentDeserializer<CopyObjectResultModel>());
  105. }
  106. public IDeserializer<ServiceResponse, DeleteObjectsResult> CreateDeleteObjectsResultDeserializer()
  107. {
  108. return new DeleteObjectsResultDeserializer(CreateContentDeserializer<DeleteObjectsResult>());
  109. }
  110. public IDeserializer<ServiceResponse, RefererConfiguration> CreateGetBucketRefererResultDeserializer()
  111. {
  112. return new SimpleResponseDeserializer<RefererConfiguration>(CreateContentDeserializer<RefererConfiguration>());
  113. }
  114. public IDeserializer<ServiceResponse, IList<LifecycleRule>> CreateGetBucketLifecycleDeserializer()
  115. {
  116. return new GetBucketLifecycleDeserializer(CreateContentDeserializer<LifecycleConfiguration>());
  117. }
  118. }
  119. internal class XmlDeserializerFactory : DeserializerFactory
  120. {
  121. protected override IDeserializer<Stream, T> CreateContentDeserializer<T>()
  122. {
  123. return new XmlStreamDeserializer<T>();
  124. }
  125. }
  126. }