Esempio n. 1
0
        public async Task OnExecute(IConsole console)
        {
            var sw = new Stopwatch();

            sw.Start();
            if (string.IsNullOrEmpty(ConnectionString))
            {
                ConnectionString = Environment.GetEnvironmentVariable("AZURE_STORAGE_CONNECTION_STRING");
                if (string.IsNullOrEmpty(ConnectionString))
                {
                    throw new ArgumentException(nameof(ConnectionString));
                }
            }
            if (!All && string.IsNullOrEmpty(ContainerName))
            {
                throw new ArgumentException("need the container name");
            }

            var csa     = CloudStorageAccount.Parse(ConnectionString);
            var account = new CloudStorageAccount(csa.Credentials, csa.TableStorageUri);

            var bc    = new BlobServiceClient(ConnectionString);
            var token = string.Empty;
            int count = 0;


            do
            {
                var results = bc.GetBlobContainersAsync(BlobContainerTraits.Metadata)
                              .AsPages(token);
                await foreach (var cp in results)
                {
                    foreach (var item in cp.Values)
                    {
                        if (All)
                        {
                            await bc.DeleteBlobContainerAsync(item.Name);

                            count++;
                        }
                        else
                        {
                            if (item.Name.Equals(ContainerName))
                            {
                                await bc.DeleteBlobContainerAsync(item.Name);
                            }
                            count++;
                        }
                    }
                }
            } while (token != string.Empty);
            sw.Stop();
            console.WriteLine($"deleted {count} containers in {sw.Elapsed.TotalSeconds} seconds.");
        }
        public async Task CollectGarbage_Explicit()
        {
            // Get all of our configs
            var configs = new List <TenantConfiguration>();

            try { configs.Add(TestConfigurations.DefaultTargetTenant); } catch (InconclusiveException) { }
            try { configs.Add(TestConfigurations.DefaultSecondaryTargetTenant); } catch (InconclusiveException) { }
            try { configs.Add(TestConfigurations.DefaultTargetPremiumBlobTenant); } catch (InconclusiveException) { }
            try { configs.Add(TestConfigurations.DefaultTargetPreviewBlobTenant); } catch (InconclusiveException) { }
            try { configs.Add(TestConfigurations.DefaultTargetOAuthTenant); } catch (InconclusiveException) { }
            foreach (TenantConfiguration config in configs)
            {
                // Blobs
                var blobs = new BlobServiceClient(config.ConnectionString);
                await foreach (Response <ContainerItem> container in blobs.GetContainersAsync())
                {
                    try
                    {
                        await blobs.DeleteBlobContainerAsync(container.Value.Name);
                    }
                    catch (StorageRequestFailedException ex) when(ex.ErrorCode == BlobErrorCode.LeaseIdMissing)
                    {
                        // Break any lingering leases
                        await blobs.GetBlobContainerClient(container.Value.Name).GetLeaseClient().BreakAsync();
                    }
                    catch (StorageRequestFailedException ex) when(ex.ErrorCode == BlobErrorCode.ContainerBeingDeleted)
                    {
                        // Ignore anything already being deleted
                    }
                }

                // Queues
                var queues = new QueueServiceClient(config.ConnectionString);
                await foreach (Response <QueueItem> queue in queues.GetQueuesAsync())
                {
                    try
                    {
                        await queues.DeleteQueueAsync(queue.Value.Name);
                    }
                    catch (StorageRequestFailedException ex) when(ex.ErrorCode == QueueErrorCode.QueueBeingDeleted)
                    {
                        // Ignore anything already being deleted
                    }
                }

                // Files
                var files = new FileServiceClient(config.ConnectionString);
                await foreach (Response <ShareItem> share in files.GetSharesAsync())
                {
                    try
                    {
                        await files.DeleteShareAsync(share.Value.Name);
                    }
                    catch (StorageRequestFailedException ex) when(ex.ErrorCode == FileErrorCode.ShareBeingDeleted)
                    {
                        // Ignore anything already being deleted
                    }
                }
            }
        }
Esempio n. 3
0
        private async Task DeleteAllContainersAsync(string prefix)
        {
            var pagenable = blobClient.GetBlobContainersAsync(prefix: prefix);

            await foreach (var blobItem in pagenable)
            {
                await blobClient.DeleteBlobContainerAsync(blobItem.Name);
            }
        }
    private async Task DeleteContainersAsync()
    {
        Console.WriteLine($"Deleting containers in storage account '{_serviceClient.AccountName}'");
        foreach (var container in _serviceClient.GetBlobContainers())
        {
            await _serviceClient.DeleteBlobContainerAsync(container.Name);

            Console.WriteLine($"\t{container.Name}");
        }
    }
        public Task DisposeAsync()
        {
            if (KeepUserContainerAfterTestIsDone)
            {
                return(Task.CompletedTask);
            }

            BlobServiceClient blobServiceClient = CreateServiceClient(BlobStorageConnectionString);

            return(blobServiceClient.DeleteBlobContainerAsync(CONTAINER_NAME));
        }
Esempio n. 6
0
        public async Task DeleteBlobContainerAsync()
        {
            var name = GetNewContainerName();
            BlobServiceClient   service   = GetServiceClient_SharedKey();
            BlobContainerClient container = InstrumentClient((await service.CreateBlobContainerAsync(name)).Value);

            await service.DeleteBlobContainerAsync(name);

            Assert.ThrowsAsync <RequestFailedException>(
                async() => await container.GetPropertiesAsync());
        }
        public async Task TearDown()
        {
            foreach (var table in tableClient.ListTables())
            {
                if (table.Name.StartsWith(tableNamePrefix))
                {
                    await table.DeleteAsync();
                }
            }

            await blobServiceClient.DeleteBlobContainerAsync(containerName);
        }
Esempio n. 8
0
        /// <summary>
        /// Asynchronously deletes an existing container.
        /// </summary>
        /// <param name="containerName">Container name.</param>
        /// <returns>true if deleted, otherwise false.</returns>
        public async Task <bool> DeleteContainerAsync(
            string containerName)
        {
            if (string.IsNullOrWhiteSpace(containerName))
            {
                throw new ArgumentNullException(paramName: nameof(containerName), message: "Container name must not be null.");
            }

            var response = await serviceClient.DeleteBlobContainerAsync(containerName);

            return(response.Status == 200);
        }
Esempio n. 9
0
        public void CanDeleteContainer() => RunOnService(service =>
        {
            BlobServiceClient cli = GetBlobServiceClient();

            try
            {
                _ = cli.DeleteBlobContainerAsync("dummycontainer");
            }
            catch
            {
                throw new Exception();
            }
        });
Esempio n. 10
0
        public async Task CreateBlobContainerAsync()
        {
            var name = GetNewContainerName();
            BlobServiceClient service = GetServiceClient_SharedKey();

            try
            {
                BlobContainerClient container = InstrumentClient((await service.CreateBlobContainerAsync(name)).Value);
                Response <BlobContainerProperties> properties = await container.GetPropertiesAsync();

                Assert.IsNotNull(properties.Value);
            }
            finally
            {
                await service.DeleteBlobContainerAsync(name);
            }
        }
 public Task DeleteContainer(string container) => serviceClient.DeleteBlobContainerAsync(container);
Esempio n. 12
0
 public async Task DeleteAsync(string name)
 {
     await _client.DeleteBlobContainerAsync(name);
 }
Esempio n. 13
0
 public async Task DeleteContainerAsync(string containerName) =>
 await _blobServiceClient.DeleteBlobContainerAsync(
     blobContainerName : containerName);
Esempio n. 14
0
 public Task DeleteBlobAsync(string blobName)
 {
     return(_blobServiceClient.DeleteBlobContainerAsync(blobName));
 }
Esempio n. 15
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="id">The container name</param>
 /// <returns></returns>
 public async Task DeleteContainer(string id)
 {
     var blobServiceClient = new BlobServiceClient(_connectionString);
     await blobServiceClient.DeleteBlobContainerAsync(id);
 }
Esempio n. 16
0
 public async Task <bool> DeleteBlobContainer(string containerName) => await Execute(() => _blobServiceClient.DeleteBlobContainerAsync(containerName));
Esempio n. 17
0
 public async Task <Response> DeleteContainer(string containerName)
 {
     return(await _client.DeleteBlobContainerAsync(containerName));
 }