public IRequest Marshall(PutBucketInventoryConfigurationRequest putBucketInventoryConfigurationRequest)
        {
            IRequest request = new DefaultRequest(putBucketInventoryConfigurationRequest, "AmazonS3");

            request.HttpMethod = "PUT";

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

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

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

            request.AddSubResource("inventory");

            if (putBucketInventoryConfigurationRequest.IsSetInventoryId())
            {
                request.AddSubResource("id", S3Transforms.ToStringValue(putBucketInventoryConfigurationRequest.InventoryId));
            }

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

            using (var xmlWriter = XmlWriter.Create(stringWriter, new XmlWriterSettings()
            {
                Encoding = Encoding.UTF8, OmitXmlDeclaration = true
            }))
            {
                if (putBucketInventoryConfigurationRequest.IsSetInventoryConfiguration())
                {
                    var inventoryConfiguration = putBucketInventoryConfigurationRequest.InventoryConfiguration;
                    xmlWriter.WriteStartElement("InventoryConfiguration", "http://s3.amazonaws.com/doc/2006-03-01/");
                    if (inventoryConfiguration != null)
                    {
                        if (inventoryConfiguration.IsSetDestination())
                        {
                            InventoryDestination inventoryDestination = inventoryConfiguration.Destination;
                            xmlWriter.WriteStartElement("Destination", "http://s3.amazonaws.com/doc/2006-03-01/");
                            if (inventoryDestination.isSetS3BucketDestination())
                            {
                                InventoryS3BucketDestination inventoryS3BucketDestination = inventoryDestination.S3BucketDestination;
                                xmlWriter.WriteStartElement("S3BucketDestination", "http://s3.amazonaws.com/doc/2006-03-01/");
                                if (inventoryS3BucketDestination.IsSetAccountId())
                                {
                                    xmlWriter.WriteElementString("AccountId", "http://s3.amazonaws.com/doc/2006-03-01/", S3Transforms.ToXmlStringValue(inventoryS3BucketDestination.AccountId));
                                }
                                if (inventoryS3BucketDestination.IsSetBucketName())
                                {
                                    xmlWriter.WriteElementString("Bucket", "http://s3.amazonaws.com/doc/2006-03-01/", S3Transforms.ToXmlStringValue(inventoryS3BucketDestination.BucketName));
                                }
                                if (inventoryS3BucketDestination.IsSetInventoryFormat())
                                {
                                    xmlWriter.WriteElementString("Format", "http://s3.amazonaws.com/doc/2006-03-01/", S3Transforms.ToXmlStringValue(inventoryS3BucketDestination.InventoryFormat));
                                }
                                if (inventoryS3BucketDestination.IsSetPrefix())
                                {
                                    xmlWriter.WriteElementString("Prefix", "http://s3.amazonaws.com/doc/2006-03-01/", S3Transforms.ToXmlStringValue(inventoryS3BucketDestination.Prefix));
                                }
                                if (inventoryS3BucketDestination.IsSetInventoryEncryption())
                                {
                                    xmlWriter.WriteStartElement("Encryption", "http://s3.amazonaws.com/doc/2006-03-01/");
                                    var inventoryEncryption = inventoryS3BucketDestination.InventoryEncryption;
                                    if (inventoryEncryption.IsSetSSEKMS())
                                    {
                                        xmlWriter.WriteStartElement("SSE-KMS", "http://s3.amazonaws.com/doc/2006-03-01/");
                                        if (inventoryEncryption.SSEKMS.IsSetKeyId())
                                        {
                                            xmlWriter.WriteElementString("KeyId", "http://s3.amazonaws.com/doc/2006-03-01/", S3Transforms.ToXmlStringValue(inventoryEncryption.SSEKMS.KeyId));
                                        }
                                        xmlWriter.WriteEndElement();
                                    }
                                    if (inventoryEncryption.IsSetSSES3())
                                    {
                                        xmlWriter.WriteStartElement("SSE-S3", "http://s3.amazonaws.com/doc/2006-03-01/");
                                        xmlWriter.WriteEndElement();
                                    }
                                    xmlWriter.WriteEndElement();
                                }
                                xmlWriter.WriteEndElement();
                            }
                            xmlWriter.WriteEndElement();
                        }

                        xmlWriter.WriteElementString("IsEnabled", "http://s3.amazonaws.com/doc/2006-03-01/", S3Transforms.ToXmlStringValue(inventoryConfiguration.IsEnabled));

                        if (inventoryConfiguration.IsSetInventoryFilter())
                        {
                            xmlWriter.WriteStartElement("Filter", "http://s3.amazonaws.com/doc/2006-03-01/");
                            var predicate = inventoryConfiguration.InventoryFilter.InventoryFilterPredicate;
                            predicate.Accept(new InventoryPredicateVisitor(xmlWriter));
                            xmlWriter.WriteEndElement();
                        }

                        if (inventoryConfiguration.IsSetInventoryId())
                        {
                            xmlWriter.WriteElementString("Id", "http://s3.amazonaws.com/doc/2006-03-01/", S3Transforms.ToXmlStringValue(inventoryConfiguration.InventoryId));
                        }

                        if (inventoryConfiguration.IsSetIncludedObjectVersions())
                        {
                            xmlWriter.WriteElementString("IncludedObjectVersions", "http://s3.amazonaws.com/doc/2006-03-01/", S3Transforms.ToXmlStringValue(inventoryConfiguration.IncludedObjectVersions));
                        }

                        if (inventoryConfiguration.IsSetInventoryOptionalFields())
                        {
                            xmlWriter.WriteStartElement("OptionalFields", "http://s3.amazonaws.com/doc/2006-03-01/");
                            foreach (var inventoryOptionalField in inventoryConfiguration.InventoryOptionalFields)
                            {
                                xmlWriter.WriteElementString("Field", "http://s3.amazonaws.com/doc/2006-03-01/", S3Transforms.ToXmlStringValue(inventoryOptionalField));
                            }
                            xmlWriter.WriteEndElement();
                        }

                        if (inventoryConfiguration.IsSetSchedule())
                        {
                            xmlWriter.WriteStartElement("Schedule", "http://s3.amazonaws.com/doc/2006-03-01/");
                            var inventorySchedule = inventoryConfiguration.Schedule;
                            if (inventorySchedule.IsFrequency())
                            {
                                xmlWriter.WriteElementString("Frequency", "http://s3.amazonaws.com/doc/2006-03-01/", S3Transforms.ToXmlStringValue(inventorySchedule.Frequency));
                            }
                            xmlWriter.WriteEndElement();
                        }
                    }
                    xmlWriter.WriteEndElement();
                }
            }

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

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

            return(request);
        }
Beispiel #2
0
        public IRequest Marshall(PutBucketInventoryConfigurationRequest putBucketInventoryConfigurationRequest)
        {
            //IL_0006: Unknown result type (might be due to invalid IL or missing references)
            //IL_000c: Expected O, but got Unknown
            //IL_0360: Unknown result type (might be due to invalid IL or missing references)
            IRequest val = new DefaultRequest(putBucketInventoryConfigurationRequest, "AmazonS3");

            val.set_HttpMethod("PUT");
            val.set_ResourcePath("/" + S3Transforms.ToStringValue(putBucketInventoryConfigurationRequest.BucketName));
            val.AddSubResource("inventory");
            if (putBucketInventoryConfigurationRequest.IsSetInventoryId())
            {
                val.AddSubResource("id", S3Transforms.ToStringValue(putBucketInventoryConfigurationRequest.InventoryId));
            }
            StringWriter stringWriter = new StringWriter(CultureInfo.InvariantCulture);

            using (XmlWriter xmlWriter = XmlWriter.Create(stringWriter, new XmlWriterSettings
            {
                Encoding = Encoding.UTF8,
                OmitXmlDeclaration = true
            }))
            {
                if (putBucketInventoryConfigurationRequest.IsSetInventoryConfiguration())
                {
                    InventoryConfiguration inventoryConfiguration = putBucketInventoryConfigurationRequest.InventoryConfiguration;
                    xmlWriter.WriteStartElement("InventoryConfiguration", "http://s3.amazonaws.com/doc/2006-03-01/");
                    if (inventoryConfiguration != null)
                    {
                        if (inventoryConfiguration.IsSetDestination())
                        {
                            InventoryDestination destination = inventoryConfiguration.Destination;
                            xmlWriter.WriteStartElement("Destination", "http://s3.amazonaws.com/doc/2006-03-01/");
                            if (destination.isSetS3BucketDestination())
                            {
                                InventoryS3BucketDestination s3BucketDestination = destination.S3BucketDestination;
                                xmlWriter.WriteStartElement("S3BucketDestination", "http://s3.amazonaws.com/doc/2006-03-01/");
                                if (s3BucketDestination.IsSetAccountId())
                                {
                                    xmlWriter.WriteElementString("AccountId", "http://s3.amazonaws.com/doc/2006-03-01/", S3Transforms.ToXmlStringValue(s3BucketDestination.AccountId));
                                }
                                if (s3BucketDestination.IsSetBucketName())
                                {
                                    xmlWriter.WriteElementString("Bucket", "http://s3.amazonaws.com/doc/2006-03-01/", S3Transforms.ToXmlStringValue(s3BucketDestination.BucketName));
                                }
                                if (s3BucketDestination.IsSetInventoryFormat())
                                {
                                    xmlWriter.WriteElementString("Format", "http://s3.amazonaws.com/doc/2006-03-01/", S3Transforms.ToXmlStringValue(ConstantClass.op_Implicit(s3BucketDestination.InventoryFormat)));
                                }
                                if (s3BucketDestination.IsSetPrefix())
                                {
                                    xmlWriter.WriteElementString("Prefix", "http://s3.amazonaws.com/doc/2006-03-01/", S3Transforms.ToXmlStringValue(s3BucketDestination.Prefix));
                                }
                                xmlWriter.WriteEndElement();
                            }
                            xmlWriter.WriteEndElement();
                        }
                        xmlWriter.WriteElementString("IsEnabled", "http://s3.amazonaws.com/doc/2006-03-01/", inventoryConfiguration.IsEnabled.ToString().ToLowerInvariant());
                        if (inventoryConfiguration.IsSetInventoryFilter())
                        {
                            xmlWriter.WriteStartElement("Filter", "http://s3.amazonaws.com/doc/2006-03-01/");
                            inventoryConfiguration.InventoryFilter.InventoryFilterPredicate.Accept(new InventoryPredicateVisitor(xmlWriter));
                            xmlWriter.WriteEndElement();
                        }
                        if (inventoryConfiguration.IsSetInventoryId())
                        {
                            xmlWriter.WriteElementString("Id", "http://s3.amazonaws.com/doc/2006-03-01/", S3Transforms.ToXmlStringValue(inventoryConfiguration.InventoryId));
                        }
                        if (inventoryConfiguration.IsSetIncludedObjectVersions())
                        {
                            xmlWriter.WriteElementString("IncludedObjectVersions", "http://s3.amazonaws.com/doc/2006-03-01/", S3Transforms.ToXmlStringValue(ConstantClass.op_Implicit(inventoryConfiguration.IncludedObjectVersions)));
                        }
                        if (inventoryConfiguration.IsSetInventoryOptionalFields())
                        {
                            xmlWriter.WriteStartElement("OptionalFields", "http://s3.amazonaws.com/doc/2006-03-01/");
                            foreach (InventoryOptionalField inventoryOptionalField in inventoryConfiguration.InventoryOptionalFields)
                            {
                                xmlWriter.WriteElementString("Field", "http://s3.amazonaws.com/doc/2006-03-01/", S3Transforms.ToXmlStringValue(ConstantClass.op_Implicit(inventoryOptionalField)));
                            }
                            xmlWriter.WriteEndElement();
                        }
                        if (inventoryConfiguration.IsSetSchedule())
                        {
                            xmlWriter.WriteStartElement("Schedule", "http://s3.amazonaws.com/doc/2006-03-01/");
                            InventorySchedule schedule = inventoryConfiguration.Schedule;
                            if (schedule.IsFrequency())
                            {
                                xmlWriter.WriteElementString("Frequency", "http://s3.amazonaws.com/doc/2006-03-01/", S3Transforms.ToXmlStringValue(ConstantClass.op_Implicit(schedule.Frequency)));
                            }
                            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);
            }
        }