public static async Task <bool> Remove(string bucket, string containerPrefix, string path, string location, String provider, String pattern, bool bUseFlat, ILogger logger) { logger.LogInformation($"You are about to delete all content at {provider}@{bucket}-{location}, {containerPrefix}/{path}"); logger.LogInformation($"Please type DELETE in all capital to confirm the operation ----> "); if (String.IsNullOrEmpty(pattern)) { pattern = ""; } var re = new Regex(pattern, RegexOptions.IgnoreCase | RegexOptions.Compiled); var confirmationString = Console.ReadLine(); if (confirmationString == "DELETE") { var container = CloudStorage.GetContainer(bucket, containerPrefix, location, provider); var dirs = container.GetDirectoryReference(path); foreach (var dir in dirs.GetBlobDirectoriesForProviders()) { try { var cnt = 0; if (!Object.ReferenceEquals(container, null)) { CustomizedBlobContinuationToken token = null; do { var lst = await dir.ListBlobsSegmentedAsync(bUseFlat, BlobListingDetails.Metadata, null, token, null, null); foreach (var item in lst.Results) { // logger.LogInformation($"{item.Uri}"); var blockItem = item.ToBlockBlob(); if (!Object.ReferenceEquals(blockItem, null) && re.IsMatch(blockItem.Name)) { logger.LogInformation($"Delete {blockItem.Name}"); var basename = blockItem.GetBaseName(dir); var deleteBlob = dirs.GetBlockBlobReference(basename); cnt++; // This way, we will delete blobs across all providers. await deleteBlob.DeleteAsync(false); } } ; token = lst.ContinuationToken; } while (token != null); logger.LogInformation($"# of items to be deleted == {cnt}"); } } catch { // Deletion failed return(false); } } return(true); } else { return(false); } }
ListBlobsSegmentedAsync(bool useFlatBlobListing, BlobListingDetails blobListingDetails, Nullable <int> maxResults, CustomizedBlobContinuationToken currentToken, BlobRequestOptions options, OperationContext operationContext) { var typeName = this.GetType().FullName; throw new Exception($"ListBlobsSegmentedAsync hasn't been implemented for BlobDirectory {typeName}"); }
ListBlobsSegmentedAsync(CustomizedBlobContinuationToken currentToken) { var azureToken = currentToken as AzureBlobContinuationToken; BlobContinuationToken useToken = null; if (!Object.ReferenceEquals(azureToken, null)) { useToken = azureToken._token; } // Console.WriteLine($"ListBlobs on {_directory.Prefix}"); var results = await _directory.ListBlobsSegmentedAsync(useToken); //Console.WriteLine($"List yield {results.Results.Count()} items, token is {Object.ReferenceEquals(useToken, null)}, azureToken is {Object.ReferenceEquals(azureToken, null)}"); return(new AzureResultSegment(Provider, results)); }
ListBlobsSegmentedAsync(bool useFlatBlobListing, BlobListingDetails blobListingDetails, Nullable <int> maxResults, CustomizedBlobContinuationToken currentToken, BlobRequestOptions options, OperationContext operationContext) { var azureToken = currentToken as AzureBlobContinuationToken; BlobContinuationToken useToken = null; if (!Object.ReferenceEquals(azureToken, null)) { useToken = azureToken._token; } var results = await _directory.ListBlobsSegmentedAsync(useFlatBlobListing, blobListingDetails, maxResults, useToken, options, operationContext); //Console.WriteLine($"List yield {results.Results.Count()} items, token is {Object.ReferenceEquals(useToken, null)}, azureToken is {Object.ReferenceEquals(azureToken, null)}"); return(new AzureResultSegment(Provider, results)); }
public static async Task Copy(string bucket, string containerPrefix, string path, string location, String provider, string bucket2, string containerPrefix2, string path2, string location2, String provider2, int maxDegreeOfParallelism, ILogger logger) { logger.LogInformation($"source {provider}@{bucket}-{location}, {containerPrefix}/{path}"); logger.LogInformation($"destination {provider2}@{bucket2}-{location2}, {containerPrefix2}/{path2}"); var container = CloudStorage.GetContainer(bucket, containerPrefix, location, provider); var dir = container.GetDirectoryReference(path); var basename = dir.Name; var prefixLength = basename.Length; var container2 = CloudStorage.GetContainer(bucket2, containerPrefix2, location2, provider2); var dir2 = container2.GetDirectoryReference(path2); if (!Object.ReferenceEquals(container, null)) { CustomizedBlobContinuationToken token = null; do { var lst = await dir.ListBlobsSegmentedAsync(true, BlobListingDetails.Metadata, null, token, null, null); var opt = new ParallelOptions(); opt.MaxDegreeOfParallelism = maxDegreeOfParallelism; foreach (var item in lst.Results) { var blockItem = item.ToBlockBlob(); if (!Object.ReferenceEquals(blockItem, null)) { // No need to deal with directories. var itemname = blockItem.Name.Substring(prefixLength); var destItem = dir2.GetBlockBlobReference(itemname); var bytes = await blockItem.DownloadByteArrayAsync(); await destItem.UploadFromByteArrayAsync(bytes, 0, bytes.Length); logger.LogInformation($"Copy item {itemname}"); } } ; token = lst.ContinuationToken; } while (token != null); } }
public static async Task List(string bucket, string containerPrefix, string path, string location, String provider, bool bUseFlat, ILogger logger) { logger.LogInformation($"Listing {provider}@{bucket}-{location}, {containerPrefix}/{path}, flat = {bUseFlat}"); var container = CloudStorage.GetContainer(bucket, containerPrefix, location, provider); var dir = container.GetDirectoryReference(path); int cnt = 0; int cntdir = 0; if (!Object.ReferenceEquals(container, null)) { CustomizedBlobContinuationToken token = null; do { var lst = await dir.ListBlobsSegmentedAsync(bUseFlat, BlobListingDetails.Metadata, null, token, null, null); foreach (var item in lst.Results) { logger.LogInformation($"{item.Uri}"); var blockItem = item.ToBlockBlob(); if (!Object.ReferenceEquals(blockItem, null)) { cnt++; } var dirItem = item.ToBlobDirectory(); if (!Object.ReferenceEquals(dirItem, null)) { cntdir++; } } ; token = lst.ContinuationToken; } while (token != null); } logger.LogInformation($"Total files == {cnt}, dir == {cntdir}"); }
ListBlobsSegmentedAsync(CustomizedBlobContinuationToken currentToken) { var typeName = this.GetType().FullName; throw new Exception($"ListBlobsSegmentedAsync hasn't been implemented for BlobDirectory {typeName}"); }