Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        protected virtual async Task <Blob> GetBlobAsync(string fullPath, CancellationToken cancellationToken)
        {
            (BlobContainerClient container, string path) = await GetPartsAsync(fullPath, false).ConfigureAwait(false);

            if (container == null)
            {
                return(null);
            }

            if (string.IsNullOrEmpty(path))
            {
                //it's a container

                Response <BlobContainerProperties> attributes = await container.GetPropertiesAsync(cancellationToken : cancellationToken).ConfigureAwait(false);

                return(AzConvert.ToBlob(container.Name, attributes));
            }

            BlobClient client = container.GetBlobClient(path);

            try
            {
                Response <BlobProperties> properties = await client.GetPropertiesAsync(cancellationToken : cancellationToken).ConfigureAwait(false);

                return(AzConvert.ToBlob(_containerName, path, properties));
            }
            catch (RequestFailedException ex) when(ex.ErrorCode == "BlobNotFound")
            {
                return(null);
            }
        }