示例#1
0
        private async Task <Blob> GetBlobAsync(string fullPath, CancellationToken cancellationToken)
        {
            DecomposePath(fullPath, out string fs, out string rp, false);

            if (StoragePath.IsRootPath(rp))
            {
                try
                {
                    ApiResponse <string> response = await _restApi.GetFilesystemProperties(fs);

                    await response.EnsureSuccessStatusCodeAsync();

                    var fsProps = new PathProperties(response);
                    return(LConvert.ToBlob(fs, fsProps));
                }
                catch (ApiException ex) when(ex.StatusCode == HttpStatusCode.NotFound)
                {
                    return(null);
                }
            }

            PathProperties pp;

            try
            {
                pp = await GetPathPropertiesAsync(fs, rp, "getProperties").ConfigureAwait(false);
            }
            catch (ApiException ex) when(ex.StatusCode == HttpStatusCode.NotFound)
            {
                return(null);
            }

            return(LConvert.ToBlob(fullPath, pp));
        }
        private async Task <Blob> GetBlobAsync(string fullPath, CancellationToken cancellationToken)
        {
            DecomposePath(fullPath, out string fs, out string rp);
            PathProperties pp;

            try
            {
                pp = await GetPathPropertiesAsync(fs, rp, "getProperties").ConfigureAwait(false);
            }
            catch (ApiException ex) when(ex.StatusCode == HttpStatusCode.NotFound)
            {
                return(null);
            }

            return(LConvert.ToBlob(fullPath, pp));
        }
示例#3
0
        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));

            PathList list;

            try
            {
                list = await _api.ListPathAsync(fs, relativePath, recursive : options.Recurse).ConfigureAwait(false);
            }
            catch (ApiException ex) when(ex.StatusCode == HttpStatusCode.NotFound)
            {
                // specified path is not found, nothing serious
                return(new List <Blob>());
            }

            IEnumerable <Blob> result = list.Paths.Select(p => LConvert.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());
        }