コード例 #1
0
        public async Task CloudBlobClientGetServiceStatsAsync()
        {
            AssertSecondaryEndpoint();

            CloudBlobClient client = GenerateCloudBlobClient();

            client.DefaultRequestOptions.LocationMode = LocationMode.SecondaryOnly;
            TestHelper.VerifyServiceStats(await client.GetServiceStatsAsync());
        }
コード例 #2
0
        public async Task CloudBlobClientGetServiceStatsInvalidLocAsync()
        {
            CloudBlobClient client = GenerateCloudBlobClient();

            client.DefaultRequestOptions.LocationMode = LocationMode.PrimaryOnly;
            try
            {
                TestHelper.VerifyServiceStats(await client.GetServiceStatsAsync());
                Assert.Fail("GetServiceStats should fail and throw an InvalidOperationException.");
            }
            catch (Exception e)
            {
                Assert.IsInstanceOfType(e, typeof(InvalidOperationException));
            }
        }
コード例 #3
0
        /// <summary>
        /// Gets the Blob service stats for the secondary endpoint for an RA-GRS (read-access geo-redundant) storage account.
        /// </summary>
        /// <param name="blobClient">The Blob service client.</param>
        /// <returns>A Task object.</returns>
        private static async Task GetServiceStatsForSecondaryAsync(CloudBlobClient blobClient)
        {
            try
            {
                // Get the URI for the secondary endpoint for Blob storage.
                Uri secondaryUri = blobClient.StorageUri.SecondaryUri;

                // Create a new service client based on the secondary endpoint.
                CloudBlobClient blobClientSecondary = new CloudBlobClient(secondaryUri, blobClient.Credentials);

                // Get the current stats for the secondary.
                // The call will fail if your storage account does not have RA-GRS enabled.
                // Change the retry policy for this call so that if it fails, it fails quickly.
                BlobRequestOptions requestOptions = new BlobRequestOptions() { RetryPolicy = new NoRetry() };
                ServiceStats blobStats = await blobClientSecondary.GetServiceStatsAsync(requestOptions, null);

                Console.WriteLine("Geo-replication status: {0}", blobStats.GeoReplication.Status);
                Console.WriteLine("Last geo-replication sync time: {0}", blobStats.GeoReplication.LastSyncTime);
                Console.WriteLine();
            }
            catch (StorageException e)
            {
                // In this case, we do not re-throw the exception, so that the sample will continue to run even if RA-GRS is not enabled
                // for this storage account.
                if (e.RequestInformation.HttpStatusCode == 403)
                {
                    Console.WriteLine("This storage account does not appear to support RA-GRS.");
                    Console.WriteLine("More information: {0}", e.Message);
                    Console.WriteLine();
                }
                else
                {
                    Console.WriteLine(e.Message);
                    Console.ReadLine();
                    throw;
                }
            }
        }