Ejemplo n.º 1
0
        public IRequest Marshall(PutBucketAnalyticsConfigurationRequest putBucketAnalyticsConfigurationRequest)
        {
            IRequest request = new DefaultRequest(putBucketAnalyticsConfigurationRequest, "AmazonS3");

            request.HttpMethod = "PUT";

            if (putBucketAnalyticsConfigurationRequest.IsSetExpectedBucketOwner())
            {
                request.Headers.Add(S3Constants.AmzHeaderExpectedBucketOwner, S3Transforms.ToStringValue(putBucketAnalyticsConfigurationRequest.ExpectedBucketOwner));
            }

            if (string.IsNullOrEmpty(putBucketAnalyticsConfigurationRequest.BucketName))
            {
                throw new System.ArgumentException("BucketName is a required property and must be set before making this call.", "PutBucketAnalyticsConfigurationRequest.BucketName");
            }

            request.MarshallerVersion = 2;
            request.ResourcePath      = string.Concat("/", S3Transforms.ToStringValue(putBucketAnalyticsConfigurationRequest.BucketName));

            request.AddSubResource("analytics");

            if (putBucketAnalyticsConfigurationRequest.IsSetAnalyticsId())
            {
                request.AddSubResource("id", S3Transforms.ToStringValue(putBucketAnalyticsConfigurationRequest.AnalyticsId));
            }

            var stringWriter = new StringWriter(System.Globalization.CultureInfo.InvariantCulture);

            using (var xmlWriter = XmlWriter.Create(stringWriter, new XmlWriterSettings()
            {
                Encoding = Encoding.UTF8, OmitXmlDeclaration = true
            }))
            {
                if (putBucketAnalyticsConfigurationRequest.IsSetAnalyticsConfiguration())
                {
                    var analyticsConfiguration = putBucketAnalyticsConfigurationRequest.AnalyticsConfiguration;
                    xmlWriter.WriteStartElement("AnalyticsConfiguration", "http://s3.amazonaws.com/doc/2006-03-01/");
                    if (analyticsConfiguration.IsSetAnalyticsId())
                    {
                        xmlWriter.WriteElementString("Id", "http://s3.amazonaws.com/doc/2006-03-01/", analyticsConfiguration.AnalyticsId);
                    }
                    if (analyticsConfiguration.IsSetAnalyticsFilter())
                    {
                        xmlWriter.WriteStartElement("Filter", "http://s3.amazonaws.com/doc/2006-03-01/");
                        var predicate = analyticsConfiguration.AnalyticsFilter.AnalyticsFilterPredicate;
                        predicate.Accept(new AnalyticsPredicateVisitor(xmlWriter));
                        xmlWriter.WriteEndElement();
                    }
                    if (analyticsConfiguration.IsSetStorageClassAnalysis())
                    {
                        if (analyticsConfiguration.IsSetStorageClassAnalysis())
                        {
                            StorageClassAnalysis storageClassAnalysis = analyticsConfiguration.StorageClassAnalysis;
                            xmlWriter.WriteStartElement("StorageClassAnalysis", "http://s3.amazonaws.com/doc/2006-03-01/");
                            if (storageClassAnalysis.IsSetDataExport())
                            {
                                xmlWriter.WriteStartElement("DataExport", "http://s3.amazonaws.com/doc/2006-03-01/");
                                StorageClassAnalysisDataExport storageClassAnalysisDataExport = storageClassAnalysis.DataExport;
                                if (storageClassAnalysisDataExport.IsSetOutputSchemaVersion())
                                {
                                    StorageClassAnalysisSchemaVersion storageClassAnalysisSchemaVersion = storageClassAnalysisDataExport.OutputSchemaVersion;
                                    if (storageClassAnalysisSchemaVersion != null)
                                    {
                                        xmlWriter.WriteElementString("OutputSchemaVersion", "http://s3.amazonaws.com/doc/2006-03-01/", storageClassAnalysisSchemaVersion);
                                    }
                                }
                                if (storageClassAnalysisDataExport.IsSetDestination())
                                {
                                    xmlWriter.WriteStartElement("Destination", "http://s3.amazonaws.com/doc/2006-03-01/");
                                    AnalyticsExportDestination analyticsExportDestination = storageClassAnalysisDataExport.Destination;
                                    if (analyticsExportDestination.IsSetS3BucketDestination())
                                    {
                                        xmlWriter.WriteStartElement("S3BucketDestination", "http://s3.amazonaws.com/doc/2006-03-01/");
                                        AnalyticsS3BucketDestination analyticsS3BucketDestination = analyticsExportDestination.S3BucketDestination;
                                        if (analyticsS3BucketDestination.IsSetFormat())
                                        {
                                            xmlWriter.WriteElementString("Format", "http://s3.amazonaws.com/doc/2006-03-01/", analyticsS3BucketDestination.Format);
                                        }
                                        if (analyticsS3BucketDestination.IsSetBucketAccountId())
                                        {
                                            xmlWriter.WriteElementString("BucketAccountId", "http://s3.amazonaws.com/doc/2006-03-01/", analyticsS3BucketDestination.BucketAccountId);
                                        }
                                        if (analyticsS3BucketDestination.IsSetBucketName())
                                        {
                                            xmlWriter.WriteElementString("Bucket", "http://s3.amazonaws.com/doc/2006-03-01/", analyticsS3BucketDestination.BucketName);
                                        }
                                        if (analyticsS3BucketDestination.IsSetPrefix())
                                        {
                                            xmlWriter.WriteElementString("Prefix", "http://s3.amazonaws.com/doc/2006-03-01/", analyticsS3BucketDestination.Prefix);
                                        }
                                        xmlWriter.WriteEndElement();
                                    }
                                    xmlWriter.WriteEndElement();
                                }
                                xmlWriter.WriteEndElement();
                            }
                            xmlWriter.WriteEndElement();
                        }
                    }
                    xmlWriter.WriteEndElement();
                }
            }

            try
            {
                var content = stringWriter.ToString();
                request.Content = Encoding.UTF8.GetBytes(content);
                request.Headers[HeaderKeys.ContentTypeHeader] = "application/xml";

                var checksum = AmazonS3Util.GenerateChecksumForContent(content, true);
                request.Headers[HeaderKeys.ContentMD5Header] = checksum;
            }
            catch (EncoderFallbackException e)
            {
                throw new AmazonServiceException("Unable to marshall request to XML", e);
            }

            return(request);
        }
        public IRequest Marshall(PutBucketAnalyticsConfigurationRequest putBucketAnalyticsConfigurationRequest)
        {
            //IL_0006: Unknown result type (might be due to invalid IL or missing references)
            //IL_000c: Expected O, but got Unknown
            //IL_02c9: Unknown result type (might be due to invalid IL or missing references)
            IRequest val = new DefaultRequest(putBucketAnalyticsConfigurationRequest, "AmazonS3");

            val.set_HttpMethod("PUT");
            val.set_ResourcePath("/" + S3Transforms.ToStringValue(putBucketAnalyticsConfigurationRequest.BucketName));
            val.AddSubResource("analytics");
            if (putBucketAnalyticsConfigurationRequest.IsSetAnalyticsId())
            {
                val.AddSubResource("id", S3Transforms.ToStringValue(putBucketAnalyticsConfigurationRequest.AnalyticsId));
            }
            StringWriter stringWriter = new StringWriter(CultureInfo.InvariantCulture);

            using (XmlWriter xmlWriter = XmlWriter.Create(stringWriter, new XmlWriterSettings
            {
                Encoding = Encoding.UTF8,
                OmitXmlDeclaration = true
            }))
            {
                if (putBucketAnalyticsConfigurationRequest.IsSetAnalyticsConfiguration())
                {
                    AnalyticsConfiguration analyticsConfiguration = putBucketAnalyticsConfigurationRequest.AnalyticsConfiguration;
                    xmlWriter.WriteStartElement("AnalyticsConfiguration", "http://s3.amazonaws.com/doc/2006-03-01/");
                    if (analyticsConfiguration.IsSetAnalyticsId())
                    {
                        xmlWriter.WriteElementString("Id", "http://s3.amazonaws.com/doc/2006-03-01/", analyticsConfiguration.AnalyticsId);
                    }
                    if (analyticsConfiguration.IsSetAnalyticsFilter())
                    {
                        xmlWriter.WriteStartElement("Filter", "http://s3.amazonaws.com/doc/2006-03-01/");
                        analyticsConfiguration.AnalyticsFilter.AnalyticsFilterPredicate.Accept(new AnalyticsPredicateVisitor(xmlWriter));
                        xmlWriter.WriteEndElement();
                    }
                    if (analyticsConfiguration.IsSetStorageClassAnalysis() && analyticsConfiguration.IsSetStorageClassAnalysis())
                    {
                        StorageClassAnalysis storageClassAnalysis = analyticsConfiguration.StorageClassAnalysis;
                        xmlWriter.WriteStartElement("StorageClassAnalysis", "http://s3.amazonaws.com/doc/2006-03-01/");
                        if (storageClassAnalysis.IsSetDataExport())
                        {
                            xmlWriter.WriteStartElement("DataExport", "http://s3.amazonaws.com/doc/2006-03-01/");
                            StorageClassAnalysisDataExport dataExport = storageClassAnalysis.DataExport;
                            if (dataExport.IsSetOutputSchemaVersion())
                            {
                                StorageClassAnalysisSchemaVersion outputSchemaVersion = dataExport.OutputSchemaVersion;
                                if (outputSchemaVersion != null)
                                {
                                    xmlWriter.WriteElementString("OutputSchemaVersion", "http://s3.amazonaws.com/doc/2006-03-01/", ConstantClass.op_Implicit(outputSchemaVersion));
                                }
                            }
                            if (dataExport.IsSetDestination())
                            {
                                xmlWriter.WriteStartElement("Destination", "http://s3.amazonaws.com/doc/2006-03-01/");
                                AnalyticsExportDestination destination = dataExport.Destination;
                                if (destination.IsSetS3BucketDestination())
                                {
                                    xmlWriter.WriteStartElement("S3BucketDestination", "http://s3.amazonaws.com/doc/2006-03-01/");
                                    AnalyticsS3BucketDestination s3BucketDestination = destination.S3BucketDestination;
                                    if (s3BucketDestination.IsSetFormat())
                                    {
                                        xmlWriter.WriteElementString("Format", "http://s3.amazonaws.com/doc/2006-03-01/", s3BucketDestination.Format);
                                    }
                                    if (s3BucketDestination.IsSetBucketAccountId())
                                    {
                                        xmlWriter.WriteElementString("BucketAccountId", "http://s3.amazonaws.com/doc/2006-03-01/", s3BucketDestination.BucketAccountId);
                                    }
                                    if (s3BucketDestination.IsSetBucketName())
                                    {
                                        xmlWriter.WriteElementString("Bucket", "http://s3.amazonaws.com/doc/2006-03-01/", s3BucketDestination.BucketName);
                                    }
                                    if (s3BucketDestination.IsSetPrefix())
                                    {
                                        xmlWriter.WriteElementString("Prefix", "http://s3.amazonaws.com/doc/2006-03-01/", s3BucketDestination.Prefix);
                                    }
                                    xmlWriter.WriteEndElement();
                                }
                                xmlWriter.WriteEndElement();
                            }
                            xmlWriter.WriteEndElement();
                        }
                        xmlWriter.WriteEndElement();
                    }
                    xmlWriter.WriteEndElement();
                }
            }
            try
            {
                string text = stringWriter.ToString();
                val.set_Content(Encoding.UTF8.GetBytes(text));
                val.get_Headers()["Content-Type"] = "application/xml";
                string value = AmazonS3Util.GenerateChecksumForContent(text, fBase64Encode: true);
                val.get_Headers()["Content-MD5"] = value;
                return(val);
            }
            catch (EncoderFallbackException ex)
            {
                throw new AmazonServiceException("Unable to marshall request to XML", (Exception)ex);
            }
        }