PageRenderTime 196ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/Amazon.CloudFront/Model/Internal/MarshallTransformations/UpdateStreamingDistributionRequestMarshaller.cs

https://bitbucket.org/mdavid/aws-sdk-for-net
C# | 215 lines | 175 code | 23 blank | 17 comment | 45 complexity | d2c4bb878d02c6655a557e814d7b58b6 MD5 | raw file
  1. /*
  2. * Copyright 2010-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License").
  5. * You may not use this file except in compliance with the License.
  6. * A copy of the License is located at
  7. *
  8. * http://aws.amazon.com/apache2.0
  9. *
  10. * or in the "license" file accompanying this file. This file is distributed
  11. * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  12. * express or implied. See the License for the specific language governing
  13. * permissions and limitations under the License.
  14. */
  15. using System;
  16. using System.Collections.Generic;
  17. using System.IO;
  18. using System.Xml;
  19. using System.Xml.Serialization;
  20. using System.Text;
  21. using Amazon.CloudFront.Model;
  22. using Amazon.Runtime;
  23. using Amazon.Runtime.Internal;
  24. using Amazon.Runtime.Internal.Transform;
  25. using Amazon.Runtime.Internal.Util;
  26. namespace Amazon.CloudFront.Model.Internal.MarshallTransformations
  27. {
  28. /// <summary>
  29. /// Update Streaming Distribution Request Marshaller
  30. /// </summary>
  31. public class UpdateStreamingDistributionRequestMarshaller : IMarshaller<IRequest, UpdateStreamingDistributionRequest>
  32. {
  33. public IRequest Marshall(UpdateStreamingDistributionRequest updateStreamingDistributionRequest)
  34. {
  35. IRequest request = new DefaultRequest(updateStreamingDistributionRequest, "AmazonCloudFront");
  36. request.HttpMethod = "PUT";
  37. request.Headers.Add("If-Match", updateStreamingDistributionRequest.IfMatch);
  38. string uriResourcePath = "2012-05-05/streaming-distribution/{Id}/config";
  39. uriResourcePath = uriResourcePath.Replace("{Id}", updateStreamingDistributionRequest.Id ?? "" );
  40. if (uriResourcePath.Contains("?"))
  41. {
  42. string queryString = uriResourcePath.Substring(uriResourcePath.IndexOf("?") + 1);
  43. uriResourcePath = uriResourcePath.Substring(0, uriResourcePath.IndexOf("?"));
  44. foreach (string s in queryString.Split('&'))
  45. {
  46. string[] nameValuePair = s.Split('=');
  47. if (nameValuePair.Length == 2 && nameValuePair[1].Length > 0)
  48. {
  49. request.Parameters.Add(nameValuePair[0], nameValuePair[1]);
  50. }
  51. }
  52. }
  53. request.ResourcePath = uriResourcePath;
  54. StringWriter stringWriter = new StringWriter();
  55. XmlTextWriter xmlWriter = new XmlTextWriter(stringWriter);
  56. xmlWriter.Namespaces = true;
  57. if (updateStreamingDistributionRequest != null)
  58. {
  59. StreamingDistributionConfig streamingDistributionConfigStreamingDistributionConfig = updateStreamingDistributionRequest.StreamingDistributionConfig;
  60. if (streamingDistributionConfigStreamingDistributionConfig != null)
  61. {
  62. xmlWriter.WriteStartElement("StreamingDistributionConfig", "http://cloudfront.amazonaws.com/doc/2012-05-05/");
  63. if (streamingDistributionConfigStreamingDistributionConfig.IsSetCallerReference())
  64. {
  65. xmlWriter.WriteElementString("CallerReference", "http://cloudfront.amazonaws.com/doc/2012-05-05/", streamingDistributionConfigStreamingDistributionConfig.CallerReference.ToString());
  66. }
  67. if (streamingDistributionConfigStreamingDistributionConfig != null)
  68. {
  69. S3Origin s3OriginS3Origin = streamingDistributionConfigStreamingDistributionConfig.S3Origin;
  70. if (s3OriginS3Origin != null)
  71. {
  72. xmlWriter.WriteStartElement("S3Origin", "http://cloudfront.amazonaws.com/doc/2012-05-05/");
  73. if (s3OriginS3Origin.IsSetDomainName())
  74. {
  75. xmlWriter.WriteElementString("DomainName", "http://cloudfront.amazonaws.com/doc/2012-05-05/", s3OriginS3Origin.DomainName.ToString());
  76. }
  77. if (s3OriginS3Origin.IsSetOriginAccessIdentity())
  78. {
  79. xmlWriter.WriteElementString("OriginAccessIdentity", "http://cloudfront.amazonaws.com/doc/2012-05-05/", s3OriginS3Origin.OriginAccessIdentity.ToString());
  80. }
  81. xmlWriter.WriteEndElement();
  82. }
  83. }
  84. if (streamingDistributionConfigStreamingDistributionConfig != null)
  85. {
  86. Aliases aliasesAliases = streamingDistributionConfigStreamingDistributionConfig.Aliases;
  87. if (aliasesAliases != null)
  88. {
  89. xmlWriter.WriteStartElement("Aliases", "http://cloudfront.amazonaws.com/doc/2012-05-05/");
  90. if (aliasesAliases.IsSetQuantity())
  91. {
  92. xmlWriter.WriteElementString("Quantity", "http://cloudfront.amazonaws.com/doc/2012-05-05/", aliasesAliases.Quantity.ToString());
  93. }
  94. if (aliasesAliases != null)
  95. {
  96. List<string> aliasesAliasesitemsList = aliasesAliases.Items;
  97. if (aliasesAliasesitemsList != null && aliasesAliasesitemsList.Count > 0)
  98. {
  99. int aliasesAliasesitemsListIndex = 1;
  100. xmlWriter.WriteStartElement("Items", "http://cloudfront.amazonaws.com/doc/2012-05-05/");
  101. foreach (string aliasesAliasesitemsListValue in aliasesAliasesitemsList)
  102. {
  103. xmlWriter.WriteStartElement("CNAME", "http://cloudfront.amazonaws.com/doc/2012-05-05/");
  104. xmlWriter.WriteValue(aliasesAliasesitemsListValue);
  105. xmlWriter.WriteEndElement();
  106. aliasesAliasesitemsListIndex++;
  107. }
  108. xmlWriter.WriteEndElement();
  109. }
  110. }
  111. xmlWriter.WriteEndElement();
  112. }
  113. }
  114. if (streamingDistributionConfigStreamingDistributionConfig.IsSetComment())
  115. {
  116. xmlWriter.WriteElementString("Comment", "http://cloudfront.amazonaws.com/doc/2012-05-05/", streamingDistributionConfigStreamingDistributionConfig.Comment.ToString());
  117. }
  118. if (streamingDistributionConfigStreamingDistributionConfig != null)
  119. {
  120. LoggingConfig loggingConfigLogging = streamingDistributionConfigStreamingDistributionConfig.Logging;
  121. if (loggingConfigLogging != null)
  122. {
  123. xmlWriter.WriteStartElement("Logging", "http://cloudfront.amazonaws.com/doc/2012-05-05/");
  124. if (loggingConfigLogging.IsSetEnabled())
  125. {
  126. xmlWriter.WriteElementString("Enabled", "http://cloudfront.amazonaws.com/doc/2012-05-05/", loggingConfigLogging.Enabled.ToString().ToLower());
  127. }
  128. if (loggingConfigLogging.IsSetBucket())
  129. {
  130. xmlWriter.WriteElementString("Bucket", "http://cloudfront.amazonaws.com/doc/2012-05-05/", loggingConfigLogging.Bucket.ToString());
  131. }
  132. if (loggingConfigLogging.IsSetPrefix())
  133. {
  134. xmlWriter.WriteElementString("Prefix", "http://cloudfront.amazonaws.com/doc/2012-05-05/", loggingConfigLogging.Prefix.ToString());
  135. }
  136. xmlWriter.WriteEndElement();
  137. }
  138. }
  139. if (streamingDistributionConfigStreamingDistributionConfig != null)
  140. {
  141. TrustedSigners trustedSignersTrustedSigners = streamingDistributionConfigStreamingDistributionConfig.TrustedSigners;
  142. if (trustedSignersTrustedSigners != null)
  143. {
  144. xmlWriter.WriteStartElement("TrustedSigners", "http://cloudfront.amazonaws.com/doc/2012-05-05/");
  145. if (trustedSignersTrustedSigners.IsSetEnabled())
  146. {
  147. xmlWriter.WriteElementString("Enabled", "http://cloudfront.amazonaws.com/doc/2012-05-05/", trustedSignersTrustedSigners.Enabled.ToString().ToLower());
  148. }
  149. if (trustedSignersTrustedSigners.IsSetQuantity())
  150. {
  151. xmlWriter.WriteElementString("Quantity", "http://cloudfront.amazonaws.com/doc/2012-05-05/", trustedSignersTrustedSigners.Quantity.ToString());
  152. }
  153. if (trustedSignersTrustedSigners != null)
  154. {
  155. List<string> trustedSignersTrustedSignersitemsList = trustedSignersTrustedSigners.Items;
  156. if (trustedSignersTrustedSignersitemsList != null && trustedSignersTrustedSignersitemsList.Count > 0)
  157. {
  158. int trustedSignersTrustedSignersitemsListIndex = 1;
  159. xmlWriter.WriteStartElement("Items", "http://cloudfront.amazonaws.com/doc/2012-05-05/");
  160. foreach (string trustedSignersTrustedSignersitemsListValue in trustedSignersTrustedSignersitemsList)
  161. {
  162. xmlWriter.WriteStartElement("AwsAccountNumber", "http://cloudfront.amazonaws.com/doc/2012-05-05/");
  163. xmlWriter.WriteValue(trustedSignersTrustedSignersitemsListValue);
  164. xmlWriter.WriteEndElement();
  165. trustedSignersTrustedSignersitemsListIndex++;
  166. }
  167. xmlWriter.WriteEndElement();
  168. }
  169. }
  170. xmlWriter.WriteEndElement();
  171. }
  172. }
  173. if (streamingDistributionConfigStreamingDistributionConfig.IsSetEnabled())
  174. {
  175. xmlWriter.WriteElementString("Enabled", "http://cloudfront.amazonaws.com/doc/2012-05-05/", streamingDistributionConfigStreamingDistributionConfig.Enabled.ToString().ToLower());
  176. }
  177. xmlWriter.WriteEndElement();
  178. }
  179. }
  180. try
  181. {
  182. request.Content = System.Text.Encoding.UTF8.GetBytes(stringWriter.ToString());
  183. request.Headers.Add("Content-Type", "application/xml");
  184. }
  185. catch (EncoderFallbackException e)
  186. {
  187. throw new AmazonServiceException("Unable to marshall request to XML", e);
  188. }
  189. return request;
  190. }
  191. }
  192. }