コード例 #1
0
 private void OnFolderUpdated(FolderUpdatedMessage message)
 {
     if (message.BlobStorage == Storage && StoragePath.ComparePath(message.FolderPath, FolderPath))
     {
         ServiceLocator.GetInstance <IUIDispatcher>().Invoke(() => Process(message));
     }
 }
コード例 #2
0
        public async Task <IReadOnlyCollection <Blob> > ListAsync(ListOptions options, CancellationToken cancellationToken)
        {
            var result = new List <Blob>();

            var request = new ListObjectsV2Request()
            {
                BucketName = _bucketName,
                Prefix     = options.FilePrefix ?? null
            };

            while (options.MaxResults == null || (result.Count < options.MaxResults))
            {
                ListObjectsV2Response response = await _client.ListObjectsV2Async(request, cancellationToken).ConfigureAwait(false);

                List <Blob> blobs = response.S3Objects
                                    .Where(s3Obj => !s3Obj.Key.EndsWith("/")) //these are "folders" in S3, but they don't always exist
                                    .Select(s3Obj => new Blob(StoragePath.RootFolderPath, s3Obj.Key, BlobItemKind.File)
                {
                    Size = s3Obj.Size
                })
                                    .Where(options.IsMatch)
                                    .Where(b => (options.FolderPath == null || StoragePath.ComparePath(b.FolderPath, options.FolderPath)))
                                    .Where(b => options.BrowseFilter == null || options.BrowseFilter(b))
                                    .ToList();

                result.AddRange(blobs);

                if (response.NextContinuationToken == null)
                {
                    break;
                }

                request.ContinuationToken = response.NextContinuationToken;
            }

            if (options.MaxResults != null && result.Count > options.MaxResults)
            {
                result = result.Take((int)options.MaxResults).ToList();
            }

            return(result);
        }
コード例 #3
0
        public Task <IReadOnlyCollection <Blob> > ListAsync(ListOptions options, CancellationToken cancellationToken)
        {
            if (options == null)
            {
                options = new ListOptions();
            }

            IEnumerable <KeyValuePair <string, Tag> > query = _pathToTag;

            //limit by folder path
            if (options.Recurse)
            {
                if (!StoragePath.IsRootPath(options.FolderPath))
                {
                    string prefix = options.FolderPath + StoragePath.PathSeparatorString;

                    query = query.Where(p => p.Key.StartsWith(prefix));
                }
            }
            else
            {
                query = query.Where(p => StoragePath.ComparePath(p.Value.blob.FolderPath, options.FolderPath));
            }

            //prefix
            query = query.Where(p => options.IsMatch(p.Value.blob));

            //browser filter
            query = query.Where(p => options.BrowseFilter == null || options.BrowseFilter(p.Value.blob));

            //limit
            if (options.MaxResults != null)
            {
                query = query.Take(options.MaxResults.Value);
            }

            IReadOnlyCollection <Blob> matches = query.Select(p => p.Value.blob).ToList();

            return(Task.FromResult(matches));
        }
コード例 #4
0
        public async Task <IReadOnlyCollection <Blob> > ListAsync(ListOptions options, CancellationToken cancellationToken)
        {
            var result = new List <Blob>();

            var request = new ListObjectsV2Request()
            {
                BucketName = _bucketName,
                Prefix     = options.FilePrefix ?? null
            };

            while (options.MaxResults == null || (result.Count < options.MaxResults))
            {
                ListObjectsV2Response response = await _client.ListObjectsV2Async(request, cancellationToken).ConfigureAwait(false);

                List <Blob> blobs = response.S3Objects
                                    .Select(ToBlob)
                                    .Where(options.IsMatch)
                                    .Where(b => (options.FolderPath == null || StoragePath.ComparePath(b.FolderPath, options.FolderPath)))
                                    .Where(b => options.BrowseFilter == null || options.BrowseFilter(b))
                                    .ToList();

                result.AddRange(blobs);

                if (response.NextContinuationToken == null)
                {
                    break;
                }

                request.ContinuationToken = response.NextContinuationToken;
            }

            if (options.MaxResults != null && result.Count > options.MaxResults)
            {
                result = result.Take((int)options.MaxResults).ToList();
            }

            return(result);
        }
コード例 #5
0
        public Task <IReadOnlyCollection <BlobId> > ListAsync(ListOptions options, CancellationToken cancellationToken)
        {
            if (options == null)
            {
                options = new ListOptions();
            }

            options.FolderPath = StoragePath.Normalize(options.FolderPath);

            List <BlobId> matches = _idToData

                                    .Where(e => options.Recurse
               ? e.Key.FolderPath.StartsWith(options.FolderPath)
               : StoragePath.ComparePath(e.Key.FolderPath, options.FolderPath))

                                    .Select(e => e.Key)
                                    .Where(options.IsMatch)
                                    .Where(e => options.BrowseFilter == null || options.BrowseFilter(e))
                                    .Take(options.MaxResults == null ? int.MaxValue : options.MaxResults.Value)
                                    .ToList();

            return(Task.FromResult((IReadOnlyCollection <BlobId>)matches));
        }