public static async Task <BlobResultSegment> AsyncReadCall(string path, string oper) { AzureFileOperations AyncObject = new AzureFileOperations("filebrowsercontent", "rbAvmn82fmt7oZ7N/3SXQ9+d9MiQmW2i1FzwAtPfUJL9sb2gZ/+cC6Ei1mkwSbMA1iVSy9hzH1unWfL0fPny0A==", "blob1"); CloudBlobDirectory sampleDirectory = AyncObject.container.GetDirectoryReference(path); BlobRequestOptions options = new BlobRequestOptions(); OperationContext context = new OperationContext(); dynamic Asyncitem = null; if (oper == "Read") { Asyncitem = await sampleDirectory.ListBlobsSegmentedAsync(false, BlobListingDetails.Metadata, null, null, options, context); } if (oper == "Paste") { Asyncitem = await sampleDirectory.ListBlobsSegmentedAsync(false, BlobListingDetails.None, null, null, options, context); } if (oper == "Rename") { Asyncitem = await sampleDirectory.ListBlobsSegmentedAsync(true, BlobListingDetails.Metadata, null, null, options, context); } if (oper == "Remove") { Asyncitem = await sampleDirectory.ListBlobsSegmentedAsync(true, BlobListingDetails.None, null, null, options, context); } if (oper == "HasChild") { Asyncitem = await sampleDirectory.ListBlobsSegmentedAsync(false, BlobListingDetails.None, null, null, options, context); } //return Asyncitem; return(await Task.Run(() => { return Asyncitem; })); }
public override async Task <IEnumerable <T> > ListContainedItemsAsync <T>(string filter, int maxResults, CancellationToken cancellationToken, TimeSpan timeout) { DateTime start = DateTime.UtcNow; DateTime end = start.Add(timeout); List <IListBlobItem> result = new List <IListBlobItem>(); CloudBlobDirectory d = _dir; BlobContinuationToken continuationToken = null; BlobResultSegment resultSegment = null; //convert filename filter to regex string filterRegEx = filter.Replace("*", "(.*)").Replace("?", "(.)"); do { //resultSegment = await _dir.ListBlobsSegmentedAsync(filter, maxResults, continuationToken, null, null, cancellationToken); resultSegment = await _dir.ListBlobsSegmentedAsync(true, BlobListingDetails.None, maxResults, continuationToken, null, null, cancellationToken); ///todo apply filter after the fact if (!string.IsNullOrEmpty(filter)) { result.AddRange(resultSegment.Results.Where(bi => Regex.IsMatch(bi.Uri.Segments.Last(), filterRegEx, RegexOptions.Compiled))); } else { result.AddRange(resultSegment.Results); } if (result.Count > maxResults) { return(result.Take(maxResults) as IEnumerable <T>); } continuationToken = resultSegment.ContinuationToken; }while (continuationToken != null && !cancellationToken.IsCancellationRequested && DateTime.UtcNow < end); return(result as IEnumerable <T>); }
// Performs files operations protected async Task <BlobResultSegment> AsyncReadCall(string path, string oper) { CloudBlobDirectory sampleDirectory = container.GetDirectoryReference(path); BlobRequestOptions options = new BlobRequestOptions(); OperationContext context = new OperationContext(); dynamic Asyncitem = null; if (oper == "Read") { Asyncitem = await sampleDirectory.ListBlobsSegmentedAsync(false, BlobListingDetails.Metadata, null, null, options, context); } if (oper == "Paste") { Asyncitem = await sampleDirectory.ListBlobsSegmentedAsync(false, BlobListingDetails.None, null, null, options, context); } if (oper == "Rename") { Asyncitem = await sampleDirectory.ListBlobsSegmentedAsync(true, BlobListingDetails.Metadata, null, null, options, context); } if (oper == "Remove") { Asyncitem = await sampleDirectory.ListBlobsSegmentedAsync(true, BlobListingDetails.None, null, null, options, context); } if (oper == "HasChild") { Asyncitem = await sampleDirectory.ListBlobsSegmentedAsync(false, BlobListingDetails.None, null, null, options, context); } //return Asyncitem; return(await Task.Run(() => { return Asyncitem; })); }
internal async Task AddBlobsToDirectory(DirectoryBlock directory) { var container = client.GetContainerReference(directory.container); CloudBlobDirectory blobDirectory = container.GetDirectoryReference(directory.prefix); var items = await blobDirectory.ListBlobsSegmentedAsync(false, new BlobListingDetails(), maxListResults, new BlobContinuationToken(), new BlobRequestOptions(), new OperationContext()); var list_continue = false; do { foreach (IListBlobItem item in items.Results) { AddToParentDirectoryObject(directory, item); } if (items.ContinuationToken != null) { items = await blobDirectory.ListBlobsSegmentedAsync(false, new BlobListingDetails(), maxListResults, items.ContinuationToken, new BlobRequestOptions(), new OperationContext()); list_continue = true; } else { list_continue = false; } } while (list_continue); }
/// <summary> /// Retrieve files and folders under the current folder from XStore /// </summary> /// <param name="blobContainer">Blob container</param> /// <param name="srcPath">XStore path</param> /// <param name="files">String array of file names in the folder</param> /// <param name="folders">String array of subfolder names in the folder</param> /// <param name="helper">The timeout helper object.</param> private void GetFilesAndSubfoldersFromXStore( CloudBlobContainer blobContainer, string srcPath, out string[] files, out string[] folders, TimeoutHelper helper) { List <string> fileList = new List <string>(); List <string> folderList = new List <string>(); CloudBlobDirectory cloudBlobDirectory = blobContainer.GetDirectoryReference(this.ConvertUriToBlobReference(srcPath)); // Azure storage team has a bug that the same BlobDirectory can be duplicated in return // to work around this issue we always check if the same directory has been added // [TO DO] this is to be removed once azure storage team fixes this issue HashSet <string> blobDirectories = new HashSet <string>(StringComparer.OrdinalIgnoreCase); #if !DotNetCoreClr IEnumerable <IListBlobItem> blobItems = helper != null ? cloudBlobDirectory.ListBlobs(false, BlobListingDetails.None, GetRequestOptions(helper)) : cloudBlobDirectory.ListBlobs(); #else BlobContinuationToken continuationToken = null; do { BlobResultSegment resultSegment = helper != null ? cloudBlobDirectory.ListBlobsSegmentedAsync(false, BlobListingDetails.None, null, continuationToken, GetRequestOptions(helper), null).Result : cloudBlobDirectory.ListBlobsSegmentedAsync(continuationToken).Result; IEnumerable <IListBlobItem> blobItems = resultSegment.Results; continuationToken = resultSegment.ContinuationToken; #endif foreach (IListBlobItem blobItem in blobItems) { Uri uri = blobItem.Uri; if (blobItem is CloudBlobDirectory) { if (!blobDirectories.Contains(uri.LocalPath.Trim())) { blobDirectories.Add(uri.LocalPath.Trim()); folderList.Add(this.ConvertUriToBlobReference(uri.LocalPath)); } } else { fileList.Add(this.ConvertUriToBlobReference(uri.LocalPath)); } } #if DotNetCoreClr } while (continuationToken != null) { ; }
public static IEnumerable <IListBlobItem> ListBlobs(this CloudBlobDirectory blob, bool useFlatBlobListing = false, BlobListingDetails blobListingDetails = BlobListingDetails.None, BlobRequestOptions options = null, Microsoft.WindowsAzure.Storage.OperationContext operationContext = null) { BlobContinuationToken token = new BlobContinuationToken(); BlobResultSegment segment = blob.ListBlobsSegmentedAsync(useFlatBlobListing, blobListingDetails, int.MaxValue, token, options, operationContext).Result; while (segment.ContinuationToken != null) { foreach (var t in segment.Results) { yield return(t); } segment = blob.ListBlobsSegmentedAsync(useFlatBlobListing, blobListingDetails, int.MaxValue, token, options, operationContext).Result; } }
static async Task <Tuple <CloudBlobDirectory, bool> > IsValidNamespaceDirectoryAsync(CloudBlobDirectory directory) { bool result = false; string nextMarker = null; do { var continuationToken = new BlobContinuationToken { NextMarker = nextMarker, }; var blobResults = await directory.ListBlobsSegmentedAsync(true, BlobListingDetails.Metadata, null, continuationToken, null, null); if (blobResults.Results .Select(blob => new NamespaceListWrapper(blob)) .Any(blobWrapper => !blobWrapper.NamespaceBlob.IsMarkedForDeletion)) { result = true; break; } if (blobResults.ContinuationToken != null) { nextMarker = blobResults.ContinuationToken.NextMarker; } else { nextMarker = null; } } while (!String.IsNullOrWhiteSpace(nextMarker)); return(Tuple.Create(directory, result)); }
public AzureBlobStorageDirectoryInfo(CloudBlobDirectory directory) { this.directory = directory; var blogResultSegment = directory.ListBlobsSegmentedAsync(null).Result; Exists = blogResultSegment.Results != null && blogResultSegment.Results.Any(); }
/// <summary> /// Lists all the blob names from directly under a directory, excluding subdirectories /// </summary> /// <param name="directoryName">The name of the directory to list</param> /// <param name="cancellationToken">The cancellation token assigned for the operation</param> /// <returns>A list for blob names found in the directory</returns> public async Task <IList <string> > ListBlobsAsync(string directoryName, CancellationToken cancellationToken) { // get a reference to the directory CloudBlobDirectory blobDirectory = _container.GetDirectoryReference(directoryName ?? string.Empty); var blobsList = new List <string>(); BlobContinuationToken token = null; Trace.TraceVerbose($"Listing all blobs under the '{directoryName}' directory"); do { // get next blobs segment BlobResultSegment segment = await blobDirectory.ListBlobsSegmentedAsync(token, cancellationToken); // set the next token token = segment.ContinuationToken; // add segment results to the list blobsList.AddRange(segment.Results.OfType <CloudBlob>().Select(blob => blob.Name)); } while (token != null); Trace.TraceVerbose($"Found {blobsList.Count} blobs under the '{directoryName}' directory"); return(blobsList); }
public async Task <IEnumerable <MediaContent> > GetChildrenBlobs(CloudBlobDirectory directory) { var blobs = new List <MediaContent>(); BlobContinuationToken continuationToken = null; do { var result = await directory.ListBlobsSegmentedAsync(continuationToken); var folderBlobs = result.Results .Where(x => x is CloudBlockBlob) .Cast <CloudBlockBlob>() .ToList(); foreach (var blobItem in folderBlobs) { var media = await ConvertToMediaContent(blobItem); if (media.Name != PlaceholderFile) { blobs.Add(media); } } continuationToken = result.ContinuationToken; }while (continuationToken != null); return(blobs); }
private async Task IterateBlobsFromDirectory(CloudBlobDirectory dir, string target) { if (dir == null) { throw new ArgumentNullException(nameof(dir)); } BlobContinuationToken continuationToken = null; do { // Get the value of the continuation token returned by the listing call. var results = await dir.ListBlobsSegmentedAsync(continuationToken); foreach (var result in results.Results) { if (result is CloudBlobDirectory) { await IterateBlobsFromDirectory(result as CloudBlobDirectory, target); } else if (result is CloudBlockBlob blockBlob) { await RestoreFile(blockBlob, target); } } }while (continuationToken != null); // Loop while the continuation token is not null. }
public bool ExistsDirectory(string directoryName) { directoryName = StorageUtils.NormalizeDirectoryName(directoryName); CloudBlobDirectory directory = PublicContainer.GetDirectoryReference(directoryName); return(directory.ListBlobsSegmentedAsync(null).GetAwaiter().GetResult().Results.Any()); }
public static async Task ForEachAsync( this CloudBlobDirectory directory, Func <IListBlobItem, Task> action, CancellationToken cancellationToken = default) { BlobContinuationToken continuationToken = null; do { var response = await directory.ListBlobsSegmentedAsync( false, new BlobListingDetails(), null, continuationToken, new BlobRequestOptions(), new OperationContext(), cancellationToken); continuationToken = response.ContinuationToken; foreach (var item in response.Results) { cancellationToken.ThrowIfCancellationRequested(); await action(item); } }while (continuationToken != null); }
async Task CopyDirectoryAsync(CloudBlobDirectory dir, string destinationKey, bool deleteSource = false) { var children = new List <IListBlobItem>(); BlobContinuationToken continuationToken = null; do { BlobResultSegment segmentResult = await dir.ListBlobsSegmentedAsync(continuationToken); continuationToken = segmentResult.ContinuationToken; children.AddRange(segmentResult.Results); } while (continuationToken != null); foreach (IListBlobItem blob in children) { string childCopyName = blob.Uri.Segments[blob.Uri.Segments.Length - 1]; string childCopyKey = $"{destinationKey}{childCopyName}"; if (blob is CloudBlob) { await CopyFileAsync((CloudBlob)blob, childCopyKey, deleteSource); } else if (blob is CloudBlobDirectory) { await CopyDirectoryAsync((CloudBlobDirectory)blob, childCopyKey, deleteSource); } else { throw new Exception("Unsupported blob type"); } } }
public async Task <IEnumerable <IListBlobItem> > ListBlobsAsync(CloudBlobDirectory directory, int?maxItems = null, bool flat = true) { var ret = new List <IListBlobItem>(); BlobContinuationToken token = null; do { var result = await directory.ListBlobsSegmentedAsync( useFlatBlobListing : flat, blobListingDetails : BlobListingDetails.None, maxResults : maxItems, currentToken : token, options : m_reqops_download, operationContext : m_opctx, cancellationToken : m_cancel); ret.AddRange(result.Results); token = result.ContinuationToken; if (ret.Count >= (maxItems ?? int.MaxValue)) { break; } } while (token != null); return(ret); }
async Task RemoveDirectoryAsync(CloudBlobDirectory dir) { var children = new List <IListBlobItem>(); BlobContinuationToken continuationToken = null; do { BlobResultSegment segmentResult = await dir.ListBlobsSegmentedAsync(continuationToken); continuationToken = segmentResult.ContinuationToken; children.AddRange(segmentResult.Results); } while (continuationToken != null); foreach (IListBlobItem blob in children) { if (blob is CloudBlob) { await RemoveFileAsync((CloudBlob)blob); } else if (blob is CloudBlobDirectory) { await RemoveDirectoryAsync((CloudBlobDirectory)blob); } else { throw new Exception("Unsupported blob type"); } } }
static void Main(string[] args) { CloudStorageAccount storageAccount = CloudStorageAccount.Parse("xxxxx"); var blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer cloudBlobContainer = blobClient.GetContainerReference("test-1"); CloudBlobDirectory directory = cloudBlobContainer.GetDirectoryReference("sub1"); foreach (IListBlobItem blobItem in directory.ListBlobsSegmentedAsync(null).Result.Results) { if (blobItem is CloudBlockBlob blob) { //the new package supports syncronous method blob.FetchAttributes(); foreach (var metadataItem in blob.Metadata) { Console.WriteLine("\tKey: {0}", metadataItem.Key); Console.WriteLine("\tValue: {0}", metadataItem.Value); } } } Console.ReadLine(); }
public ActionResult Upload() { CloudBlobContainer blobContainer = BlobStorageService.GetCloudBlodContainer(); List <string> blobs = new List <string>(); //Lay duong dan (URL) tu hinh tu blob vao List<String> // Create the container if it doesn't already exist. CloudBlobDirectory sampleDirectory = blobContainer.GetDirectoryReference("images"); //BlobContinuationToken continuationToken = null; //do //{ //} while (continuationToken != null); //var segment = blobContainer.ListBlobsSegmentedAsync(null).Result; var list = sampleDirectory.ListBlobsSegmentedAsync(false, BlobListingDetails.Metadata, 100, null, null, null).Result; foreach (var blob in list.Results) { blobs.Add(blob.Uri.ToString()); } return(View(blobs)); }
/// <summary> /// Check to see if the specified blob folder exists /// </summary> /// <param name="blobContainer">Container item</param> /// <param name="blobUri">Blob uri of the blob folder</param> /// <param name="checkXStoreFolderManifest">Indicates whether to check XStore folder manifest.</param> /// <param name="requestOptions">Represents the Azure blob request option.</param> /// <returns> /// Returns true if exists /// </returns> public static bool XStoreFolderExists(CloudBlobContainer blobContainer, string blobUri, bool checkXStoreFolderManifest, BlobRequestOptions requestOptions) { bool folderExists = false; CloudBlobDirectory cloudBlobDirectory = blobContainer.GetDirectoryReference(blobUri); #if !DotNetCoreClr IEnumerable <IListBlobItem> blobItems = cloudBlobDirectory.ListBlobs(false, BlobListingDetails.None, requestOptions); #else BlobContinuationToken continuationToken = null; do { BlobResultSegment resultSegment = cloudBlobDirectory.ListBlobsSegmentedAsync(continuationToken).Result; IEnumerable <IListBlobItem> blobItems = resultSegment.Results; continuationToken = resultSegment.ContinuationToken; #endif // Windows Azure storage has strong consistency guarantees. // As soon the manifest file is ready, all users are guaranteed // to see the complete folder if ((!checkXStoreFolderManifest || XStoreFileExists(blobContainer, GetXStoreFolderManifest(blobUri), requestOptions)) && (blobItems.Count() > 0)) { folderExists = true; } #if DotNetCoreClr } while (!folderExists && (continuationToken != null)) { ; }
private static async Task DeleteRawBlobFiles(string League, string Season, string SeasonType, string Week, string GameKey) { CloudStorageAccount storageAccount = CloudStorageAccount.Parse(settings.outputStorageAccountConnStr); // Connect to the blob storage var serviceClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer inputContainer = serviceClient.GetContainerReference($"{League}"); CloudBlobDirectory inputDirectory = inputContainer.GetDirectoryReference($"{Season}/{SeasonType}/{Week}/{GameKey}/"); var blobItem = await inputDirectory.ListBlobsSegmentedAsync(null); try { // Delete any files, but no folders in the specified container foreach (var item in blobItem.Results) { if (item.GetType() == typeof(CloudBlockBlob)) { var blob = (CloudBlockBlob)item; await blob.DeleteAsync(); } } } catch (StorageException e) { Console.WriteLine("HTTP error code {0}: {1}", e.RequestInformation.HttpStatusCode, e.RequestInformation.ErrorCode); Console.WriteLine(e.Message); Console.ReadLine(); } }
private async Task <BlobResultSegment> GetNextHeartbeatsAsync(CloudBlobDirectory directory, BlobContinuationToken currentToken) { const int batchSize = 100; try { return(await directory.ListBlobsSegmentedAsync(useFlatBlobListing : true, blobListingDetails : BlobListingDetails.None, maxResults : batchSize, currentToken : currentToken, options : null, operationContext : null)); } catch (StorageException exception) { if (exception.IsNotFound()) { return(null); } else { throw; } } }
public IEnumerable <IListBlobItem> ListBlobs(bool useFlatListing = false) { var task = _directory.ListBlobsSegmentedAsync(useFlatListing, BlobListingDetails.All, null, null, null, null); task.Wait(); return(task.Result.Results); }
public void DeleteDirectory(string directoryName) { directoryName = StorageUtils.NormalizeDirectoryName(directoryName); CloudBlobDirectory directory = PublicContainer.GetDirectoryReference(directoryName); foreach (IListBlobItem item in directory.ListBlobsSegmentedAsync(null).GetAwaiter().GetResult().Results) { if (item.GetType() == typeof(CloudBlockBlob)) { CloudBlockBlob blob = (CloudBlockBlob)item; blob.DeleteAsync().GetAwaiter().GetResult(); } else if (item.GetType() == typeof(CloudPageBlob)) { CloudPageBlob pageBlob = (CloudPageBlob)item; pageBlob.DeleteAsync().GetAwaiter().GetResult(); } else if (item.GetType() == typeof(CloudBlobDirectory)) { CloudBlobDirectory dir = (CloudBlobDirectory)item; DeleteDirectory(dir.Prefix); } } }
public CloudBlockBlob[] ListBlobContainer(string containerName, string directoryPath) { List <CloudBlockBlob> blobs = new List <CloudBlockBlob>(); BlobContinuationToken continuationToken = null; CloudBlobContainer blobContainer = GetBlobContainer(containerName); do { BlobResultSegment resultSegment; if (!string.IsNullOrEmpty(directoryPath)) { CloudBlobDirectory blobDirectory = blobContainer.GetDirectoryReference(directoryPath); resultSegment = blobDirectory.ListBlobsSegmentedAsync(continuationToken).Result; } else { resultSegment = blobContainer.ListBlobsSegmentedAsync(continuationToken).Result; } foreach (IListBlobItem blobItem in resultSegment.Results) { if (blobItem is CloudBlockBlob blob) { blobs.Add(blob); } } continuationToken = resultSegment.ContinuationToken; } while (continuationToken != null); return(blobs.ToArray()); }
public void RenameDirectory(string directoryName, string newDirectoryName) { CreateDirectory(newDirectoryName); directoryName = StorageUtils.NormalizeDirectoryName(directoryName); newDirectoryName = StorageUtils.NormalizeDirectoryName(newDirectoryName); CloudBlobDirectory directory = PublicContainer.GetDirectoryReference(directoryName); foreach (IListBlobItem item in directory.ListBlobsSegmentedAsync(null).GetAwaiter().GetResult().Results) { string fileName = string.Empty; if (item.GetType() == typeof(CloudBlockBlob)) { CloudBlockBlob blob = (CloudBlockBlob)item; fileName = Path.GetFileName(blob.Name); Copy(blob.Name, GxFileType.Public, newDirectoryName + fileName, GxFileType.Public); Delete(blob.Name, GxFileType.Public); } else if (item.GetType() == typeof(CloudPageBlob)) { CloudPageBlob pageBlob = (CloudPageBlob)item; fileName = Path.GetFileName(pageBlob.Name); Copy(directoryName + fileName, GxFileType.Public, newDirectoryName + fileName, GxFileType.Public); } else if (item.GetType() == typeof(CloudBlobDirectory)) { CloudBlobDirectory dir = (CloudBlobDirectory)item; RenameDirectory(directoryName + dir.Prefix, newDirectoryName + dir.Prefix); } } DeleteDirectory(directoryName); }
public async Task <List <String> > ListBlobs(String ContainerName, String folder) { List <String> blobs = new List <String>(); CloudBlobContainer container = await getCloudBlobContainer(ContainerName); CloudBlobDirectory dir = container.GetDirectoryReference(folder); BlobResultSegment resultSegment = dir.ListBlobsSegmentedAsync(null).Result; foreach (IListBlobItem item in resultSegment.Results) { if (item.GetType() == typeof(CloudBlockBlob)) { CloudBlockBlob blob = (CloudBlockBlob)item; blobs.Add(blob.Name); } else if (item.GetType() == typeof(CloudPageBlob)) { CloudPageBlob blob = (CloudPageBlob)item; blobs.Add(blob.Name); } else if (item.GetType() == typeof(CloudBlobDirectory)) { CloudBlobDirectory dirr = (CloudBlobDirectory)item; blobs.Add(dirr.Uri.ToString()); } } return(blobs); }
private IEnumerable <BlobResultSegment> EnumerateDirectoryBlobs(CloudBlobDirectory cloudBlobDirectory) { Log.Info($"enter {cloudBlobDirectory.Uri}"); BlobResultSegment resultSegment = default(BlobResultSegment); BlobContinuationToken blobToken = null; while (!_blobChildTasks.CancellationToken.IsCancellationRequested) { resultSegment = _blobChildTasks.TaskFunction((blobresultsegment) => cloudBlobDirectory.ListBlobsSegmentedAsync( false, BlobListingDetails.None, Constants.MaxResults, blobToken, null, null).Result as BlobResultSegment).Result as BlobResultSegment; blobToken = resultSegment.ContinuationToken; yield return(resultSegment); if (blobToken == null) { break; } } Log.Info($"exit {cloudBlobDirectory.Uri}"); }
/// <summary> /// Gets list of uploads found at a storage location. /// </summary> /// <param name="tenantId">Tenant identifier.</param> /// <param name="storageHierarchy">Location of files. E.g. { "Uploads" > "Users" }.</param> /// <param name="unitOfWork">Unit of work.</param> /// <returns>List of files.</returns> public List <string> List(long tenantId, List <string> storageHierarchy, IUnitOfWork unitOfWork = null) { // Get Azure storage configuration AzureStorageConfiguration configuration = _azureConfigurationService.GetStorageConfiguration(tenantId, storageHierarchy); // Retrieve storage account from connection string CloudStorageAccount storageAccount = CloudStorageAccount.Parse(configuration.ConnectionString); // Create the blob client CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); // Retrieve reference to a previously created container CloudBlobContainer blobContainer = blobClient.GetContainerReference(configuration.BlobContainerName); CloudBlobDirectory blobDirectory = blobContainer.GetDirectoryReference(configuration.BlobPath); // Get uploads List <string> uploads = new List <string>(); BlobContinuationToken token = null; do { BlobResultSegment results = blobDirectory.ListBlobsSegmentedAsync(token).Result; foreach (IListBlobItem item in results.Results) { if (ItemIsBlockBlob(item)) { uploads.Add(GetBlockBlobFileName((CloudBlockBlob)item)); } } token = results.ContinuationToken; }while (token != null); // Return the result return(uploads); }
internal async Task DeleteLargeMessageBlobs(string instanceId, AzureStorageOrchestrationServiceStats stats) { var blobForDeletionTaskList = new List <Task>(); if (!await this.cloudBlobContainer.ExistsAsync()) { return; } CloudBlobDirectory instanceDirectory = this.cloudBlobContainer.GetDirectoryReference(instanceId); BlobContinuationToken blobContinuationToken = null; while (true) { BlobResultSegment segment = await instanceDirectory.ListBlobsSegmentedAsync(blobContinuationToken); stats.StorageRequests.Increment(); foreach (IListBlobItem blobListItem in segment.Results) { var cloudBlockBlob = blobListItem as CloudBlockBlob; CloudBlockBlob blob = this.cloudBlobContainer.GetBlockBlobReference(cloudBlockBlob?.Name); blobForDeletionTaskList.Add(blob.DeleteIfExistsAsync()); } await Task.WhenAll(blobForDeletionTaskList); stats.StorageRequests.Increment(blobForDeletionTaskList.Count); if (blobContinuationToken == null) { break; } } }
private static async Task <List <IListBlobItem> > ListBlobsAsync(CloudBlobDirectory cloudBlobDirectory) { BlobContinuationToken continuationToken = null; BlobResultSegment blobResultSegment = null; List <IListBlobItem> blobItems = new List <IListBlobItem>(); do { try { blobResultSegment = await cloudBlobDirectory.ListBlobsSegmentedAsync(continuationToken); continuationToken = blobResultSegment.ContinuationToken; blobItems.AddRange(blobResultSegment.Results); if (blobItems.Count >= 100000) { break; } } catch (Exception ex) { Console.WriteLine($"Problem with {blobResultSegment?.Results} {ex.Message} {ex?.InnerException?.Message}"); } }while (continuationToken != null); return(blobItems); }