public IRequest Marshall(UpdateCloudFrontOriginAccessIdentityRequest updateCloudFrontOriginAccessIdentityRequest)
        {
            IRequest request = new DefaultRequest(updateCloudFrontOriginAccessIdentityRequest, "AmazonCloudFront");



            request.HttpMethod = "PUT";
            if (updateCloudFrontOriginAccessIdentityRequest.IsSetIfMatch())
            {
                request.Headers.Add("If-Match", updateCloudFrontOriginAccessIdentityRequest.IfMatch);
            }

            string uriResourcePath = "2014-01-31/origin-access-identity/cloudfront/{Id}/config";

            uriResourcePath      = uriResourcePath.Replace("{Id}", updateCloudFrontOriginAccessIdentityRequest.IsSetId() ? updateCloudFrontOriginAccessIdentityRequest.Id.ToString() : "");
            request.ResourcePath = uriResourcePath;


            StringWriter stringWriter = new StringWriter(CultureInfo.InvariantCulture);

            using (XmlWriter xmlWriter = XmlWriter.Create(stringWriter, new XmlWriterSettings()
            {
                Encoding = System.Text.Encoding.UTF8, OmitXmlDeclaration = true
            }))
            {
                if (updateCloudFrontOriginAccessIdentityRequest != null)
                {
                    CloudFrontOriginAccessIdentityConfig cloudFrontOriginAccessIdentityConfigCloudFrontOriginAccessIdentityConfig = updateCloudFrontOriginAccessIdentityRequest.CloudFrontOriginAccessIdentityConfig;
                    if (cloudFrontOriginAccessIdentityConfigCloudFrontOriginAccessIdentityConfig != null)
                    {
                        xmlWriter.WriteStartElement("CloudFrontOriginAccessIdentityConfig", "http://cloudfront.amazonaws.com/doc/2014-01-31/");
                        if (cloudFrontOriginAccessIdentityConfigCloudFrontOriginAccessIdentityConfig.IsSetCallerReference())
                        {
                            xmlWriter.WriteElementString("CallerReference", "http://cloudfront.amazonaws.com/doc/2014-01-31/", cloudFrontOriginAccessIdentityConfigCloudFrontOriginAccessIdentityConfig.CallerReference.ToString(CultureInfo.InvariantCulture));
                        }
                        if (cloudFrontOriginAccessIdentityConfigCloudFrontOriginAccessIdentityConfig.IsSetComment())
                        {
                            xmlWriter.WriteElementString("Comment", "http://cloudfront.amazonaws.com/doc/2014-01-31/", cloudFrontOriginAccessIdentityConfigCloudFrontOriginAccessIdentityConfig.Comment.ToString(CultureInfo.InvariantCulture));
                        }
                        xmlWriter.WriteEndElement();
                    }
                }
            }
            try
            {
                string content = stringWriter.ToString();
                request.Content = System.Text.Encoding.UTF8.GetBytes(content);
                request.Headers["Content-Type"] = "application/xml";
            }
            catch (EncoderFallbackException e)
            {
                throw new AmazonServiceException("Unable to marshall request to XML", e);
            }


            return(request);
        }
コード例 #2
0
        public CreateOriginAccessIdentityResponse CreateOriginAccessIdentity(CreateOriginAccessIdentityRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request", "The CreateOriginAccessIdentityRequest specified is null!");
            }
            CloudFrontOriginAccessIdentityConfig originAccessIdentityConfig = request.OriginAccessIdentityConfig;

            if (originAccessIdentityConfig == null)
            {
                throw new ArgumentNullException("request", "The request's OriginAccessIdentityConfig is null!");
            }
            if (!originAccessIdentityConfig.IsSetCallerReference())
            {
                throw new ArgumentNullException("request", "The CallerReference to create the distribution with is null or empty!");
            }
            return(this.Invoke <CreateOriginAccessIdentityResponse>(this.ConvertCreateOriginAccessIdentity(request), request.Headers));
        }
        public IRequest Marshall(UpdateCloudFrontOriginAccessIdentityRequest updateCloudFrontOriginAccessIdentityRequest)
        {
            IRequest request = new DefaultRequest(updateCloudFrontOriginAccessIdentityRequest, "AmazonCloudFront");



            request.HttpMethod = "PUT";
            if (updateCloudFrontOriginAccessIdentityRequest.IfMatch != null)
            {
                request.Headers.Add("If-Match", updateCloudFrontOriginAccessIdentityRequest.IfMatch);
            }



            string uriResourcePath = "2013-08-26/origin-access-identity/cloudfront/{Id}/config";

            uriResourcePath = uriResourcePath.Replace("{Id}", updateCloudFrontOriginAccessIdentityRequest.Id ?? "");

            if (uriResourcePath.Contains("?"))
            {
                string queryString = uriResourcePath.Substring(uriResourcePath.IndexOf("?") + 1);
                uriResourcePath = uriResourcePath.Substring(0, uriResourcePath.IndexOf("?"));

                foreach (string s in queryString.Split('&', ';'))
                {
                    string[] nameValuePair = s.Split('=');
                    if (nameValuePair.Length == 2 && nameValuePair[1].Length > 0)
                    {
                        request.Parameters.Add(nameValuePair[0], nameValuePair[1]);
                    }
                    else
                    {
                        request.Parameters.Add(nameValuePair[0], null);
                    }
                }
            }

            request.ResourcePath = uriResourcePath;


            StringWriter  stringWriter = new StringWriter();
            XmlTextWriter xmlWriter    = new XmlTextWriter(stringWriter);

            xmlWriter.Namespaces = true;

            if (updateCloudFrontOriginAccessIdentityRequest != null)
            {
                CloudFrontOriginAccessIdentityConfig cloudFrontOriginAccessIdentityConfigCloudFrontOriginAccessIdentityConfig = updateCloudFrontOriginAccessIdentityRequest.CloudFrontOriginAccessIdentityConfig;
                if (cloudFrontOriginAccessIdentityConfigCloudFrontOriginAccessIdentityConfig != null)
                {
                    xmlWriter.WriteStartElement("CloudFrontOriginAccessIdentityConfig", "http://cloudfront.amazonaws.com/doc/2013-08-26/");
                    if (cloudFrontOriginAccessIdentityConfigCloudFrontOriginAccessIdentityConfig.IsSetCallerReference())
                    {
                        xmlWriter.WriteElementString("CallerReference", "http://cloudfront.amazonaws.com/doc/2013-08-26/", cloudFrontOriginAccessIdentityConfigCloudFrontOriginAccessIdentityConfig.CallerReference.ToString());
                    }
                    if (cloudFrontOriginAccessIdentityConfigCloudFrontOriginAccessIdentityConfig.IsSetComment())
                    {
                        xmlWriter.WriteElementString("Comment", "http://cloudfront.amazonaws.com/doc/2013-08-26/", cloudFrontOriginAccessIdentityConfigCloudFrontOriginAccessIdentityConfig.Comment.ToString());
                    }
                    xmlWriter.WriteEndElement();
                }
            }


            try
            {
                request.Content = System.Text.Encoding.UTF8.GetBytes(stringWriter.ToString());
                request.Headers.Add("Content-Type", "application/xml");
            }
            catch (EncoderFallbackException e)
            {
                throw new AmazonServiceException("Unable to marshall request to XML", e);
            }


            return(request);
        }
        public IRequest Marshall(CreateCloudFrontOriginAccessIdentityRequest createCloudFrontOriginAccessIdentityRequest)
        {
            IRequest request = new DefaultRequest(createCloudFrontOriginAccessIdentityRequest, "AmazonCloudFront");



            request.HttpMethod = "POST";
            string uriResourcePath = "2013-11-11/origin-access-identity/cloudfront";

            if (uriResourcePath.Contains("?"))
            {
                int    queryIndex  = uriResourcePath.IndexOf("?", StringComparison.OrdinalIgnoreCase);
                string queryString = uriResourcePath.Substring(queryIndex + 1);

                uriResourcePath = uriResourcePath.Substring(0, queryIndex);


                foreach (string s in queryString.Split('&', ';'))
                {
                    string[] nameValuePair = s.Split('=');
                    if (nameValuePair.Length == 2 && nameValuePair[1].Length > 0)
                    {
                        request.Parameters.Add(nameValuePair[0], nameValuePair[1]);
                    }
                    else
                    {
                        request.Parameters.Add(nameValuePair[0], null);
                    }
                }
            }

            request.ResourcePath = uriResourcePath;


            StringWriter stringWriter = new StringWriter(CultureInfo.InvariantCulture);

            using (XmlWriter xmlWriter = XmlWriter.Create(stringWriter, new XmlWriterSettings()
            {
                Encoding = System.Text.Encoding.UTF8, OmitXmlDeclaration = true
            }))
            {
                if (createCloudFrontOriginAccessIdentityRequest != null)
                {
                    CloudFrontOriginAccessIdentityConfig cloudFrontOriginAccessIdentityConfigCloudFrontOriginAccessIdentityConfig = createCloudFrontOriginAccessIdentityRequest.CloudFrontOriginAccessIdentityConfig;
                    if (cloudFrontOriginAccessIdentityConfigCloudFrontOriginAccessIdentityConfig != null)
                    {
                        xmlWriter.WriteStartElement("CloudFrontOriginAccessIdentityConfig", "http://cloudfront.amazonaws.com/doc/2013-11-11/");
                        if (cloudFrontOriginAccessIdentityConfigCloudFrontOriginAccessIdentityConfig.IsSetCallerReference())
                        {
                            xmlWriter.WriteElementString("CallerReference", "http://cloudfront.amazonaws.com/doc/2013-11-11/", cloudFrontOriginAccessIdentityConfigCloudFrontOriginAccessIdentityConfig.CallerReference.ToString(CultureInfo.InvariantCulture));
                        }
                        if (cloudFrontOriginAccessIdentityConfigCloudFrontOriginAccessIdentityConfig.IsSetComment())
                        {
                            xmlWriter.WriteElementString("Comment", "http://cloudfront.amazonaws.com/doc/2013-11-11/", cloudFrontOriginAccessIdentityConfigCloudFrontOriginAccessIdentityConfig.Comment.ToString(CultureInfo.InvariantCulture));
                        }
                        xmlWriter.WriteEndElement();
                    }
                }
            }
            try
            {
                string content = stringWriter.ToString();
                request.Content = System.Text.Encoding.UTF8.GetBytes(content);
                request.Headers["Content-Type"] = "application/xml";
            }
            catch (EncoderFallbackException e)
            {
                throw new AmazonServiceException("Unable to marshall request to XML", e);
            }


            return(request);
        }