コード例 #1
0
ファイル: ExtendedSdk.cs プロジェクト: nisun-007/storage
        private async Task <IReadOnlyCollection <Blob> > ListPathAsync(string path, int?maxResults, ListOptions options, CancellationToken cancellationToken)
        {
            //get filesystem name and folder path
            string[] parts = StoragePath.Split(path);

            string fs           = parts[0];
            string relativePath = StoragePath.Combine(parts.Skip(1));

            var list = new List <Gen2Path>();

            try
            {
                string continuation = null;
                do
                {
                    string continuationParam = continuation == null ? null : $"&continuation={continuation}";

                    (PathList pl, IDictionary <string, string> responseHeaders) = await InvokeExtraAsync <PathList>(
                        $"{fs}?resource=filesystem&directory={relativePath.UrlEncode()}&recursive={options.Recurse}{continuationParam}",
                        RequestMethod.Get,
                        cancellationToken).ConfigureAwait(false);

                    list.AddRange(pl.Paths);

                    responseHeaders.TryGetValue("x-ms-continuation", out continuation);
                } while(continuation != null);
            }
            catch (RequestFailedException ex) when(ex.ErrorCode == "PathNotFound" || ex.ErrorCode == "FilesystemNotFound")
            {
                // trying to list a path which doesn't exist, just return an empty result
                return(new List <Blob>());
            }

            IEnumerable <Blob> result = list.Select(p => AzConvert.ToBlob(fs, p));

            if (options.FilePrefix != null)
            {
                result = result.Where(b => b.IsFolder || b.Name.StartsWith(options.FilePrefix));
            }

            if (options.BrowseFilter != null)
            {
                result = result.Where(b => options.BrowseFilter(b));
            }

            if (maxResults != null)
            {
                result = result.Take(maxResults.Value);
            }

            return(result.ToList());
        }
コード例 #2
0
ファイル: ExtendedSdk.cs プロジェクト: nisun-007/storage
        public async Task <Blob> GetBlobAsync(string fullPath, CancellationToken cancellationToken)
        {
            DecomposePath(fullPath, out string fs, out string rp, false);

            if (StoragePath.IsRootPath(rp))
            {
                try
                {
                    (Void _, IDictionary <string, string> headers) = await InvokeExtraAsync <Void>(
                        $"{fs}?resource=filesystem",
                        RequestMethod.Head,
                        cancellationToken).ConfigureAwait(false);

                    return(AzConvert.ToBlob(fullPath, headers, true));
                }
                catch (RequestFailedException ex) when(ex.ErrorCode == "FilesystemNotFound")
                {
                    //filesystem doesn't exist
                    return(null);
                }
            }

            try
            {
                (Void _, IDictionary <string, string> fheaders) = await InvokeExtraAsync <Void>(
                    $"{fs}/{rp.UrlEncode()}?action=getProperties",
                    RequestMethod.Head,
                    cancellationToken).ConfigureAwait(false);

                return(AzConvert.ToBlob(fullPath, fheaders, false));
            }
            catch (RequestFailedException ex) when(ex.ErrorCode == "PathNotFound")
            {
                return(null);
            }
        }