当前位置: 首页>>代码示例>>C#>>正文


C# CloudBlobContainer.FetchAttributesAsync方法代码示例

本文整理汇总了C#中Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer.FetchAttributesAsync方法的典型用法代码示例。如果您正苦于以下问题:C# CloudBlobContainer.FetchAttributesAsync方法的具体用法?C# CloudBlobContainer.FetchAttributesAsync怎么用?C# CloudBlobContainer.FetchAttributesAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer的用法示例。


在下文中一共展示了CloudBlobContainer.FetchAttributesAsync方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestAccessAsync

        private static async Task TestAccessAsync(BlobContainerPublicAccessType accessType, CloudBlobContainer container, CloudBlob inputBlob)
        {
            StorageCredentials credentials = new StorageCredentials();
            container = new CloudBlobContainer(container.Uri, credentials);
            CloudPageBlob blob = new CloudPageBlob(inputBlob.Uri, credentials);
            OperationContext context = new OperationContext();
            BlobRequestOptions options = new BlobRequestOptions();

            if (accessType.Equals(BlobContainerPublicAccessType.Container))
            {
                await blob.FetchAttributesAsync();
                await container.ListBlobsSegmentedAsync(null, true, BlobListingDetails.All, null, null, options, context);
                await container.FetchAttributesAsync();
            }
            else if (accessType.Equals(BlobContainerPublicAccessType.Blob))
            {
                await blob.FetchAttributesAsync();
                await TestHelper.ExpectedExceptionAsync(
                    async () => await container.ListBlobsSegmentedAsync(null, true, BlobListingDetails.All, null, null, options, context),
                    context,
                    "List blobs while public access does not allow for listing",
                    HttpStatusCode.NotFound);
                await TestHelper.ExpectedExceptionAsync(
                    async () => await container.FetchAttributesAsync(null, options, context),
                    context,
                    "Fetch container attributes while public access does not allow",
                    HttpStatusCode.NotFound);
            }
            else
            {
                await TestHelper.ExpectedExceptionAsync(
                    async () => await blob.FetchAttributesAsync(null, options, context),
                    context,
                    "Fetch blob attributes while public access does not allow",
                    HttpStatusCode.NotFound);
                await TestHelper.ExpectedExceptionAsync(
                    async () => await container.ListBlobsSegmentedAsync(null, true, BlobListingDetails.All, null, null, options, context),
                    context,
                    "List blobs while public access does not allow for listing",
                    HttpStatusCode.NotFound);
                await TestHelper.ExpectedExceptionAsync(
                    async () => await container.FetchAttributesAsync(null, options, context),
                    context,
                    "Fetch container attributes while public access does not allow",
                    HttpStatusCode.NotFound);
            }
        }
开发者ID:Gajendra-Bahakar,项目名称:azure-storage-net,代码行数:47,代码来源:CloudBlobContainerTest.cs

示例2: CallContainerSamples

        /// <summary>
        /// Calls samples that demonstrate how to work with a blob container.
        /// </summary>
        /// <param name="container">A CloudBlobContainer object.</param>
        /// <returns>A Task object.</returns>
        private static async Task CallContainerSamples(CloudBlobContainer container)
        {
            // Fetch container attributes in order to populate the container's properties and metadata.
            await container.FetchAttributesAsync();

            // Read container metadata and properties.
            PrintContainerPropertiesAndMetadata(container);

            // Add container metadata.
            await AddContainerMetadataAsync(container);

            // Fetch the container's attributes again, and read container metadata to see the new additions.
            await container.FetchAttributesAsync();
            PrintContainerPropertiesAndMetadata(container);

            // Make the container available for public access.
            // With Container-level permissions, container and blob data can be read via anonymous request. 
            // Clients can enumerate blobs within the container via anonymous request, but cannot enumerate containers.
            await SetAnonymousAccessLevelAsync(container, BlobContainerPublicAccessType.Container);

            // Try an anonymous operation to read container properties and metadata.
            Uri containerUri = container.Uri;

            // Note that we obtain the container reference using only the URI. No account credentials are used.
            CloudBlobContainer publicContainer = new CloudBlobContainer(containerUri);
            Console.WriteLine("Read container metadata anonymously");
            await container.FetchAttributesAsync();
            PrintContainerPropertiesAndMetadata(container);

            // Make the container private again.
            await SetAnonymousAccessLevelAsync(container, BlobContainerPublicAccessType.Off);

            // Test container lease conditions.
            // This code creates and deletes additional containers.
            await ManageContainerLeasesAsync(container.ServiceClient);
        }
开发者ID:tamram,项目名称:storage-blob-dotnet-getting-started,代码行数:41,代码来源:Advanced.cs

示例3: ContainerReadWriteExpectLeaseSuccessAsync

 /// <summary>
 /// Test container reads and writes, expecting success.
 /// </summary>
 /// <param name="testContainer">The container.</param>
 /// <param name="testAccessCondition">The access condition to use.</param>
 private async Task ContainerReadWriteExpectLeaseSuccessAsync(CloudBlobContainer testContainer, AccessCondition testAccessCondition)
 {
     await testContainer.FetchAttributesAsync(testAccessCondition, null /* options */, null);
     await testContainer.GetPermissionsAsync(testAccessCondition, null /* options */, null);
     await testContainer.SetMetadataAsync(testAccessCondition, null /* options */, null);
     await testContainer.SetPermissionsAsync(new BlobContainerPermissions(), testAccessCondition, null /* options */, null);
 }
开发者ID:benaadams,项目名称:azure-storage-net,代码行数:12,代码来源:LeaseTests.cs

示例4: CheckLeaseStatusAsync

        /// <summary>
        /// Checks the lease status of a container, both from its attributes and from a container listing.
        /// </summary>
        /// <param name="container">The container to test.</param>
        /// <param name="expectedStatus">The expected lease status.</param>
        /// <param name="expectedState">The expected lease state.</param>
        /// <param name="expectedDuration">The expected lease duration.</param>
        /// <param name="description">A description of the circumstances that lead to the expected status.</param>
        private async Task CheckLeaseStatusAsync(
            CloudBlobContainer container,
            LeaseStatus expectedStatus,
            LeaseState expectedState,
            LeaseDuration expectedDuration,
            string description)
        {
            await container.FetchAttributesAsync();
            Assert.AreEqual(expectedStatus, container.Properties.LeaseStatus, "LeaseStatus mismatch: " + description + " (from FetchAttributes)");
            Assert.AreEqual(expectedState, container.Properties.LeaseState, "LeaseState mismatch: " + description + " (from FetchAttributes)");
            Assert.AreEqual(expectedDuration, container.Properties.LeaseDuration, "LeaseDuration mismatch: " + description + " (from FetchAttributes)");

            ContainerResultSegment containers = await this.blobClient.ListContainersSegmentedAsync(container.Name, ContainerListingDetails.None, null, null, null, null);
            BlobContainerProperties propertiesInListing = (from CloudBlobContainer c in containers.Results
                                                           where c.Name == container.Name
                                                           select c.Properties).Single();

            Assert.AreEqual(expectedStatus, propertiesInListing.LeaseStatus, "LeaseStatus mismatch: " + description + " (from ListContainers)");
            Assert.AreEqual(expectedState, propertiesInListing.LeaseState, "LeaseState mismatch: " + description + " (from ListContainers)");
            Assert.AreEqual(expectedDuration, propertiesInListing.LeaseDuration, "LeaseDuration mismatch: " + description + " (from ListContainers)");
        }
开发者ID:benaadams,项目名称:azure-storage-net,代码行数:29,代码来源:LeaseTests.cs

示例5: ContainerAcquireRenewLeaseTestAsync

        /// <summary>
        /// Verifies the behavior of a lease while the lease holds. Once the lease expires, this method confirms that write operations succeed.
        /// The test is cut short once the <c>testLength</c> time has elapsed.
        /// </summary>
        /// <param name="leasedContainer">The container.</param>
        /// <param name="duration">The duration of the lease.</param>
        /// <param name="testLength">The maximum length of time to run the test.</param>
        /// <param name="tolerance">The allowed lease time error.</param>
        internal async Task ContainerAcquireRenewLeaseTestAsync(CloudBlobContainer leasedContainer, TimeSpan? duration, TimeSpan testLength, TimeSpan tolerance)
        {
            OperationContext operationContext = new OperationContext();
            DateTime beginTime = DateTime.UtcNow;

            while (true)
            {
                try
                {
                    // Attempt to delete the container with no lease ID.
                    await leasedContainer.DeleteAsync(null, null, operationContext);

                    // The delete succeeded, which means that the lease must have expired.

                    // If the lease was infinite then there is an error because it should not have expired.
                    Assert.IsNotNull(duration, "An infinite lease should not expire.");

                    // The lease should be past its expiration time.
                    Assert.IsTrue(DateTime.UtcNow - beginTime > duration - tolerance, "Deletes should not succeed while lease is present.");

                    // Since the lease has expired (and the container was deleted), the test is over.
                    return;
                }
                catch (Exception)
                {
                    if (operationContext.LastResult.ExtendedErrorInformation.ErrorCode == BlobErrorCodeStrings.LeaseIdMissing)
                    {
                        // We got this error because the lease has not expired yet.

                        // Make sure the lease is not past its expiration time yet.
                        DateTime currentTime = DateTime.UtcNow;
                        if (duration.HasValue)
                        {
                            Assert.IsTrue(currentTime - beginTime < duration + tolerance, "Deletes should succeed after a lease expires.");
                        }

                        // End the test early if necessary
                        if (currentTime - beginTime > testLength)
                        {
                            // The lease has not expired, but we're not waiting any longer.
                            return;
                        }
                    }
                    else
                    {
                        throw;
                    }
                }

                // Attempt to write to and read from the container. This should always succeed.
                await leasedContainer.SetMetadataAsync();
                await leasedContainer.FetchAttributesAsync();

                // Wait 1 second before trying again.
                await Task.Delay(TimeSpan.FromSeconds(1));
            }
        }
开发者ID:benaadams,项目名称:azure-storage-net,代码行数:65,代码来源:LeaseTests.cs

示例6: ContainerReadWriteExpectLeaseFailureAsync

        /// <summary>
        /// Test container reads and writes, expecting lease failure.
        /// </summary>
        /// <param name="testContainer">The container.</param>
        /// <param name="testAccessCondition">The failing access condition to use.</param>
        /// <param name="expectedErrorCode">The expected error code.</param>
        /// <param name="description">The reason why these calls should fail.</param>
        private async Task ContainerReadWriteExpectLeaseFailureAsync(CloudBlobContainer testContainer, AccessCondition testAccessCondition, HttpStatusCode expectedStatusCode, string expectedErrorCode, string description)
        {
            OperationContext operationContext = new OperationContext();

            // FetchAttributes is a HEAD request with no extended error info, so it returns with the generic ConditionFailed error code.
            await TestHelper.ExpectedExceptionAsync(
                async () => await testContainer.FetchAttributesAsync(testAccessCondition, null /* options */, operationContext),
                operationContext,
                description + "(Fetch Attributes)",
                HttpStatusCode.PreconditionFailed);

            await TestHelper.ExpectedExceptionAsync(
                async () => await testContainer.GetPermissionsAsync(testAccessCondition, null /* options */, operationContext),
                operationContext,
                description + " (Get Permissions)",
                expectedStatusCode,
                expectedErrorCode);
            await TestHelper.ExpectedExceptionAsync(
                async () => await testContainer.SetMetadataAsync(testAccessCondition, null /* options */, operationContext),
                operationContext,
                description + " (Set Metadata)",
                expectedStatusCode,
                expectedErrorCode);
            await TestHelper.ExpectedExceptionAsync(
                async () => await testContainer.SetPermissionsAsync(new BlobContainerPermissions(), testAccessCondition, null /* options */, operationContext),
                operationContext,
                description + " (Set Permissions)",
                expectedStatusCode,
                expectedErrorCode);
        }
开发者ID:benaadams,项目名称:azure-storage-net,代码行数:37,代码来源:LeaseTests.cs

示例7: ContainerReadWriteExpectLeaseSuccessTask

 /// <summary>
 /// Test container reads and writes, expecting success.
 /// </summary>
 /// <param name="testContainer">The container.</param>
 /// <param name="testAccessCondition">The access condition to use.</param>
 private void ContainerReadWriteExpectLeaseSuccessTask(CloudBlobContainer testContainer, AccessCondition testAccessCondition)
 {
     testContainer.FetchAttributesAsync(testAccessCondition, null /* options */, null /* operationContext */).Wait();
     testContainer.GetPermissionsAsync(testAccessCondition, null /* options */, null /* operationContext */).Wait();
     testContainer.SetMetadataAsync(testAccessCondition, null /* options */, null /* operationContext */).Wait();
     testContainer.SetPermissionsAsync(new BlobContainerPermissions(), testAccessCondition, null /* options */, null /* operationContext */).Wait();
 }
开发者ID:benaadams,项目名称:azure-storage-net,代码行数:12,代码来源:LeaseTests.cs

示例8: TestAccessTask

        private static void TestAccessTask(BlobContainerPublicAccessType accessType, CloudBlobContainer container, CloudBlob inputBlob)
        {
            StorageCredentials credentials = new StorageCredentials();
            container = new CloudBlobContainer(container.Uri, credentials);
            CloudPageBlob blob = new CloudPageBlob(inputBlob.Uri, credentials);

            if (accessType.Equals(BlobContainerPublicAccessType.Container))
            {
                blob.FetchAttributesAsync().Wait();
                BlobContinuationToken token = null;
                do
                {
                    BlobResultSegment results = container.ListBlobsSegmented(token);
                    results.Results.ToArray();
                    token = results.ContinuationToken;
                }
                while (token != null);
                container.FetchAttributesAsync().Wait();
            }
            else if (accessType.Equals(BlobContainerPublicAccessType.Blob))
            {
                blob.FetchAttributesAsync().Wait();

                TestHelper.ExpectedExceptionTask(
                    container.ListBlobsSegmentedAsync(null),
                    "List blobs while public access does not allow for listing",
                    HttpStatusCode.NotFound);
                TestHelper.ExpectedExceptionTask(
                    container.FetchAttributesAsync(),
                    "Fetch container attributes while public access does not allow",
                    HttpStatusCode.NotFound);
            }
            else
            {
                TestHelper.ExpectedExceptionTask(
                    blob.FetchAttributesAsync(),
                    "Fetch blob attributes while public access does not allow",
                    HttpStatusCode.NotFound);
                TestHelper.ExpectedExceptionTask(
                    container.ListBlobsSegmentedAsync(null),
                    "List blobs while public access does not allow for listing",
                    HttpStatusCode.NotFound);
                TestHelper.ExpectedExceptionTask(
                    container.FetchAttributesAsync(),
                    "Fetch container attributes while public access does not allow",
                    HttpStatusCode.NotFound);
            }
        }
开发者ID:Gajendra-Bahakar,项目名称:azure-storage-net,代码行数:48,代码来源:CloudBlobContainerTest.cs

示例9: AddBasicContainerHeaders

 private async Task AddBasicContainerHeaders(HttpResponseMessage response, CloudBlobContainer container)
 {
     await container.FetchAttributesAsync();
     response.Headers.ETag = new EntityTagHeaderValue(container.Properties.ETag);
     if (container.Properties.LastModified.HasValue)
     {
         if (response.Content == null)
         {
             response.Content = new StringContent("");
         }
         response.Content.Headers.LastModified = container.Properties.LastModified.Value.UtcDateTime;
     }
     //Right now we are just parroting back the values sent by the client. Might need to generate our
     //own values for these if none are provided.
     IEnumerable<string> headerValues;
     if (Request.Headers.TryGetValues("x-ms-client-request-id", out headerValues))
     {
         response.Headers.Add("x-ms-request-id", headerValues);
     }
     response.Headers.Add("x-ms-version", TryGetHeader(Request.Headers, "x-ms-version"));
     response.Headers.Date = DateTimeOffset.UtcNow;
 }
开发者ID:farukc,项目名称:Dash,代码行数:22,代码来源:ContainerController.cs

示例10: ValidatePreconditions

 private async Task<HttpResponseMessage> ValidatePreconditions(CloudBlobContainer container)
 {
     // TODO: Ensure that all preconditions are validated
     if (!await container.ExistsAsync())
     {
         return new HttpResponseMessage(HttpStatusCode.NotFound);
     }
     IEnumerable<string> leaseID;
     if (Request.Headers.TryGetValues("x-ms-lease-id", out leaseID))
     {
         AccessCondition condition = new AccessCondition()
         {
             LeaseId = leaseID.First()
         };
         //Try fetching the attributes to force validation of the leaseID
         await container.FetchAttributesAsync(condition, null, null);
     }
     // If we don't find any errors, just return null to indicate that everything is A-OK.
     return null;
 }
开发者ID:farukc,项目名称:Dash,代码行数:20,代码来源:ContainerController.cs

示例11: CopyContainer

 static async Task CopyContainer(CloudBlobContainer sourceContainer, CloudBlobContainer destContainer)
 {
     await sourceContainer.FetchAttributesAsync();
     var access = await sourceContainer.GetPermissionsAsync();
     await destContainer.CreateIfNotExistsAsync(access.PublicAccess, null, null);
     await destContainer.SetPermissionsAsync(access);
     destContainer.Metadata.Clear();
     foreach (var metadatum in sourceContainer.Metadata)
     {
         destContainer.Metadata.Add(metadatum);
     }
     await destContainer.SetMetadataAsync();
 }
开发者ID:farukc,项目名称:Dash,代码行数:13,代码来源:AccountManager.cs


注:本文中的Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer.FetchAttributesAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。