public async Task <IReadOnlyCollection <Blob> > ListFolderAsync(ListOptions options, CancellationToken cancellationToken) { var result = new List <Blob>(); await foreach (BlobHierarchyItem item in _client.GetBlobsByHierarchyAsync( delimiter: options.Recurse ? null : "/", prefix: FormatFolderPrefix(options.FolderPath), traits: options.IncludeAttributes ? BlobTraits.Metadata : BlobTraits.None).ConfigureAwait(false)) { Blob blob = AzConvert.ToBlob(_prependContainerName ? _client.Name : null, item); if (options.IsMatch(blob) && (options.BrowseFilter == null || options.BrowseFilter(blob))) { result.Add(blob); } } if (options.Recurse) { AssumeImplicitPrefixes( _prependContainerName ? StoragePath.Combine(_client.Name, options.FolderPath) : options.FolderPath, result); } return(result); }
private async Task ListFolderAsync(List <Blob> container, string path, ListOptions options, CancellationToken cancellationToken) { CloudBlobDirectory dir = GetCloudBlobDirectory(path); BlobContinuationToken token = null; var batch = new List <Blob>(); await _throttler.WaitAsync(); try { do { BlobResultSegment segment = await dir.ListBlobsSegmentedAsync( false, //automatically include metadata in the response options.IncludeAttributes?BlobListingDetails.Metadata : BlobListingDetails.None, null, token, null, null, cancellationToken).ConfigureAwait(false); token = segment.ContinuationToken; foreach (IListBlobItem listItem in segment.Results) { Blob blob = ToBlob(listItem); if (options.IsMatch(blob) && (options.BrowseFilter == null || options.BrowseFilter(blob))) { batch.Add(blob); } } }while (token != null && ((options.MaxResults == null) || (container.Count + batch.Count < options.MaxResults.Value))); } finally { _throttler.Release(); } batch = batch.Where(options.IsMatch).ToList(); if (options.Add(container, batch)) { return; } if (options.Recurse) { var folderIds = batch.Where(r => r.Kind == BlobItemKind.Folder).ToList(); await Task.WhenAll( folderIds.Select(folderId => ListFolderAsync( container, StoragePath.Combine(path, folderId.Name), options, cancellationToken))).ConfigureAwait(false); } }
private async Task ListFolderAsync(List <BlobId> container, string path, ListOptions options, CancellationToken cancellationToken) { CloudBlobDirectory dir = GetCloudBlobDirectory(path); BlobContinuationToken token = null; var batch = new List <BlobId>(); await _throttler.WaitAsync(); try { do { BlobResultSegment segment = await dir.ListBlobsSegmentedAsync( false, BlobListingDetails.None, null, token, null, null, cancellationToken); token = segment.ContinuationToken; foreach (IListBlobItem blob in segment.Results) { BlobId id = ToBlobId(blob, options.IncludeMetaWhenKnown); if (options.IsMatch(id) && (options.BrowseFilter == null || options.BrowseFilter(id))) { batch.Add(id); } } }while (token != null && ((options.MaxResults == null) || (container.Count + batch.Count < options.MaxResults.Value))); } finally { _throttler.Release(); } batch = batch.Where(options.IsMatch).ToList(); if (options.Add(container, batch)) { return; } options.ListProgressCallback?.Invoke(container.Count, -1); if (options.Recurse) { List <BlobId> folderIds = batch.Where(r => r.Kind == BlobItemKind.Folder).ToList(); await Task.WhenAll( folderIds.Select(folderId => ListFolderAsync( container, StoragePath.Combine(path, folderId.Id), options, cancellationToken))); } }
private async Task ListFolderAsync(List <BlobId> container, string path, ListOptions options, CancellationToken cancellationToken) { CloudBlobDirectory dir = GetCloudBlobDirectory(path); BlobContinuationToken token = null; var batch = new List <BlobId>(); do { BlobResultSegment segment = await dir.ListBlobsSegmentedAsync( false, BlobListingDetails.None, null, token, null, null, cancellationToken); token = segment.ContinuationToken; foreach (IListBlobItem blob in segment.Results) { BlobId id = ToBlobId(blob, options.IncludeMetaWhenKnown); if (options.IsMatch(id)) { batch.Add(id); } } }while (token != null && ((options.MaxResults == null) || (container.Count + batch.Count < options.MaxResults.Value))); batch = batch.Where(options.IsMatch).ToList(); if (options.Add(container, batch)) { return; } if (options.Recurse) { List <BlobId> folderIds = batch.Where(r => r.Kind == BlobItemKind.Folder).ToList(); foreach (BlobId folderId in folderIds) { await ListFolderAsync( container, StoragePath.Combine(path, folderId.Id), options, cancellationToken); } } }
public async Task ListFolder(List <BlobId> container, string path, ListOptions options, CancellationToken cancellationToken) { CloudBlobDirectory dir = GetCloudBlobDirectory(path); BlobContinuationToken token = null; var batch = new List <BlobId>(); do { BlobResultSegment segment = await dir.ListBlobsSegmentedAsync( false, BlobListingDetails.None, null, token, null, null, cancellationToken); token = segment.ContinuationToken; foreach (IListBlobItem blob in segment.Results) { BlobId id; if (blob is CloudBlockBlob blockBlob) { id = new BlobId(blockBlob.Name, BlobItemKind.File); } else if (blob is CloudAppendBlob appendBlob) { id = new BlobId(appendBlob.Name, BlobItemKind.File); } else if (blob is CloudBlobDirectory dirBlob) { id = new BlobId(dirBlob.Prefix, BlobItemKind.Folder); } else { throw new InvalidOperationException($"unknown item type {blob.GetType()}"); } if (options.IsMatch(id)) { batch.Add(id); } } }while (token != null && ((options.MaxResults == null) || (container.Count + batch.Count < options.MaxResults.Value))); batch = batch.Where(options.IsMatch).ToList(); if (options.Add(container, batch)) { return; } if (options.Recurse) { List <BlobId> folderIds = batch.Where(r => r.Kind == BlobItemKind.Folder).ToList(); foreach (BlobId folderId in folderIds) { await ListFolder( container, StoragePath.Combine(path, folderId.Id), options, cancellationToken); } } }