public async Task SetQueueServicePropertiesAsync(StorageServiceProperties expectedServiceProperties)
 {
     var request = new SetQueueServicePropertiesRequest(_account, expectedServiceProperties);
     await request.ExecuteAsync(_optionalRetryPolicy);
 }
 public void SetQueueServiceProperties(StorageServiceProperties expectedServiceProperties)
 {
     var request = new SetQueueServicePropertiesRequest(_account, expectedServiceProperties);
     request.Execute(_optionalRetryPolicy);
 }
        public async Task SetQueueServicePropertiesAsync_AddCorsRule_SuccessfullyAddsCorsRuleToService()
        {
            IQueueServiceClient client = new QueueServiceClient(_accountSettings);
            var expectedServiceProperties = new StorageServiceProperties();
            expectedServiceProperties.Cors.Add(new StorageServiceCorsRule()
            {
                AllowedHeaders = new List<string>() { "X-Whatever" },
                AllowedMethods = new List<string>() { "GET" },
                AllowedOrigins = new List<string>() { "a.b.c" },
                ExposedHeaders = new List<string>() { "X-Whatever" },
                MaxAgeInSeconds = 7
            });
            _util.ClearCorsRules();

            await client.SetQueueServicePropertiesAsync(expectedServiceProperties);

            var actualProperties = _util.GetServiceProperties();
            Assert.AreEqual(1, actualProperties.Cors.CorsRules.Count);
            Assert.AreEqual("X-Whatever", actualProperties.Cors.CorsRules[0].AllowedHeaders[0]);
            Assert.AreEqual(Microsoft.WindowsAzure.Storage.Shared.Protocol.CorsHttpMethods.Get, actualProperties.Cors.CorsRules[0].AllowedMethods);
            Assert.AreEqual("a.b.c", actualProperties.Cors.CorsRules[0].AllowedOrigins[0]);
            Assert.AreEqual("X-Whatever", actualProperties.Cors.CorsRules[0].ExposedHeaders[0]);
            Assert.AreEqual(7, actualProperties.Cors.CorsRules[0].MaxAgeInSeconds);
        }
        public async Task SetQueueServicePropertiesAsync_TurnOnLoggingAndMetrics_SuccessfullyTurnsOnOptionsOnService()
        {
            IQueueServiceClient client = new QueueServiceClient(_accountSettings);
            var expectedServiceProperties = new StorageServiceProperties();
            expectedServiceProperties.Logging = new StorageServiceLoggingProperties()
            {
                Delete = true,
                Read = true,
                Write = true,
                RetentionPolicyEnabled = true,
                RetentionPolicyNumberOfDays = 123
            };
            expectedServiceProperties.HourMetrics = new StorageServiceMetricsProperties()
            {
                Enabled = true,
                IncludeAPIs = true,
                RetentionPolicyEnabled = true,
                RetentionPolicyNumberOfDays = 45
            };
            expectedServiceProperties.MinuteMetrics = new StorageServiceMetricsProperties()
            {
                Enabled = true,
                IncludeAPIs = true,
                RetentionPolicyEnabled = true,
                RetentionPolicyNumberOfDays = 45
            };
            _util.SetServicePropertiesOff();

            await client.SetQueueServicePropertiesAsync(expectedServiceProperties);

            var actualProperties = _util.GetServiceProperties();
            Assert.AreEqual(Microsoft.WindowsAzure.Storage.Shared.Protocol.LoggingOperations.All, actualProperties.Logging.LoggingOperations);
            Assert.AreEqual(123, actualProperties.Logging.RetentionDays);
            Assert.AreEqual(Microsoft.WindowsAzure.Storage.Shared.Protocol.MetricsLevel.ServiceAndApi, actualProperties.HourMetrics.MetricsLevel);
            Assert.AreEqual(45, actualProperties.HourMetrics.RetentionDays);
        }
        public void SetQueueServiceProperties_TurnOffLoggingAndMetrics_SuccessfullyTurnsOffOptionsOnService()
        {
            IQueueServiceClient client = new QueueServiceClient(_accountSettings);
            var expectedServiceProperties = new StorageServiceProperties();
            expectedServiceProperties.Logging = new StorageServiceLoggingProperties()
            {
                Delete = false,
                Read = false,
                Write = false,
                RetentionPolicyEnabled = false
            };
            expectedServiceProperties.HourMetrics = new StorageServiceMetricsProperties()
            {
                Enabled = false,
                RetentionPolicyEnabled = false
            };
            expectedServiceProperties.MinuteMetrics = new StorageServiceMetricsProperties()
            {
                Enabled = false,
                RetentionPolicyEnabled = false
            };
            _util.SetServicePropertiesOn();

            client.SetQueueServiceProperties(expectedServiceProperties);

            var actualProperties = _util.GetServiceProperties();
            Assert.AreEqual(Microsoft.WindowsAzure.Storage.Shared.Protocol.LoggingOperations.None, actualProperties.Logging.LoggingOperations);
            Assert.AreEqual(Microsoft.WindowsAzure.Storage.Shared.Protocol.MetricsLevel.None, actualProperties.HourMetrics.MetricsLevel);
        }
        public async Task ParseResponseBodyAsync(Stream responseStream)
        {
            Properties = new StorageServiceProperties();

            using (StreamReader sr = new StreamReader(responseStream))
            {
                var content = await sr.ReadToEndAsync();
                if (content.Length > 0)
                {
                    var xDoc = XDocument.Parse(content);
                    foreach (var topField in xDoc.Root.Elements())
                    {
                        if (topField.Name.LocalName.Equals("Logging", StringComparison.InvariantCultureIgnoreCase))
                        {
                            foreach (var field in topField.Elements())
                            {
                                switch (field.Name.LocalName)
                                {
                                    case "Version":
                                        Properties.Logging.Version = StorageAnalyticsVersionNumber.v1_0;
                                        break;
                                    case "Delete":
                                        Properties.Logging.Delete = field.Value.Equals("true");
                                        break;
                                    case "Read":
                                        Properties.Logging.Read = field.Value.Equals("true");
                                        break;
                                    case "Write":
                                        Properties.Logging.Write = field.Value.Equals("true");
                                        break;
                                    case "RetentionPolicy":
                                        foreach (var retentionField in field.Elements())
                                        {
                                            switch (retentionField.Name.LocalName)
                                            {
                                                case "Enabled":
                                                    Properties.Logging.RetentionPolicyEnabled = retentionField.Value.Equals("true");
                                                    break;
                                                case "Days":
                                                    Properties.Logging.RetentionPolicyNumberOfDays = int.Parse(retentionField.Value);
                                                    break;
                                            }
                                        }
                                        break;
                                }
                            }
                        }
                        else if (topField.Name.LocalName.Equals("Metrics", StringComparison.InvariantCultureIgnoreCase))
                        {
                            foreach (var field in topField.Elements())
                            {
                                switch (field.Name.LocalName)
                                {
                                    case "Version":
                                        Properties.Metrics.Version = StorageAnalyticsVersionNumber.v1_0;
                                        break;
                                    case "Enabled":
                                        Properties.Metrics.Enabled = field.Value.Equals("true");
                                        break;
                                    case "IncludeAPIs":
                                        Properties.Metrics.IncludeAPIs = field.Value.Equals("true");
                                        break;
                                    case "RetentionPolicy":
                                        foreach (var retentionField in field.Elements())
                                        {
                                            switch (retentionField.Name.LocalName)
                                            {
                                                case "Enabled":
                                                    Properties.Metrics.RetentionPolicyEnabled = retentionField.Value.Equals("true");
                                                    break;
                                                case "Days":
                                                    Properties.Metrics.RetentionPolicyNumberOfDays = int.Parse(retentionField.Value);
                                                    break;
                                            }
                                        }
                                        break;
                                }
                            }
                        }
                    }

                    
                }
            }
        }