/// <summary>
        /// Gets all the blob names, then filters by prefix optionally
        /// </summary>
        public async Task <IEnumerable <BlobId> > ListAsync(ListOptions options, CancellationToken cancellationToken)
        {
            if (options == null)
            {
                options = new ListOptions();
            }

            var browser = new AzureBlobDirectoryBrowser(_blobContainer);

            return(await browser.ListFolder(options, cancellationToken));
        }
        private async Task ListAsync(CloudBlobContainer container, CloudBlobContainer fixedContainer,
                                     List <BlobId> result,
                                     ListOptions options,
                                     CancellationToken cancellationToken)
        {
            var browser = new AzureBlobDirectoryBrowser(container, _fixedContainer == null, options.MaxDegreeOfParalellism);
            IReadOnlyCollection <BlobId> containerBlobs = await browser.ListFolderAsync(options, cancellationToken);

            if (containerBlobs.Count > 0)
            {
                result.AddRange(containerBlobs);
            }
        }
Example #3
0
        public async Task <IReadOnlyCollection <BlobId> > ListAsync(ListOptions options, CancellationToken cancellationToken = default)
        {
            if (options == null)
            {
                options = new ListOptions();
            }

            var result     = new List <BlobId>();
            var containers = new List <CloudBlobContainer>();

            if (_fixedContainer != null)
            {
                containers.Add(_fixedContainer);
            }
            else if (options.FolderPath == null)
            {
                // list all of the containers
                containers.AddRange(await GetCloudBlobContainersAsync(cancellationToken));

                //represent containers as folders in the result
                result.AddRange(containers.Select(c => new BlobId(c.Name, BlobItemKind.Folder)));
            }
            else
            {
                (CloudBlobContainer container, string path) = await GetPartsAsync(options.FolderPath, false);

                if (container == null)
                {
                    return(new List <BlobId>());
                }
                options.FolderPath = path; //scan from subpath now
                containers.Add(container);

                //add container as search result
                result.Add(new BlobId(container.Name, BlobItemKind.Folder));
            }

            foreach (CloudBlobContainer container in containers)
            {
                var browser = new AzureBlobDirectoryBrowser(container);
                IReadOnlyCollection <BlobId> containerBlobs = await browser.ListFolderAsync(options, cancellationToken);

                if (containerBlobs.Count > 0)
                {
                    if (_fixedContainer == null)
                    {
                        result.AddRange(containerBlobs.Select(bid => new BlobId(StoragePath.Combine(container.Name, bid.FullPath), bid.Kind)));
                    }
                    else
                    {
                        result.AddRange(containerBlobs);
                    }
                }

                if (options.MaxResults != null && result.Count >= options.MaxResults.Value)
                {
                    break;
                }
            }

            return(result);
        }