public async virtual Task <BlobContainerCreateOperation> CreateOrUpdateAsync(string containerName, BlobContainerData blobContainer, bool waitForCompletion = true, CancellationToken cancellationToken = default)
        {
            if (containerName == null)
            {
                throw new ArgumentNullException(nameof(containerName));
            }
            if (blobContainer == null)
            {
                throw new ArgumentNullException(nameof(blobContainer));
            }

            using var scope = _clientDiagnostics.CreateScope("BlobContainerContainer.CreateOrUpdate");
            scope.Start();
            try
            {
                var response = await _restClient.CreateAsync(Id.ResourceGroupName, Id.Parent.Name, Id.Name, containerName, blobContainer, cancellationToken).ConfigureAwait(false);

                var operation = new BlobContainerCreateOperation(Parent, response);
                if (waitForCompletion)
                {
                    await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false);
                }
                return(operation);
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }
        public virtual BlobContainerCreateOperation CreateOrUpdate(string containerName, BlobContainerData blobContainer, bool waitForCompletion = true, CancellationToken cancellationToken = default)
        {
            if (containerName == null)
            {
                throw new ArgumentNullException(nameof(containerName));
            }
            if (blobContainer == null)
            {
                throw new ArgumentNullException(nameof(blobContainer));
            }

            using var scope = _clientDiagnostics.CreateScope("BlobContainerCollection.CreateOrUpdate");
            scope.Start();
            try
            {
                var response  = _blobContainersRestClient.Create(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Name, containerName, blobContainer, cancellationToken);
                var operation = new BlobContainerCreateOperation(Parent, response);
                if (waitForCompletion)
                {
                    operation.WaitForCompletion(cancellationToken);
                }
                return(operation);
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }
Exemplo n.º 3
0
        public async Task CreateOrUpdate()
        {
            #region Snippet:Managing_BlobContainers_CreateBlobContainer
            BlobContainerCollection blobContainerCollection           = blobService.GetBlobContainers();
            string                       blobContainerName            = "myBlobContainer";
            BlobContainerData            blobContainerData            = new BlobContainerData();
            BlobContainerCreateOperation blobContainerCreateOperation = await blobContainerCollection.CreateOrUpdateAsync(blobContainerName, blobContainerData);

            BlobContainer blobContainer = blobContainerCreateOperation.Value;
            #endregion
        }