Ejemplo n.º 1
0
        public async Task CloudBlobTestAnalyticsMetricsLevelAsync()
        {
            CloudBlobClient client = GenerateCloudBlobClient();

            ServiceProperties props = await client.GetServicePropertiesAsync();

            // None
            props.Metrics.MetricsLevel  = MetricsLevel.None;
            props.Metrics.RetentionDays = null;
            props.Metrics.Version       = "1.0";
            await client.SetServicePropertiesAsync(props);

            // Wait for analytics server to update
            await Task.Delay(60 * 1000);

            AssertServicePropertiesAreEqual(props, await client.GetServicePropertiesAsync());

            // Service
            props.Metrics.MetricsLevel = MetricsLevel.Service;
            await client.SetServicePropertiesAsync(props);

            // Wait for analytics server to update
            await Task.Delay(60 * 1000);

            AssertServicePropertiesAreEqual(props, await client.GetServicePropertiesAsync());

            // ServiceAndAPI
            props.Metrics.MetricsLevel = MetricsLevel.ServiceAndApi;
            await client.SetServicePropertiesAsync(props);

            // Wait for analytics server to update
            await Task.Delay(60 * 1000);

            AssertServicePropertiesAreEqual(props, await client.GetServicePropertiesAsync());
        }
Ejemplo n.º 2
0
        public async Task CloudBlobTestAnalyticsLoggingOperationsAsync()
        {
            CloudBlobClient client = GenerateCloudBlobClient();

            ServiceProperties props = await client.GetServicePropertiesAsync();

            // None
            props.Logging.LoggingOperations = LoggingOperations.None;
            props.Logging.RetentionDays     = null;
            props.Logging.Version           = "1.0";

            await client.SetServicePropertiesAsync(props);

            // Wait for analytics server to update
            await Task.Delay(60 * 1000);

            AssertServicePropertiesAreEqual(props, await client.GetServicePropertiesAsync());

            // None
            props.Logging.LoggingOperations = LoggingOperations.All;
            await client.SetServicePropertiesAsync(props);

            // Wait for analytics server to update
            await Task.Delay(60 * 1000);

            AssertServicePropertiesAreEqual(props, await client.GetServicePropertiesAsync());
        }
        public void CloudBlobTestAnalyticsRoundTripTask()
        {
            props.Logging.LoggingOperations = LoggingOperations.Read | LoggingOperations.Write;
            props.Logging.RetentionDays     = 5;
            props.Logging.Version           = Constants.AnalyticsConstants.LoggingVersionV1;

            props.HourMetrics.MetricsLevel  = MetricsLevel.Service;
            props.HourMetrics.RetentionDays = 6;
            props.HourMetrics.Version       = Constants.AnalyticsConstants.MetricsVersionV1;

            client.SetServicePropertiesAsync(props).Wait();

            // Wait for analytics server to update
            TestHelper.SpinUpTo30SecondsIgnoringFailures(() => TestHelper.AssertServicePropertiesAreEqual(props, client.GetServicePropertiesAsync().Result));
        }
Ejemplo n.º 4
0
        public void CloudBlobTestAnalyticsRoundTripTask()
        {
            props.Logging.LoggingOperations = LoggingOperations.Read | LoggingOperations.Write;
            props.Logging.RetentionDays     = 5;
            props.Logging.Version           = Constants.AnalyticsConstants.LoggingVersionV1;

            props.HourMetrics.MetricsLevel  = MetricsLevel.Service;
            props.HourMetrics.RetentionDays = 6;
            props.HourMetrics.Version       = Constants.AnalyticsConstants.MetricsVersionV1;

            client.SetServicePropertiesAsync(props).Wait();

            // Wait for analytics server to update
            Thread.Sleep(60 * 1000);
            TestHelper.AssertServicePropertiesAreEqual(props, client.GetServicePropertiesAsync().Result);
        }
        private async Task TestCorsRulesAsync(CloudBlobClient client, OperationContext context, IList <CorsRule> corsProps)
        {
            props.Cors.CorsRules.Clear();

            foreach (CorsRule rule in corsProps)
            {
                props.Cors.CorsRules.Add(rule);
            }

            await client.SetServicePropertiesAsync(props, null, context);

            TestHelper.AssertServicePropertiesAreEqual(props, await client.GetServicePropertiesAsync());
        }
Ejemplo n.º 6
0
        public async Task CloudBlobTestAnalyticsDefaultServiceVersionAsync()
        {
            CloudBlobClient client = GenerateCloudBlobClient();

            ServiceProperties props = await client.GetServicePropertiesAsync();

            props.DefaultServiceVersion = "2009-09-19";
            await client.SetServicePropertiesAsync(props);

            // Wait for analytics server to update
            await Task.Delay(60 * 1000);

            AssertServicePropertiesAreEqual(props, await client.GetServicePropertiesAsync());

            props.DefaultServiceVersion = "2011-08-18";
            await client.SetServicePropertiesAsync(props);

            // Wait for analytics server to update
            await Task.Delay(60 * 1000);

            AssertServicePropertiesAreEqual(props, await client.GetServicePropertiesAsync());

            props.DefaultServiceVersion = "2012-02-12";
            await client.SetServicePropertiesAsync(props);

            // Wait for analytics server to update
            await Task.Delay(60 * 1000);

            AssertServicePropertiesAreEqual(props, await client.GetServicePropertiesAsync());

            props.DefaultServiceVersion = null;
            await client.SetServicePropertiesAsync(props);

            // Wait for analytics server to update
            await Task.Delay(60 * 1000);

            AssertServicePropertiesAreEqual(props, await client.GetServicePropertiesAsync());
        }
        public async Task CloudBlobClientServerTimeoutAsync()
        {
            CloudBlobClient client = GenerateCloudBlobClient();

            string           timeout = null;
            OperationContext context = new OperationContext();

            context.SendingRequest += (sender, e) =>
            {
                IDictionary <string, string> query = HttpWebUtility.ParseQueryString(e.RequestUri.Query);
                if (!query.TryGetValue("timeout", out timeout))
                {
                    timeout = null;
                }
            };

            BlobRequestOptions options = new BlobRequestOptions();
            await client.GetServicePropertiesAsync(null, context);

            Assert.IsNull(timeout);
            await client.GetServicePropertiesAsync(options, context);

            Assert.IsNull(timeout);

            options.ServerTimeout = TimeSpan.FromSeconds(100);
            await client.GetServicePropertiesAsync(options, context);

            Assert.AreEqual("100", timeout);

            client.DefaultRequestOptions.ServerTimeout = TimeSpan.FromSeconds(90);
            await client.GetServicePropertiesAsync(null, context);

            Assert.AreEqual("90", timeout);
            await client.GetServicePropertiesAsync(options, context);

            Assert.AreEqual("100", timeout);

            options.ServerTimeout = null;
            await client.GetServicePropertiesAsync(options, context);

            Assert.AreEqual("90", timeout);

            options.ServerTimeout = TimeSpan.Zero;
            await client.GetServicePropertiesAsync(options, context);

            Assert.IsNull(timeout);
        }
Ejemplo n.º 8
0
        public void BlobGetSetServicePropertiesTask()
        {
            CloudBlobClient blobClient = GenerateCloudBlobClient();

            ServiceProperties serviceProperties = new ServiceProperties();

            serviceProperties.Logging.LoggingOperations = LoggingOperations.Read | LoggingOperations.Write | LoggingOperations.Delete;
            serviceProperties.Logging.RetentionDays     = 8;
            serviceProperties.Logging.Version           = "1.0";
            serviceProperties.Metrics.MetricsLevel      = MetricsLevel.Service;
            serviceProperties.Metrics.RetentionDays     = 8;
            serviceProperties.Metrics.Version           = "1.0";

            blobClient.SetServicePropertiesAsync(serviceProperties).Wait();

            ServiceProperties actual = blobClient.GetServicePropertiesAsync().Result;

            AssertServicePropertiesAreEqual(serviceProperties, actual);
        }
Ejemplo n.º 9
0
        public void CloudBlobTestAnalyticsRoundTripTask()
        {
            CloudBlobClient client = GenerateCloudBlobClient();

            ServiceProperties props = new ServiceProperties();

            props.Logging.LoggingOperations = LoggingOperations.Read | LoggingOperations.Write;
            props.Logging.RetentionDays     = 5;
            props.Logging.Version           = "1.0";

            props.Metrics.MetricsLevel  = MetricsLevel.Service;
            props.Metrics.RetentionDays = 6;
            props.Metrics.Version       = "1.0";

            client.SetServicePropertiesAsync(props).Wait();

            // Wait for analytics server to update
            Thread.Sleep(60 * 1000);
            AssertServicePropertiesAreEqual(props, client.GetServicePropertiesAsync().Result);
        }
Ejemplo n.º 10
0
        public void BlobGetSetServicePropertiesRequestOptionsOperationContextTask()
        {
            CloudBlobClient    blobClient       = GenerateCloudBlobClient();
            BlobRequestOptions requestOptions   = new BlobRequestOptions();
            OperationContext   operationContext = new OperationContext();

            ServiceProperties serviceProperties = new ServiceProperties();

            serviceProperties.Logging.LoggingOperations = LoggingOperations.Read | LoggingOperations.Write | LoggingOperations.Delete;
            serviceProperties.Logging.RetentionDays     = 10;
            serviceProperties.Logging.Version           = "1.0";
            serviceProperties.Metrics.MetricsLevel      = MetricsLevel.Service;
            serviceProperties.Metrics.RetentionDays     = 10;
            serviceProperties.Metrics.Version           = "1.0";

            blobClient.SetServicePropertiesAsync(serviceProperties, requestOptions, operationContext).Wait();

            ServiceProperties actual = blobClient.GetServicePropertiesAsync(requestOptions, operationContext).Result;

            AssertServicePropertiesAreEqual(serviceProperties, actual);
        }
Ejemplo n.º 11
0
        public async Task CloudBlobTestAnalyticsRoundTripAsync()
        {
            CloudBlobClient client = GenerateCloudBlobClient();

            ServiceProperties props = new ServiceProperties();

            props.Logging.LoggingOperations = LoggingOperations.Read | LoggingOperations.Write;
            props.Logging.RetentionDays     = 5;
            props.Logging.Version           = "1.0";

            props.Metrics.MetricsLevel  = MetricsLevel.Service;
            props.Metrics.RetentionDays = 6;
            props.Metrics.Version       = "1.0";

            await client.SetServicePropertiesAsync(props);

            // Wait for analytics server to update
            await Task.Delay(60 * 1000);

            AssertServicePropertiesAreEqual(props, await client.GetServicePropertiesAsync());
        }
 public static void MyClassInitialize(TestContext testContext)
 {
     client          = GenerateCloudBlobClient();
     startProperties = client.GetServicePropertiesAsync().AsTask().Result;
 }
        public async Task CloudBlobTestAnalyticsRoundTripAsync()
        {
            props.Logging.LoggingOperations = LoggingOperations.Read | LoggingOperations.Write;
            props.Logging.RetentionDays     = 5;
            props.Logging.Version           = "1.0";

            props.HourMetrics.MetricsLevel  = MetricsLevel.Service;
            props.HourMetrics.RetentionDays = 6;
            props.HourMetrics.Version       = "1.0";

            props.MinuteMetrics.MetricsLevel  = MetricsLevel.Service;
            props.MinuteMetrics.RetentionDays = 6;
            props.MinuteMetrics.Version       = "1.0";

            props.Cors.CorsRules.Add(
                new CorsRule()
            {
                AllowedOrigins = new List <string>()
                {
                    "www.ab.com", "www.bc.com"
                },
                AllowedMethods  = CorsHttpMethods.Get | CorsHttpMethods.Put,
                MaxAgeInSeconds = 500,
                ExposedHeaders  =
                    new List <string>()
                {
                    "x-ms-meta-data*",
                    "x-ms-meta-source*",
                    "x-ms-meta-abc",
                    "x-ms-meta-bcd"
                },
                AllowedHeaders =
                    new List <string>()
                {
                    "x-ms-meta-data*",
                    "x-ms-meta-target*",
                    "x-ms-meta-xyz",
                    "x-ms-meta-foo"
                }
            });

            await client.SetServicePropertiesAsync(props);

            TestHelper.AssertServicePropertiesAreEqual(props, await client.GetServicePropertiesAsync());
        }
 public static void MyClassInitialize(TestContext testContext)
 {
     client = GenerateCloudBlobClient();
     startProperties = client.GetServicePropertiesAsync().AsTask().Result;
 }
        private async Task TestCorsRulesAsync(CloudBlobClient client, OperationContext context, IList<CorsRule> corsProps)
        {
            props.Cors.CorsRules.Clear();

            foreach (CorsRule rule in corsProps)
            {
                props.Cors.CorsRules.Add(rule);
            }

            await client.SetServicePropertiesAsync(props, null, context);
            TestHelper.AssertServicePropertiesAreEqual(props, await client.GetServicePropertiesAsync());
        }
        public async Task CloudBlobTestAnalyticsRoundTripAsync()
        {
            props.Logging.LoggingOperations = LoggingOperations.Read | LoggingOperations.Write;
            props.Logging.RetentionDays     = 5;
            props.Logging.Version           = "1.0";

            props.HourMetrics.MetricsLevel  = MetricsLevel.Service;
            props.HourMetrics.RetentionDays = 6;
            props.HourMetrics.Version       = "1.0";

            props.StaticWebsite.Enabled              = true;
            props.StaticWebsite.IndexDocument        = "myindex.html";
            props.StaticWebsite.ErrorDocument404Path = "errors/error/404error.html";

            await client.SetServicePropertiesAsync(props);

            // Wait for analytics server to update
            await Task.Delay(60 * 1000);

            AssertServicePropertiesAreEqual(props, await client.GetServicePropertiesAsync());
        }
        //******************
        //*                *
        //*  LoadLeftPane  *
        //*                *
        //******************
        // Load a list of storage containers/queues/tables into the left pane of the storage view.

        public async Task LoadLeftPaneAsync()
        {
            Cursor = Cursors.Wait;

            NewAction();

            AccountTitle.Text = Account.Name;

            ClearMainPane();

            CloudStorageAccount account = OpenStorageAccount();

            blobClient = account.CreateCloudBlobClient();
            tableClient = account.CreateCloudTableClient();
            queueClient = account.CreateCloudQueueClient();

            try
            {
                var serviceProperties = await blobClient.GetServicePropertiesAsync();

                if (serviceProperties.Cors.CorsRules.Count == 0)
                {
                    ButtonBlobServiceCORSIcon.Source = new BitmapImage(new Uri("pack://application:,,/Images/unchecked.png"));
                    ButtonBlobServiceCORSLabel.Text = "CORS";
                }
                else
                {
                    ButtonBlobServiceCORSIcon.Source = new BitmapImage(new Uri("pack://application:,,/Images/checked.png"));
                    ButtonBlobServiceCORSLabel.Text = "CORS (" + serviceProperties.Cors.CorsRules.Count.ToString() + ")";
                }
            }
            catch (Exception)
            {
                // Disallowed for developer storage account.
            }

            try
            {
                blobSection.Items.Clear();
                queueSection.Items.Clear();
                tableSection.Items.Clear();

                var tasks = new Task[] { LoadLogsContainerAsync(), LoadBlobContainersAsync(), LoadQueuesAsync(), LoadTablesAsync() };
                await Task.WhenAll(tasks);

                //switch (itemType)
                //{
                //    case ItemType.BLOB_SERVICE:
                //    case ItemType.BLOB_CONTAINER:
                //        blobSection.IsExpanded = true;
                //        break;
                //    case ItemType.QUEUE_SERVICE:
                //    case ItemType.QUEUE_CONTAINER:
                //        queueSection.IsExpanded = true;
                //        break;
                //    case ItemType.TABLE_SERVICE:
                //    case ItemType.TABLE_CONTAINER:
                //        tableSection.IsExpanded = true;
                //        break;
                //    default:
                //        blobSection.IsExpanded = true;
                //        break;
                //}
            }
            catch (Exception ex)
            {
                ShowError("Error enumerating in storage account: " + ex.Message);
            }

            Cursor = Cursors.Arrow;
        }
        /// <summary>
        /// Configures logging and metrics for Blob storage, as well as the default service version.
        /// Note that if you have already enabled analytics for your storage account, running this sample 
        /// will change those settings. For that reason, it's best to run with a test storage account if possible.
        /// The sample saves your settings and resets them after it has completed running.
        /// </summary>
        /// <param name="blobClient">The Blob service client.</param>
        /// <returns>A Task object.</returns>
        private static async Task ConfigureBlobAnalyticsAsync(CloudBlobClient blobClient)
        {
            try
            {
                // Get current service property settings.
                ServiceProperties serviceProperties = await blobClient.GetServicePropertiesAsync();

                // Enable analytics logging and set retention policy to 14 days. 
                serviceProperties.Logging.LoggingOperations = LoggingOperations.All;
                serviceProperties.Logging.RetentionDays = 14;
                serviceProperties.Logging.Version = "1.0";

                // Configure service properties for hourly and minute metrics. 
                // Set retention policy to 7 days.
                serviceProperties.HourMetrics.MetricsLevel = MetricsLevel.ServiceAndApi;
                serviceProperties.HourMetrics.RetentionDays = 7;
                serviceProperties.HourMetrics.Version = "1.0";

                serviceProperties.MinuteMetrics.MetricsLevel = MetricsLevel.ServiceAndApi;
                serviceProperties.MinuteMetrics.RetentionDays = 7;
                serviceProperties.MinuteMetrics.Version = "1.0";

                // Set the default service version to be used for anonymous requests.
                serviceProperties.DefaultServiceVersion = "2015-04-05";

                // Set the service properties.
                await blobClient.SetServicePropertiesAsync(serviceProperties);            
            }
            catch (StorageException e)
            {
                Console.WriteLine(e.Message);
                Console.ReadLine();
                throw;
            }
        }
 public static async Task MyClassInitialize(TestContext testContext)
 {
     client = GenerateCloudBlobClient();
     startProperties = await client.GetServicePropertiesAsync();
 }
Ejemplo n.º 20
0
        public async Task CloudBlobTestAnalyticsRetentionPoliciesAsync()
        {
            CloudBlobClient client = GenerateCloudBlobClient();

            ServiceProperties props = await client.GetServicePropertiesAsync();

            // Set retention policy null with metrics disabled.
            props.Metrics.RetentionDays = null;
            props.Metrics.MetricsLevel  = MetricsLevel.None;
            await client.SetServicePropertiesAsync(props);

            // Wait for analytics server to update
            await Task.Delay(60 * 1000);

            AssertServicePropertiesAreEqual(props, await client.GetServicePropertiesAsync());

            // Set retention policy not null with metrics disabled.
            props.Metrics.RetentionDays = 1;
            props.Metrics.MetricsLevel  = MetricsLevel.Service;
            await client.SetServicePropertiesAsync(props);

            // Wait for analytics server to update
            await Task.Delay(60 * 1000);

            AssertServicePropertiesAreEqual(props, await client.GetServicePropertiesAsync());

            // Set retention policy not null with metrics enabled.
            props.Metrics.MetricsLevel  = MetricsLevel.ServiceAndApi;
            props.Metrics.RetentionDays = 2;
            await client.SetServicePropertiesAsync(props);

            // Wait for analytics server to update
            await Task.Delay(60 * 1000);

            AssertServicePropertiesAreEqual(props, await client.GetServicePropertiesAsync());

            // Set retention policy null with logging disabled.
            props.Logging.RetentionDays     = null;
            props.Logging.LoggingOperations = LoggingOperations.None;
            await client.SetServicePropertiesAsync(props);

            // Wait for analytics server to update
            await Task.Delay(60 * 1000);

            AssertServicePropertiesAreEqual(props, await client.GetServicePropertiesAsync());

            // Set retention policy not null with logging disabled.
            props.Logging.RetentionDays     = 3;
            props.Logging.LoggingOperations = LoggingOperations.None;
            await client.SetServicePropertiesAsync(props);

            // Wait for analytics server to update
            await Task.Delay(60 * 1000);

            AssertServicePropertiesAreEqual(props, await client.GetServicePropertiesAsync());

            // Set retention policy null with logging enabled.
            props.Logging.RetentionDays     = null;
            props.Logging.LoggingOperations = LoggingOperations.All;
            await client.SetServicePropertiesAsync(props);

            // Wait for analytics server to update
            await Task.Delay(60 * 1000);

            AssertServicePropertiesAreEqual(props, await client.GetServicePropertiesAsync());

            // Set retention policy not null with logging enabled.
            props.Logging.RetentionDays     = 4;
            props.Logging.LoggingOperations = LoggingOperations.All;
            await client.SetServicePropertiesAsync(props);

            // Wait for analytics server to update
            await Task.Delay(60 * 1000);

            AssertServicePropertiesAreEqual(props, await client.GetServicePropertiesAsync());
        }
Ejemplo n.º 21
0
 public static async Task MyClassInitialize(TestContext testContext)
 {
     client          = GenerateCloudBlobClient();
     startProperties = await client.GetServicePropertiesAsync();
 }
        /// <summary>
        /// Query the Cross-Origin Resource Sharing (CORS) rules for the Queue service
        /// </summary>
        /// <param name="blobClient"></param>
        private static async Task CorsSample(CloudBlobClient blobClient)
        {
            // Get CORS rules
            Console.WriteLine("Get CORS rules");

            ServiceProperties serviceProperties = await blobClient.GetServicePropertiesAsync();

            // Add CORS rule
            Console.WriteLine("Add CORS rule");

            CorsRule corsRule = new CorsRule
            {
                AllowedHeaders = new List<string> { "*" },
                AllowedMethods = CorsHttpMethods.Get,
                AllowedOrigins = new List<string> { "*" },
                ExposedHeaders = new List<string> { "*" },
                MaxAgeInSeconds = 3600
            };

            serviceProperties.Cors.CorsRules.Add(corsRule);
            await blobClient.SetServicePropertiesAsync(serviceProperties);
            Console.WriteLine();
        }