SerializerFactory.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright (C) Alibaba Cloud Computing
  3. * All rights reserved.
  4. *
  5. * 版权所有 (C)阿里云计算有限公司
  6. */
  7. using System.IO;
  8. using Aliyun.OSS.Model;
  9. namespace Aliyun.OSS.Transform
  10. {
  11. internal abstract class SerializerFactory
  12. {
  13. public static SerializerFactory GetFactory(string contentType = null)
  14. {
  15. if (contentType == null || contentType.Contains("xml"))
  16. {
  17. return new XmlSerializerFactory();
  18. }
  19. // Ignore other content types, current only supports XML serializer factory.
  20. return null;
  21. }
  22. protected abstract ISerializer<T, Stream> CreateContentSerializer<T>();
  23. public ISerializer<CompleteMultipartUploadRequest, Stream> CreateCompleteUploadRequestSerializer()
  24. {
  25. return new CompleteMultipartUploadRequestSerializer(CreateContentSerializer<CompleteMultipartUploadRequestModel>());
  26. }
  27. public ISerializer<SetBucketLoggingRequest, Stream> CreateSetBucketLoggingRequestSerializer()
  28. {
  29. return new SetBucketLoggingRequestSerializer(CreateContentSerializer<SetBucketLoggingRequestModel>());
  30. }
  31. public ISerializer<SetBucketWebsiteRequest, Stream> CreateSetBucketWebsiteRequestSerializer()
  32. {
  33. return new SetBucketWebsiteRequestSerializer(CreateContentSerializer<SetBucketWebsiteRequestModel>());
  34. }
  35. public ISerializer<SetBucketCorsRequest, Stream> CreateSetBucketCorsRequestSerializer()
  36. {
  37. return new SetBucketCorsRequestSerializer(CreateContentSerializer<SetBucketCorsRequestModel>());
  38. }
  39. public ISerializer<DeleteObjectsRequest, Stream> CreateDeleteObjectsRequestSerializer()
  40. {
  41. return new DeleteObjectsRequestSerializer(CreateContentSerializer<DeleteObjectsRequestModel>());
  42. }
  43. public ISerializer<SetBucketRefererRequest, Stream> CreateSetBucketRefererRequestSerializer()
  44. {
  45. return new SetBucketRefererRequestSerializer(CreateContentSerializer<RefererConfiguration>());
  46. }
  47. public ISerializer<SetBucketLifecycleRequest, Stream> CreateSetBucketLifecycleRequestSerializer()
  48. {
  49. return new SetBucketLifecycleRequestSerializer(CreateContentSerializer<LifecycleConfiguration>());
  50. }
  51. }
  52. internal class XmlSerializerFactory : SerializerFactory
  53. {
  54. protected override ISerializer<T, Stream> CreateContentSerializer<T>()
  55. {
  56. return new XmlStreamSerializer<T>();
  57. }
  58. }
  59. }