Beispiel #1
0
        public IRequest Marshall(CreateHostedZoneRequest createHostedZoneRequest)
        {
            IRequest request = new DefaultRequest(createHostedZoneRequest, "AmazonRoute53");



            request.HttpMethod = "POST";

            string uriResourcePath = "/2012-12-12/hostedzone";

            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;


            xmlWriter.WriteStartElement("CreateHostedZoneRequest", "https://route53.amazonaws.com/doc/2012-12-12/");
            if (createHostedZoneRequest.IsSetName())
            {
                xmlWriter.WriteElementString("Name", "https://route53.amazonaws.com/doc/2012-12-12/", createHostedZoneRequest.Name.ToString());
            }
            if (createHostedZoneRequest.IsSetCallerReference())
            {
                xmlWriter.WriteElementString("CallerReference", "https://route53.amazonaws.com/doc/2012-12-12/", createHostedZoneRequest.CallerReference.ToString());
            }
            if (createHostedZoneRequest != null)
            {
                HostedZoneConfig hostedZoneConfigHostedZoneConfig = createHostedZoneRequest.HostedZoneConfig;
                if (hostedZoneConfigHostedZoneConfig != null)
                {
                    xmlWriter.WriteStartElement("HostedZoneConfig", "https://route53.amazonaws.com/doc/2012-12-12/");
                    if (hostedZoneConfigHostedZoneConfig.IsSetComment())
                    {
                        xmlWriter.WriteElementString("Comment", "https://route53.amazonaws.com/doc/2012-12-12/", hostedZoneConfigHostedZoneConfig.Comment.ToString());
                    }
                    xmlWriter.WriteEndElement();
                }
            }

            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);
        }
Beispiel #2
0
        public IRequest Marshall(CreateHostedZoneRequest createHostedZoneRequest)
        {
            IRequest request = new DefaultRequest(createHostedZoneRequest, "AmazonRoute53");



            request.HttpMethod = "POST";
            string uriResourcePath = "/2013-04-01/hostedzone";

            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
            }))
            {
                xmlWriter.WriteStartElement("CreateHostedZoneRequest", "https://route53.amazonaws.com/doc/2013-04-01/");
                if (createHostedZoneRequest.IsSetName())
                {
                    xmlWriter.WriteElementString("Name", "https://route53.amazonaws.com/doc/2013-04-01/", createHostedZoneRequest.Name.ToString(CultureInfo.InvariantCulture));
                }
                if (createHostedZoneRequest.IsSetCallerReference())
                {
                    xmlWriter.WriteElementString("CallerReference", "https://route53.amazonaws.com/doc/2013-04-01/", createHostedZoneRequest.CallerReference.ToString(CultureInfo.InvariantCulture));
                }
                if (createHostedZoneRequest != null)
                {
                    HostedZoneConfig hostedZoneConfigHostedZoneConfig = createHostedZoneRequest.HostedZoneConfig;
                    if (hostedZoneConfigHostedZoneConfig != null)
                    {
                        xmlWriter.WriteStartElement("HostedZoneConfig", "https://route53.amazonaws.com/doc/2013-04-01/");
                        if (hostedZoneConfigHostedZoneConfig.IsSetComment())
                        {
                            xmlWriter.WriteElementString("Comment", "https://route53.amazonaws.com/doc/2013-04-01/", hostedZoneConfigHostedZoneConfig.Comment.ToString(CultureInfo.InvariantCulture));
                        }
                        xmlWriter.WriteEndElement();
                    }
                }

                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);
        }