當前位置: 首頁>>代碼示例>>C#>>正文


C# CloudBlobContainer.SetPermissionsAsync方法代碼示例

本文整理匯總了C#中Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer.SetPermissionsAsync方法的典型用法代碼示例。如果您正苦於以下問題:C# CloudBlobContainer.SetPermissionsAsync方法的具體用法?C# CloudBlobContainer.SetPermissionsAsync怎麽用?C# CloudBlobContainer.SetPermissionsAsync使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer的用法示例。


在下文中一共展示了CloudBlobContainer.SetPermissionsAsync方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: SetContainerPermission

 protected void SetContainerPermission(CloudBlobContainer container, BlobContainerPublicAccessType perimssion)
 {
     container.SetPermissionsAsync(new BlobContainerPermissions
     {
         PublicAccess = perimssion
     });
 }
開發者ID:sergeyb12345,項目名稱:MarketHunter,代碼行數:7,代碼來源:AzureStorageClient.cs

示例2: CreateContainerAsync

 /// <summary>
 /// Creates a private container with the given name
 /// </summary>
 /// <param name="containerName"></param>
 /// <returns></returns>
 public async Task<bool> CreateContainerAsync(string containerName, bool isPublic)
 {
     // Create the container if it doesn't exist.
     blobContainer = blobClient.GetContainerReference(containerName);
     if (isPublic)
     {
         var returnData = await blobContainer.CreateIfNotExistsAsync();
         if (returnData)
             await blobContainer.SetPermissionsAsync(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob });
         return returnData;
     }
     return await blobContainer.CreateIfNotExistsAsync();
 }
開發者ID:sudheeshv,項目名稱:AzureStorage,代碼行數:18,代碼來源:BlobRepository.cs

示例3: Sync

        public void Sync(CloudBlobContainer container, string localPath)
        {
            Console.WriteLine("Syncing localPath: '{0}', to container: '{1}'.", localPath, container.Uri);
            container.CreateIfNotExists();
            container.SetPermissionsAsync(new BlobContainerPermissions {
                PublicAccess = BlobContainerPublicAccessType.Blob
            });

            SyncLocalDirToBlob(localPath, container);
            Console.WriteLine(
                @"Total new: {0}, updated: {1}, deleted {2}."
                , _new.Count
                , _changed.Count
                , _deleted.Count
            );
        }
開發者ID:GiscardBiamby,項目名稱:AzzySync,代碼行數:16,代碼來源:SyncToBlobStorage.cs

示例4: SetContainerPermissionsAsync

 /// <summary>
 /// Return a task that asynchronously set the container permission
 /// </summary>
 /// <param name="container">CloudBlobContainer object</param>
 /// <param name="permissions">Container permission</param>
 /// <param name="accessCondition">Access condition</param>
 /// <param name="requestOptions">Blob request option</param>
 /// <param name="operationContext">Operation context</param>
 /// <param name="cmdletCancellationToken">cancellation token</param>
 /// <returns>Return a task that asynchronously set the container permission</returns>
 public Task SetContainerPermissionsAsync(CloudBlobContainer container, BlobContainerPermissions permissions, AccessCondition accessCondition, BlobRequestOptions requestOptions, OperationContext operationContext, CancellationToken cancellationToken)
 {
     return container.SetPermissionsAsync(permissions, accessCondition, requestOptions, operationContext, cancellationToken);
 }
開發者ID:NordPool,項目名稱:azure-sdk-tools,代碼行數:14,代碼來源:StorageBlobManagement.cs

示例5: CreateSharedAccessPolicyAsync

        /// <summary>
        /// Creates a shared access policy on the container.
        /// </summary>
        /// <param name="container">A CloudBlobContainer object.</param>
        /// <param name="policyName">The name of the stored access policy.</param>
        /// <returns>A Task object.</returns>
        private static async Task CreateSharedAccessPolicyAsync(CloudBlobContainer container, string policyName)
        {
            // Create a new shared access policy and define its constraints.
            // The access policy provides create, write, read, list, and delete permissions.
            SharedAccessBlobPolicy sharedPolicy = new SharedAccessBlobPolicy()
            {
                // When the start time for the SAS is omitted, the start time is assumed to be the time when the storage service receives the request. 
                // Omitting the start time for a SAS that is effective immediately helps to avoid clock skew.
                SharedAccessExpiryTime = DateTime.UtcNow.AddHours(24),
                Permissions = SharedAccessBlobPermissions.Read | SharedAccessBlobPermissions.List |
                    SharedAccessBlobPermissions.Write | SharedAccessBlobPermissions.Create | SharedAccessBlobPermissions.Delete
            };

            // Get the container's existing permissions.
            BlobContainerPermissions permissions = await container.GetPermissionsAsync();

            // Add the new policy to the container's permissions, and set the container's permissions.
            permissions.SharedAccessPolicies.Add(policyName, sharedPolicy);
            await container.SetPermissionsAsync(permissions);
        }
開發者ID:tamram,項目名稱:storage-blob-dotnet-getting-started,代碼行數:26,代碼來源:Advanced.cs

示例6: SetAnonymousAccessLevelAsync

        /// <summary>
        /// Sets the anonymous access level.
        /// </summary>
        /// <param name="container">The container.</param>
        /// <param name="accessType">Type of the access.</param>
        /// <returns>A Task object.</returns>
        private static async Task SetAnonymousAccessLevelAsync(CloudBlobContainer container, BlobContainerPublicAccessType accessType)
        {
            try
            {
                // Read the existing permissions first so that we have all container permissions. 
                // This ensures that we do not inadvertently remove any shared access policies while setting the public access level.
                BlobContainerPermissions permissions = await container.GetPermissionsAsync();

                // Set the container's public access level.
                permissions.PublicAccess = BlobContainerPublicAccessType.Container;
                await container.SetPermissionsAsync(permissions);

                Console.WriteLine("Container public access set to {0}", accessType.ToString());
                Console.WriteLine();
            }
            catch (StorageException e)
            {
                Console.WriteLine(e.Message);
                Console.ReadLine();
                throw;
            }
        }
開發者ID:tamram,項目名稱:storage-blob-dotnet-getting-started,代碼行數:28,代碼來源:Advanced.cs

示例7: 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

示例8: 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

示例9: 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

示例10: 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.SetPermissionsAsync方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。