Esempio n. 1
0
        public Task <IEnumerable <string> > GetFilesAsync(string path, StorageSearchOption storageSearchOption)
        {
            string       fileName            = $"{this._containerRoot}\\{path.Trim()}";
            var          containerRootLength = this._containerRoot.Length;
            SearchOption searchOption        = storageSearchOption.HasFlag(StorageSearchOption.AllDirectories) ?
                                               SearchOption.AllDirectories :
                                               SearchOption.TopDirectoryOnly;

            try {
                IEnumerable <string> query = Directory.EnumerateFiles(fileName, "*.*", searchOption);

                query = storageSearchOption.HasFlag(StorageSearchOption.StripPaths) ?
                        query.Select(Path.GetFileName) :
                        query.Select(f => f.Substring(containerRootLength));

                IEnumerable <string> files = query.ToArray();

                var tcs = new TaskCompletionSource <IEnumerable <string> >();
                tcs.SetResult(files);
                return(tcs.Task);
            }
            catch (Exception ex) {
                throw new StorageException(
                          StorageExceptionReason.StorageOperationFailed,
                          $"Error while getting files list. {path}",
                          ex);
            }
        }
Esempio n. 2
0
        public async Task <IEnumerable <string> > GetFilesAsync(string path, StorageSearchOption searchOption)
        {
            try {
                // ReSharper disable RedundantCast
                var selector = searchOption.HasFlag(StorageSearchOption.StripPaths) ?
                               (Func <IListBlobItem, string>)(item => item.Uri.Segments.Last()) :
                               (Func <IListBlobItem, string>)(item => {
                    string url             = item.Uri.ToString();
                    var containerUrlLenght = this._blobContainer.Uri.ToString().Length;
                    if (containerUrlLenght < url.Length)
                    {
                        url = url.Substring(containerUrlLenght + 1);
                    }

                    return(url);
                });

                // ReSharper restore RedundantCast

                var blobs = await this.ListBlobsAsync(this._blobContainer, this.GetCorrectPath(path, true), searchOption.HasFlag(StorageSearchOption.AllDirectories))
                            .ConfigureAwait(false);

                IEnumerable <string> files = blobs
                                             .Where(item => !(item is CloudBlobDirectory))
                                             .Select(selector)
                                             .ToList();

                return(files);
            }
            catch (Exception e) {
                throw new StorageException(
                          StorageExceptionReason.StorageOperationFailed,
                          $"Unable to get the files list. {path}",
                          e);
            }
        }
        public async Task<IEnumerable<string>> GetFilesAsync(string path, StorageSearchOption searchOption)
        {
            try {
                // ReSharper disable RedundantCast
                var selector = searchOption.HasFlag(StorageSearchOption.StripPaths) ?
                    (Func<IListBlobItem, string>)(item => item.Uri.Segments.Last()) :
                    (Func<IListBlobItem, string>)(item => {
                        string url = item.Uri.ToString();
                        var containerUrlLenght = this._blobContainer.Uri.ToString().Length;
                        if (containerUrlLenght < url.Length)
                            url = url.Substring(containerUrlLenght + 1);

                        return url;
                    });

                // ReSharper restore RedundantCast

                var blobs = await this.ListBlobsAsync(this._blobContainer, this.GetCorrectPath(path, true), searchOption.HasFlag(StorageSearchOption.AllDirectories))
                    .ConfigureAwait(false);

                IEnumerable<string> files = blobs
                        .Where(item => !(item is CloudBlobDirectory))
                        .Select(selector)
                        .ToList();

                return files;
            }
            catch (Exception e) {
                throw new StorageException(
                    StorageExceptionReason.StorageOperationFailed,
                    $"Unable to get the files list. {path}",
                    e);
            }
        }
        public Task<IEnumerable<string>> GetFilesAsync(string path, StorageSearchOption storageSearchOption)
        {
            string fileName = $"{this._containerRoot}\\{path.Trim()}";
            var containerRootLength = this._containerRoot.Length;
            SearchOption searchOption = storageSearchOption.HasFlag(StorageSearchOption.AllDirectories) ?
                SearchOption.AllDirectories :
                SearchOption.TopDirectoryOnly;

            try {
                IEnumerable<string> query = Directory.EnumerateFiles(fileName, "*.*", searchOption);

                query = storageSearchOption.HasFlag(StorageSearchOption.StripPaths) ?
                    query.Select(Path.GetFileName) :
                    query.Select(f => f.Substring(containerRootLength));

                IEnumerable<string> files = query.ToArray();

                var tcs = new TaskCompletionSource<IEnumerable<string>>();
                tcs.SetResult(files);
                return tcs.Task;
            }
            catch (Exception ex) {
                throw new StorageException(
                    StorageExceptionReason.StorageOperationFailed,
                    $"Error while getting files list. {path}",
                    ex);
            }
        }