private Task<BlobResultSegment> ListBlobsSegmented(string prefix, bool useFlatBlobListing, BlobListingDetails blobListingDetails, int? maxResults, BlobContinuationToken continuationToken, BlobRequestOptions options, OperationContext operationContext, CancellationToken cancellationToken = default(CancellationToken))
 {
     return AsyncTaskUtil.RunAsyncCancellable<BlobResultSegment>(
         _inner.BeginListBlobsSegmented(prefix, useFlatBlobListing, blobListingDetails, maxResults, continuationToken, options, operationContext, null, null),
         _inner.EndListBlobsSegmented,
         cancellationToken);
 }
Пример #2
0
 public BlobResultSegment ListBlobsSegmented(string prefix, bool useFlatListing, BlobListingDetails blobListingDetails,
     int? maxResults, BlobContinuationToken continuationToken, BlobRequestOptions blobRequestOptions,
     OperationContext operationContext)
 {
     return _client.ListBlobsSegmented(prefix, useFlatListing, blobListingDetails, maxResults, continuationToken,
         blobRequestOptions, operationContext);
 }
        /// <summary>
        ///     Returns an enumerable collection of the blobs in the container that are retrieved asynchronously.
        /// </summary>
        /// <param name="blobDirectory">Cloud blob directory.</param>
        /// <param name="cloudBlobs">List of cloud blobs.</param>
        /// <param name="useFlatBlobListing">Whether to list blobs in a flat listing, or whether to list blobs hierarchically, by virtual directory.</param>
        /// <param name="blobListingDetails">
        ///     A <see cref="T:Microsoft.WindowsAzure.Storage.Blob.BlobListingDetails" /> enumeration describing which items to include in the listing.
        /// </param>
        /// <param name="maxResults">
        ///     A non-negative integer value that indicates the maximum number of results to be returned at a time, up to the
        ///     per-operation limit of 5000. If this value is null, the maximum possible number of results will be returned, up to 5000.
        /// </param>
        /// <param name="continuationToken">Continuation token.</param>
        /// <param name="cancellationToken">Cancellation token.</param>
        /// <returns>
        ///     An enumerable collection of objects that implement <see cref="T:Microsoft.WindowsAzure.Storage.Blob.IListBlobItem" /> that are retrieved.
        /// </returns>
        private static Task<List<IListBlobItem>> ListBlobsImplAsync(
            this CloudBlobDirectory blobDirectory,
            List<IListBlobItem> cloudBlobs,
            bool useFlatBlobListing,
            BlobListingDetails blobListingDetails,
            int? maxResults,
            BlobContinuationToken continuationToken,
            CancellationToken cancellationToken = default (CancellationToken))
        {
            return blobDirectory
                .ListBlobsSegmentedAsync(useFlatBlobListing, blobListingDetails, maxResults, continuationToken, cancellationToken)
                .Then(result =>
                    {
                        cancellationToken.ThrowIfCancellationRequested();

                        cloudBlobs.AddRange(result.Results);

                        // Checks whether maxresults entities has been received
                        if (maxResults.HasValue && cloudBlobs.Count >= maxResults.Value)
                        {
                            return TaskHelpers.FromResult(cloudBlobs.Take(maxResults.Value).ToList());
                        }

                        // Checks whether enumeration has been completed
                        if (result.ContinuationToken != null)
                        {
                            return ListBlobsImplAsync(blobDirectory, cloudBlobs, useFlatBlobListing, blobListingDetails, maxResults, continuationToken, cancellationToken);
                        }

                        return TaskHelpers.FromResult(cloudBlobs);
                    });
        }
        public static async Task<IEnumerable<IStorageListBlobItem>> ListBlobsAsync(this IStorageBlobClient client,
            string prefix, bool useFlatBlobListing, BlobListingDetails blobListingDetails,
            CancellationToken cancellationToken)
        {
            if (client == null)
            {
                throw new ArgumentNullException("client");
            }

            List<IStorageListBlobItem> allResults = new List<IStorageListBlobItem>();
            BlobContinuationToken continuationToken = null;
            IStorageBlobResultSegment result;

            do
            {
                result = await client.ListBlobsSegmentedAsync(prefix, useFlatBlobListing, blobListingDetails,
                    maxResults: null, currentToken: continuationToken, options: null, operationContext: null,
                    cancellationToken: cancellationToken);

                if (result != null)
                {
                    IEnumerable<IStorageListBlobItem> currentResults = result.Results;
                    if (currentResults != null)
                    {
                        allResults.AddRange(currentResults);
                    }

                    continuationToken = result.ContinuationToken;
                }
            }
            while (result != null && continuationToken != null);

            return allResults;
        }
		public static async Task<ReadOnlyCollection<IListBlobItem>> ListBlobsSegmentedAsync(
			this CloudBlobDirectory container,
			bool useFlatBlobListing,
			int pageSize,
			BlobListingDetails details,
			BlobRequestOptions options,
			OperationContext operationContext,
			IProgress<IEnumerable<IListBlobItem>> progress = null,
			CancellationToken cancellationToken = default(CancellationToken)) {
			options = options ?? new BlobRequestOptions();
			var results = new List<IListBlobItem>();
			BlobContinuationToken continuation = null;
			BlobResultSegment segment;
			do {
				segment = await Task.Factory.FromAsync(
					(cb, state) => container.BeginListBlobsSegmented(useFlatBlobListing, details, pageSize, continuation, options, operationContext, cb, state).WithCancellation(cancellationToken),
					ar => container.EndListBlobsSegmented(ar),
					null);
				if (progress != null) {
					progress.Report(segment.Results);
				}
				results.AddRange(segment.Results);
				continuation = segment.ContinuationToken;
			} while (continuation != null);

			return new ReadOnlyCollection<IListBlobItem>(results);
		}
Пример #6
0
        public static IAzureBlobResultSegment ListBlobsSegmentedAsync(
            string containerDirectory,
            string searchDirectory,
            string prefix,
            BlobListing blobListing,
            BlobListingDetails blobListingDetails,
            int? maxResults,
            BlobContinuationToken currentToken)
        {
            if (blobListing == BlobListing.Hierarchical && (blobListingDetails & BlobListingDetails.Snapshots) == BlobListingDetails.Snapshots)
            {
                throw new ArgumentException("Listing snapshots is only supported in flat mode.");
            }

            var numberToSkip = DetermineNumberToSkip(currentToken);

            var resultSegment = blobListing == BlobListing.Flat
                ? FindFilesFlattened(containerDirectory, searchDirectory, prefix, maxResults, numberToSkip)
                : FindFilesHierarchical(containerDirectory, searchDirectory, prefix, maxResults, numberToSkip);

            if ((blobListingDetails & BlobListingDetails.Metadata) == BlobListingDetails.Metadata)
            {
                foreach (var blob in resultSegment.Results.OfType<StandaloneAzureBlockBlob>())
                {
                    blob.FetchAttributes();
                }
            }

            return resultSegment;
        }
 /// <inheritdoc />
 public Task<IStorageBlobResultSegment> ListBlobsSegmentedAsync(string prefix, bool useFlatBlobListing,
     BlobListingDetails blobListingDetails, int? maxResults, BlobContinuationToken currentToken,
     BlobRequestOptions options, OperationContext operationContext, CancellationToken cancellationToken)
 {
     Task<BlobResultSegment> sdkTask = _sdk.ListBlobsSegmentedAsync(prefix, useFlatBlobListing,
         blobListingDetails, maxResults, currentToken, options, operationContext, cancellationToken);
     return ListBlobsSegmentedAsyncCore(sdkTask);
 }
 public void AllowsSnapshotsOnlyInFlatMode(BlobListingDetails blobListingDetails)
 {
     var container = new StandaloneAzureBlobContainer(BasePath);
     Assert.Throws<ArgumentException>(() => container.ListBlobsSegmentedAsync(
         "",
         BlobListing.Hierarchical,
         blobListingDetails,
         500,
         null));
 }
 public async Task<IAzureBlobResultSegment> ListBlobsSegmentedAsync(BlobListing blobListing, BlobListingDetails blobListingDetails, int? maxResults, BlobContinuationToken currentToken)
 {
     return new HostedAzureBlobResultSegment(await _cloudBlobDirectory.ListBlobsSegmentedAsync(
         blobListing == BlobListing.Flat,
         blobListingDetails,
         maxResults,
         currentToken,
         null,
         null));
 }
 public Task<IAzureBlobResultSegment> ListBlobsSegmentedAsync(BlobListing blobListing, BlobListingDetails blobListingDetails, int? maxResults, BlobContinuationToken currentToken)
 {
     return Task.FromResult(StandaloneList.ListBlobsSegmentedAsync(
         _containerDirectory,
         _directoryPath,
         "",
         blobListing,
         blobListingDetails,
         maxResults,
         currentToken));
 }
Пример #11
0
        public async Task ContainerWillNotLoadMetadataIfNotSpecifiedForFlatListing(BlobListingDetails blobListingDetails)
        {
            var results = await new StandaloneAzureBlobContainer(BasePath)
                .ListBlobsSegmentedAsync(
                    "",
                    BlobListing.Flat,
                    blobListingDetails,
                    null,
                    null);

            Assert.Empty(results.Results.OfType<IAzureBlockBlob>().First(r => r.Name == "flat").Metadata);
        }
Пример #12
0
 public static async Task<List<IListBlobItem>> ListBlobsAsync(this CloudBlobContainer container, string prefix, BlobListingDetails details)
 {
     BlobContinuationToken continuationToken = null;
     List<IListBlobItem> results = new List<IListBlobItem>();
     do
     {
         var response = await container.ListBlobsSegmentedAsync(prefix, true, details, null, continuationToken, new BlobRequestOptions(), new OperationContext());
         continuationToken = response.ContinuationToken;
         results.AddRange(response.Results);
     }
     while (continuationToken != null);
     return results;
 }
        public Task<IAzureBlobResultSegment> ListBlobsSegmentedAsync(string prefix, BlobListing blobListing, BlobListingDetails blobListingDetails, int? maxResults, BlobContinuationToken currentToken)
        {
            if (blobListing == BlobListing.Hierarchical && (blobListingDetails & BlobListingDetails.Snapshots) == BlobListingDetails.Snapshots)
            {
                throw new ArgumentException("Listing snapshots is only supported in flat mode.");
            }

            var numberToSkip = DetermineNumberToSkip(currentToken);

            var resultSegment = blobListing == BlobListing.Flat
                ? FindFilesFlattened(prefix, maxResults, numberToSkip)
                : FindFilesHierarchical(prefix, maxResults, numberToSkip);

            return Task.FromResult((IAzureBlobResultSegment) resultSegment);
        }
        public IObservable<IAsyncListBlobItem> ListBlobs(string prefix, bool useFlatBlobListing, BlobListingDetails blobListingDetails = BlobListingDetails.None, int? maxResults = null, BlobRequestOptions options = null, OperationContext operationContext = null)
        {
            return Observable.Create<IAsyncListBlobItem>(
            async (observer, ct) =>
            {
                var containerToken = new BlobContinuationToken();
                while (containerToken != null)
                {
                    var results = await ListBlobsSegmented(prefix, useFlatBlobListing, blobListingDetails, maxResults, containerToken, options, operationContext, ct);
                    foreach (var result in results.Results)
                    {
                        observer.OnNext(AsyncListBlobItemHelpers.FromIListBlobItem(result));
                    }

                    containerToken = results.ContinuationToken;
                }
            });
        }
        /// <summary>
        ///     Returns a result segment containing a collection of blob items in the container asynchronously.
        /// </summary>
        /// <param name="blobDirectory">Cloud blob directory.</param>
        /// <param name="useFlatBlobListing">Whether to list blobs in a flat listing, or whether to list blobs hierarchically, by virtual directory.</param>
        /// <param name="blobListingDetails">
        ///     A <see cref="T:Microsoft.WindowsAzure.Storage.Blob.BlobListingDetails" /> enumeration describing which items to include in the listing.
        /// </param>
        /// <param name="maxResults">
        ///     A non-negative integer value that indicates the maximum number of results to be returned at a time, up to the
        ///     per-operation limit of 5000. If this value is <c>null</c>, the maximum possible number of results will be returned, up to 5000.
        /// </param>
        /// <param name="continuationToken">A continuation token returned by a previous listing operation.</param>
        /// <param name="cancellationToken">Cancellation token.</param>
        /// <returns>
        ///     The ID of the acquired lease.
        /// </returns>
        public static Task<BlobResultSegment> ListBlobsSegmentedAsync(
            this CloudBlobDirectory blobDirectory,
            bool useFlatBlobListing,
            BlobListingDetails blobListingDetails,
            int? maxResults,
            BlobContinuationToken continuationToken,
            CancellationToken cancellationToken = default (CancellationToken))
        {
            ICancellableAsyncResult asyncResult = blobDirectory.BeginListBlobsSegmented(useFlatBlobListing, blobListingDetails, maxResults, continuationToken, null, null, null, null);
            CancellationTokenRegistration registration = cancellationToken.Register(p => asyncResult.Cancel(), null);

            return Task<BlobResultSegment>.Factory.FromAsync(
                asyncResult,
                result =>
                    {
                        registration.Dispose();
                        return blobDirectory.EndListBlobsSegmented(result);
                    });
        }
        public Task<IStorageBlobResultSegment> ListBlobsSegmentedAsync(string prefix, bool useFlatBlobListing,
            BlobListingDetails blobListingDetails, int? maxResults, BlobContinuationToken currentToken,
            BlobRequestOptions options, OperationContext operationContext, CancellationToken cancellationToken)
        {
            if (options != null)
            {
                throw new NotImplementedException();
            }

            if (operationContext != null)
            {
                throw new NotImplementedException();
            }

            Func<string, IStorageBlobContainer> containerFactory = (n) => new FakeStorageBlobContainer(_store, n, this);
            IStorageBlobResultSegment segment = _store.ListBlobsSegmented(containerFactory, prefix, useFlatBlobListing,
                blobListingDetails, maxResults, currentToken);
            return Task.FromResult(segment);
        }
Пример #17
0
        public IStorageBlobResultSegment ListBlobsSegmented(Func<string, IStorageBlobContainer> containerFactory,
            string prefix, bool useFlatBlobListing, BlobListingDetails blobListingDetails, int? maxResults,
            BlobContinuationToken currentToken)
        {
            if (prefix == null)
            {
                throw new ArgumentNullException("prefix");
            }

            if (!useFlatBlobListing)
            {
                throw new NotImplementedException();
            }

            if (maxResults.HasValue)
            {
                throw new NotImplementedException();
            }

            if (blobListingDetails != BlobListingDetails.None && blobListingDetails != BlobListingDetails.Metadata)
            {
                throw new NotImplementedException();
            }

            if (prefix.StartsWith("$logs/"))
            {
                return null;
            }

            if (prefix.Contains("/"))
            {
                throw new NotImplementedException();
            }

            if (!_items.ContainsKey(prefix))
            {
                return null;
            }

            IStorageBlobContainer parent = containerFactory.Invoke(prefix);
            IEnumerable<IStorageBlob> results = _items[prefix].ListBlobs(this, parent, blobListingDetails);
            return new StorageBlobResultSegment(null, results);
        }
        public Task<IStorageBlobResultSegment> ListBlobsSegmentedAsync(string prefix, bool useFlatBlobListing,
            BlobListingDetails blobListingDetails, int? maxResults, BlobContinuationToken currentToken,
            BlobRequestOptions options, OperationContext operationContext, CancellationToken cancellationToken)
        {
            if (options != null)
            {
                throw new NotImplementedException();
            }

            if (operationContext != null)
            {
                throw new NotImplementedException();
            }

            string fullPrefix;

            if (!String.IsNullOrEmpty(prefix))
            {
                fullPrefix = _containerName + "/" + prefix;
            }
            else
            {
                fullPrefix = _containerName;
            }

            Func<string, IStorageBlobContainer> containerFactory = (name) =>
            {
                if (name != _containerName)
                {
                    throw new InvalidOperationException();
                }

                return this;
            };
            IStorageBlobResultSegment segment = _store.ListBlobsSegmented(containerFactory, fullPrefix,
                useFlatBlobListing, blobListingDetails, maxResults, currentToken);
            return Task.FromResult(segment);
        }
Пример #19
0
        public IEnumerable<IListBlobItem> ListBlobs(string prefix, bool useFlatBlobListing = false, BlobListingDetails blobListingDetails = BlobListingDetails.None, BlobRequestOptions options = null, OperationContext operationContext = null)
        {
            string containerName;
            string listingPrefix;
            CloudBlobClient.ParseUserPrefix(prefix, out containerName, out listingPrefix);

            CloudBlobContainer container = this.GetContainerReference(containerName);
            return container.ListBlobs(listingPrefix, useFlatBlobListing, blobListingDetails, options, operationContext);
        }
 /// List part of blobs.
 /// </summary>
 /// <param name="prefix">Blob prefix</param>
 /// <param name="useFlatBlobListing">Use flat blob listing</param>
 /// <param name="blobListingDetails">Blob listing details.</param>
 /// <param name="maxResults">Max results.</param>
 /// <param name="currentToken">Current token.</param>
 /// <param name="options">Request options</param>
 /// <param name="operationContext">Operation Context.</param>
 /// <returns>BlobResultSegment object</returns>
 public BlobResultSegment ListBlobsSegmented(CloudBlobContainer container, string prefix, bool useFlatBlobListing,
     BlobListingDetails blobListingDetails, int? maxResults, BlobContinuationToken currentToken, BlobRequestOptions options, OperationContext operationContext)
 {
     return container.ListBlobsSegmented(prefix, useFlatBlobListing, blobListingDetails, maxResults, currentToken, options, operationContext);
 }
        /// <summary>
        /// Core implementation of the ListBlobs method.
        /// </summary>
        /// <param name="prefix">The blob prefix.</param>
        /// <param name="maxResults">A non-negative integer value that indicates the maximum number of results to be returned at a time, up to the 
        /// per-operation limit of 5000. If this value is <c>null</c>, the maximum possible number of results will be returned, up to 5000.</param>
        /// <param name="useFlatBlobListing">Whether to list blobs in a flat listing, or whether to list blobs hierarchically, by virtual directory.</param>
        /// <param name="blobListingDetails">A <see cref="BlobListingDetails"/> enumeration describing which items to include in the listing.</param>
        /// <param name="options">A <see cref="BlobRequestOptions"/> object that specifies additional options for the request.</param>
        /// <param name="currentToken">The continuation token.</param>
        /// <returns>A <see cref="RESTCommand"/> that lists the blobs.</returns>
        private RESTCommand<ResultSegment<IListBlobItem>> ListBlobsImpl(string prefix, int? maxResults, bool useFlatBlobListing, BlobListingDetails blobListingDetails, BlobRequestOptions options, BlobContinuationToken currentToken)
        {
            if (!useFlatBlobListing
                && (blobListingDetails & BlobListingDetails.Snapshots) == BlobListingDetails.Snapshots)
            {
                throw new ArgumentException(SR.ListSnapshotsWithDelimiterError, "blobListingDetails");
            }

            string delimiter = useFlatBlobListing ? null : this.ServiceClient.DefaultDelimiter;
            BlobListingContext listingContext = new BlobListingContext(prefix, maxResults, delimiter, blobListingDetails)
            {
                Marker = currentToken != null ? currentToken.NextMarker : null
            };

            RESTCommand<ResultSegment<IListBlobItem>> getCmd = new RESTCommand<ResultSegment<IListBlobItem>>(this.ServiceClient.Credentials, this.StorageUri);

            options.ApplyToStorageCommand(getCmd);
            getCmd.CommandLocationMode = CommonUtility.GetListingLocationMode(currentToken);
            getCmd.RetrieveResponseStream = true;
            getCmd.Handler = this.ServiceClient.AuthenticationHandler;
            getCmd.BuildClient = HttpClientFactory.BuildHttpClient;
            getCmd.BuildRequest = (cmd, uri, builder, cnt, serverTimeout, ctx) => ContainerHttpRequestMessageFactory.ListBlobs(uri, serverTimeout, listingContext, cnt, ctx);
            getCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp, null /* retVal */, cmd, ex);
            getCmd.PostProcessResponse = (cmd, resp, ctx) =>
            {
                return Task.Factory.StartNew(() =>
                {
                    ListBlobsResponse listBlobsResponse = new ListBlobsResponse(cmd.ResponseStream);
                    List<IListBlobItem> blobList = listBlobsResponse.Blobs.Select(item => this.SelectListBlobItem(item)).ToList();
                    BlobContinuationToken continuationToken = null;
                    if (listBlobsResponse.NextMarker != null)
                    {
                        continuationToken = new BlobContinuationToken()
                        {
                            NextMarker = listBlobsResponse.NextMarker,
                            TargetLocation = cmd.CurrentResult.TargetLocation,
                        };
                    }

                    return new ResultSegment<IListBlobItem>(blobList)
                    {
                        ContinuationToken = continuationToken,
                    };
                });
            };

            return getCmd;
        }
        /// <summary>
        /// Returns an enumerable collection of log blobs containing Analytics log records. The blobs are retrieved lazily.
        /// </summary>
        /// <param name="service">A <see cref="StorageService"/> enumeration value.</param>
        /// <param name="startTime">A <see cref="DateTimeOffset"/> object representing the start of the time range for which logs should be retrieved.</param>
        /// <param name="endTime">A <see cref="DateTimeOffset"/> object representing the end of the time range for which logs should be retrieved.</param>
        /// <param name="operations">A <see cref="LoggingOperations"/> enumeration value that indicates the types of logging operations on which to filter the log blobs.</param>
        /// <param name="details">A <see cref="BlobListingDetails"/> enumeration value that indicates whether or not blob metadata should be returned. Only <c>None</c> and <c>Metadata</c> are valid values. </param>
        /// <param name="options">A <see cref="BlobRequestOptions"/> object that specifies additional options for the request.</param>
        /// <param name="operationContext">An <see cref="OperationContext"/> object that represents the context for the current operation.</param>
        /// <returns>An enumerable collection of objects that implement <see cref="ICloudBlob"/> and are retrieved lazily.</returns>
        /// <remarks>Note that specifying a logging operation type for the <paramref name="operations"/> parameter will return any Analytics log blob that contains the specified logging operation,
        /// even if that log blob also includes other types of logging operations. Also note that the only currently supported values for the <paramref name="details"/> 
        /// parameter are <c>None</c> and <c>Metadata</c>.</remarks>
        public IEnumerable<ICloudBlob> ListLogs(StorageService service, DateTimeOffset startTime, DateTimeOffset? endTime, LoggingOperations operations, BlobListingDetails details, BlobRequestOptions options, OperationContext operationContext)
        {
            CloudBlobDirectory logDirectory = this.GetLogDirectory(service);
            BlobListingDetails metadataDetails = details;
            DateTimeOffset utcStartTime = startTime.ToUniversalTime();
            DateTimeOffset dateCounter = new DateTimeOffset(utcStartTime.Ticks - (utcStartTime.Ticks % TimeSpan.TicksPerHour), utcStartTime.Offset);
            DateTimeOffset? utcEndTime = null;
            string endPrefix = null;

            // Ensure that the date range is correct.
            if (endTime.HasValue)
            {
                utcEndTime = endTime.Value.ToUniversalTime();
                endPrefix = logDirectory.Prefix + utcEndTime.Value.ToString("yyyy/MM/dd/HH", CultureInfo.InvariantCulture);
                if (utcStartTime > utcEndTime.Value)
                {
                    string errorString = string.Format(CultureInfo.InvariantCulture, SR.StartTimeExceedsEndTime, startTime, endTime.Value);
                    throw new ArgumentException(errorString);
                }
            }

            // Currently only support the ability to retrieve metadata on logs.
            if (details.HasFlag(BlobListingDetails.Copy) || details.HasFlag(BlobListingDetails.Snapshots) || details.HasFlag(BlobListingDetails.UncommittedBlobs))
            {
                throw new ArgumentException(SR.InvalidListingDetails);
            }

            // At least one LogType must be specified.
            if (operations == LoggingOperations.None)
            {
                throw new ArgumentException(SR.InvalidLoggingLevel);
            }

            // If metadata or a specific LogType is specified, metadata should be retrieved.
            if (details.HasFlag(BlobListingDetails.Metadata) || !operations.HasFlag(LoggingOperations.All))
            {
                metadataDetails = BlobListingDetails.Metadata;
            }

            // Check logs using an hour-based prefix until we reach a day boundary.
            while (dateCounter.Hour > 0)
            {
                string currentPrefix = logDirectory.Prefix + dateCounter.ToString("yyyy/MM/dd/HH", CultureInfo.InvariantCulture);
                IEnumerable<IListBlobItem> currentLogs = logDirectory.Container.ListBlobs(currentPrefix, true, metadataDetails, options, operationContext);

                foreach (ICloudBlob log in currentLogs)
                {
                    if (!utcEndTime.HasValue || string.Compare(log.Parent.Prefix, endPrefix) <= 0)
                    {
                        if (IsCorrectLogType(log, operations))
                        {
                            yield return log;
                        }
                    }
                    else
                    {
                        yield break;
                    }
                }

                dateCounter = dateCounter.AddHours(1);
                if (dateCounter > DateTimeOffset.UtcNow.AddHours(1))
                {
                    yield break;
                }
            }

            // Check logs using a day-based prefix until we reach a month boundary.
            while (dateCounter.Day > 1)
            {
                string currentPrefix = logDirectory.Prefix + dateCounter.ToString("yyyy/MM/dd", CultureInfo.InvariantCulture);
                IEnumerable<IListBlobItem> currentLogs = logDirectory.Container.ListBlobs(currentPrefix, true, metadataDetails, options, operationContext);

                foreach (ICloudBlob log in currentLogs)
                {
                    if (!utcEndTime.HasValue || string.Compare(log.Parent.Prefix, endPrefix) <= 0)
                    {
                        if (IsCorrectLogType(log, operations))
                        {
                            yield return log;
                        }
                    }
                    else
                    {
                        yield break;
                    }
                }

                dateCounter = dateCounter.AddDays(1);
                if (dateCounter > DateTimeOffset.UtcNow.AddHours(1))
                {
                    yield break;
                }
            }

            // Check logs using a month-based prefix until we reach a year boundary.
            while (dateCounter.Month > 1)
            {
                string currentPrefix = logDirectory.Prefix + dateCounter.ToString("yyyy/MM", CultureInfo.InvariantCulture);
                IEnumerable<IListBlobItem> currentLogs = logDirectory.Container.ListBlobs(currentPrefix, true, metadataDetails, options, operationContext);

                foreach (ICloudBlob log in currentLogs)
                {
                    if (!utcEndTime.HasValue || string.Compare(log.Parent.Prefix, endPrefix) <= 0)
                    {
                        if (IsCorrectLogType(log, operations))
                        {
                            yield return log;
                        }
                    }
                    else
                    {
                        yield break;
                    }
                }

                dateCounter = dateCounter.AddMonths(1);
                if (dateCounter > DateTimeOffset.UtcNow.AddHours(1))
                {
                    yield break;
                }
            }

            // Continue using a year-based prefix. 
            while (true)
            {
                string currentPrefix = logDirectory.Prefix + dateCounter.ToString("yyyy", CultureInfo.InvariantCulture);
                IEnumerable<IListBlobItem> currentLogs = logDirectory.Container.ListBlobs(currentPrefix, true, metadataDetails, options, operationContext);

                foreach (ICloudBlob log in currentLogs)
                {
                    if (!utcEndTime.HasValue || string.Compare(log.Parent.Prefix, endPrefix) <= 0)
                    {
                        if (IsCorrectLogType(log, operations))
                        {
                            yield return log;
                        }
                    }
                    else
                    {
                        yield break;
                    }
                }

                dateCounter = dateCounter.AddYears(1);
                if (dateCounter > DateTimeOffset.UtcNow.AddHours(1))
                { 
                    yield break;
                }
            }
        }
 /// <summary>
 /// List all blobs in specified containers
 /// </summary>
 /// <param name="container">A cloudblobcontainer object</param>
 /// <param name="prefix">Blob prefix</param>
 /// <param name="useFlatBlobListing">Use flat blob listing(whether treat "container/" as directory)</param>
 /// <param name="blobListingDetails">Blob listing details</param>
 /// <param name="options">Blob request option</param>
 /// <param name="operationContext">Operation context</param>
 /// <returns>An enumerable collection of icloudblob</returns>
 public IEnumerable<IListBlobItem> ListBlobs(CloudBlobContainer container, string prefix, bool useFlatBlobListing, BlobListingDetails blobListingDetails, BlobRequestOptions options, OperationContext operationContext)
 {
     return container.ListBlobs(prefix, useFlatBlobListing, blobListingDetails, options, operationContext);
 }
Пример #24
0
 /// <summary>
 /// List the blobs segmented in specified containers
 /// </summary>
 /// <param name="container">A cloudblobcontainer object</param>
 /// <param name="prefix">Blob prefix</param>
 /// <param name="useFlatBlobListing">Use flat blob listing(whether treat "container/" as directory)</param>
 /// <param name="blobListingDetails">Blob listing details</param>
 /// <param name="options">Blob request option</param>
 /// <param name="operationContext">Operation context</param>
 public Task <BlobResultSegment> ListBlobsSegmentedAsync(CloudBlobContainer container, string prefix, bool useFlatBlobListing, BlobListingDetails blobListingDetails, int?maxResults, BlobContinuationToken currentToken, BlobRequestOptions options, OperationContext operationContext, CancellationToken cancellationToken)
 {
     //BlobResultSegment is sealed without any public constructors.
     throw new NotImplementedException();
 }
Пример #25
0
        /// <summary>
        /// List all blobs in specified containers
        /// </summary>
        /// <param name="container">A cloudblobcontainer object</param>
        /// <param name="prefix">Blob prefix</param>
        /// <param name="useFlatBlobListing">Use flat blob listing(whether treat "container/" as directory)</param>
        /// <param name="blobListingDetails">Blob listing details</param>
        /// <param name="options">Blob request option</param>
        /// <param name="operationContext">Operation context</param>
        /// <returns>An enumerable collection of icloudblob</returns>
        public IEnumerable <IListBlobItem> ListBlobs(CloudBlobContainer container, string prefix, bool useFlatBlobListing, BlobListingDetails blobListingDetails, BlobRequestOptions options, OperationContext operationContext)
        {
            string containerName = container.Name;

            if (ContainerBlobs.ContainsKey(containerName))
            {
                List <ICloudBlob> blobList = ContainerBlobs[containerName];

                if (string.IsNullOrEmpty(prefix))
                {
                    return(blobList);
                }

                List <ICloudBlob> prefixBlobs = new List <ICloudBlob>();

                foreach (ICloudBlob blob in blobList)
                {
                    if (blob.Name.StartsWith(prefix))
                    {
                        prefixBlobs.Add(blob);
                    }
                }

                return(prefixBlobs);
            }
            else
            {
                return(new List <ICloudBlob>());
            }
        }
Пример #26
0
 public async Task <IAzureBlobResultSegment> ListBlobsSegmentedAsync(string prefix, BlobListing blobListing, BlobListingDetails blobListingDetails, int?maxResults, BlobContinuationToken currentToken)
 {
     return(new HostedAzureBlobResultSegment(await _cloudBlobContainer.ListBlobsSegmentedAsync(
                                                 prefix,
                                                 blobListing == BlobListing.Flat,
                                                 blobListingDetails,
                                                 maxResults,
                                                 currentToken,
                                                 null,
                                                 null)));
 }
Пример #27
0
 public Task <BlobResultSegment> ListBlobsSegmentedAsync(string prefix, bool useFlatBlobListing, BlobListingDetails blobListingDetails, int?maxResults, BlobContinuationToken currentToken, BlobRequestOptions options, OperationContext operationContext)
Пример #28
0
 public virtual IEnumerable <IListBlobItem> ListBlobs(bool useFlatBlobListing = false, BlobListingDetails blobListingDetails = BlobListingDetails.None, BlobRequestOptions options = null, OperationContext operationContext = null)
 {
     return(this.Container.ListBlobs(this.Prefix, useFlatBlobListing, blobListingDetails, options, operationContext));
 }
Пример #29
0
 public virtual BlobResultSegment ListBlobsSegmented(bool useFlatBlobListing, BlobListingDetails blobListingDetails, int?maxResults, BlobContinuationToken currentToken, BlobRequestOptions options, OperationContext operationContext)
 {
     return(this.Container.ListBlobsSegmented(this.Prefix, useFlatBlobListing, blobListingDetails, maxResults, currentToken, options, operationContext));
 }
Пример #30
0
 public virtual Task <BlobResultSegment> ListBlobsSegmentedAsync(bool useFlatBlobListing, BlobListingDetails blobListingDetails, int?maxResults, BlobContinuationToken currentToken, BlobRequestOptions options, OperationContext operationContext, CancellationToken cancellationToken)
 {
     return(this.Container.ListBlobsSegmentedAsync(this.Prefix, useFlatBlobListing, blobListingDetails, maxResults, currentToken, options, operationContext, cancellationToken));
 }
Пример #31
0
 public virtual ICancellableAsyncResult BeginListBlobsSegmented(bool useFlatBlobListing, BlobListingDetails blobListingDetails, int?maxResults, BlobContinuationToken currentToken, BlobRequestOptions options, OperationContext operationContext, AsyncCallback callback, object state)
 {
     return(CancellableAsyncResultTaskWrapper.Create(token => this.ListBlobsSegmentedAsync(useFlatBlobListing, blobListingDetails, maxResults, currentToken, options, operationContext, token), callback, state));
 }
Пример #32
0
        /// <summary>
        /// Returns an enumerable collection of log blobs containing Analytics log records. The blobs are retrieved lazily.
        /// </summary>
        /// <param name="service">A <see cref="StorageService"/> enumeration value.</param>
        /// <param name="startTime">A <see cref="DateTimeOffset"/> object representing the start of the time range for which logs should be retrieved.</param>
        /// <param name="endTime">A <see cref="DateTimeOffset"/> object representing the end of the time range for which logs should be retrieved.</param>
        /// <param name="operations">A <see cref="LoggingOperations"/> enumeration value that indicates the types of logging operations on which to filter the log blobs.</param>
        /// <param name="details">A <see cref="BlobListingDetails"/> enumeration value that indicates whether or not blob metadata should be returned. Only <c>None</c> and <c>Metadata</c> are valid values. </param>
        /// <param name="options">A <see cref="BlobRequestOptions"/> object that specifies additional options for the request.</param>
        /// <param name="operationContext">An <see cref="OperationContext"/> object that represents the context for the current operation.</param>
        /// <returns>An enumerable collection of objects that implement <see cref="ICloudBlob"/> and are retrieved lazily.</returns>
        /// <remarks>Note that specifying a logging operation type for the <paramref name="operations"/> parameter will return any Analytics log blob that contains the specified logging operation,
        /// even if that log blob also includes other types of logging operations. Also note that the only currently supported values for the <paramref name="details"/>
        /// parameter are <c>None</c> and <c>Metadata</c>.</remarks>
        public IEnumerable <ICloudBlob> ListLogs(StorageService service, DateTimeOffset startTime, DateTimeOffset?endTime, LoggingOperations operations, BlobListingDetails details, BlobRequestOptions options, OperationContext operationContext)
        {
            CloudBlobDirectory logDirectory    = this.GetLogDirectory(service);
            BlobListingDetails metadataDetails = details;
            DateTimeOffset     utcStartTime    = startTime.ToUniversalTime();
            DateTimeOffset     dateCounter     = new DateTimeOffset(utcStartTime.Ticks - (utcStartTime.Ticks % TimeSpan.TicksPerHour), utcStartTime.Offset);
            DateTimeOffset?    utcEndTime      = null;
            string             endPrefix       = null;

            // Ensure that the date range is correct.
            if (endTime.HasValue)
            {
                utcEndTime = endTime.Value.ToUniversalTime();
                endPrefix  = logDirectory.Prefix + utcEndTime.Value.ToString("yyyy/MM/dd/HH", CultureInfo.InvariantCulture);
                if (utcStartTime > utcEndTime.Value)
                {
                    string errorString = string.Format(CultureInfo.InvariantCulture, SR.StartTimeExceedsEndTime, startTime, endTime.Value);
                    throw new ArgumentException(errorString);
                }
            }

            // Currently only support the ability to retrieve metadata on logs.
            if (details.HasFlag(BlobListingDetails.Copy) || details.HasFlag(BlobListingDetails.Snapshots) || details.HasFlag(BlobListingDetails.UncommittedBlobs))
            {
                throw new ArgumentException(SR.InvalidListingDetails);
            }

            // At least one LogType must be specified.
            if (operations == LoggingOperations.None)
            {
                throw new ArgumentException(SR.InvalidLoggingLevel);
            }

            // If metadata or a specific LogType is specified, metadata should be retrieved.
            if (details.HasFlag(BlobListingDetails.Metadata) || !operations.HasFlag(LoggingOperations.All))
            {
                metadataDetails = BlobListingDetails.Metadata;
            }

            // Check logs using an hour-based prefix until we reach a day boundary.
            while (dateCounter.Hour > 0)
            {
                string currentPrefix = logDirectory.Prefix + dateCounter.ToString("yyyy/MM/dd/HH", CultureInfo.InvariantCulture);
                IEnumerable <IListBlobItem> currentLogs = logDirectory.Container.ListBlobs(currentPrefix, true, metadataDetails, options, operationContext);

                foreach (ICloudBlob log in currentLogs)
                {
                    if (!utcEndTime.HasValue || string.Compare(log.Parent.Prefix, endPrefix) <= 0)
                    {
                        if (IsCorrectLogType(log, operations))
                        {
                            yield return(log);
                        }
                    }
                    else
                    {
                        yield break;
                    }
                }

                dateCounter = dateCounter.AddHours(1);
                if (dateCounter > DateTimeOffset.UtcNow.AddHours(1))
                {
                    yield break;
                }
            }

            // Check logs using a day-based prefix until we reach a month boundary.
            while (dateCounter.Day > 1)
            {
                string currentPrefix = logDirectory.Prefix + dateCounter.ToString("yyyy/MM/dd", CultureInfo.InvariantCulture);
                IEnumerable <IListBlobItem> currentLogs = logDirectory.Container.ListBlobs(currentPrefix, true, metadataDetails, options, operationContext);

                foreach (ICloudBlob log in currentLogs)
                {
                    if (!utcEndTime.HasValue || string.Compare(log.Parent.Prefix, endPrefix) <= 0)
                    {
                        if (IsCorrectLogType(log, operations))
                        {
                            yield return(log);
                        }
                    }
                    else
                    {
                        yield break;
                    }
                }

                dateCounter = dateCounter.AddDays(1);
                if (dateCounter > DateTimeOffset.UtcNow.AddHours(1))
                {
                    yield break;
                }
            }

            // Check logs using a month-based prefix until we reach a year boundary.
            while (dateCounter.Month > 1)
            {
                string currentPrefix = logDirectory.Prefix + dateCounter.ToString("yyyy/MM", CultureInfo.InvariantCulture);
                IEnumerable <IListBlobItem> currentLogs = logDirectory.Container.ListBlobs(currentPrefix, true, metadataDetails, options, operationContext);

                foreach (ICloudBlob log in currentLogs)
                {
                    if (!utcEndTime.HasValue || string.Compare(log.Parent.Prefix, endPrefix) <= 0)
                    {
                        if (IsCorrectLogType(log, operations))
                        {
                            yield return(log);
                        }
                    }
                    else
                    {
                        yield break;
                    }
                }

                dateCounter = dateCounter.AddMonths(1);
                if (dateCounter > DateTimeOffset.UtcNow.AddHours(1))
                {
                    yield break;
                }
            }

            // Continue using a year-based prefix.
            while (true)
            {
                string currentPrefix = logDirectory.Prefix + dateCounter.ToString("yyyy", CultureInfo.InvariantCulture);
                IEnumerable <IListBlobItem> currentLogs = logDirectory.Container.ListBlobs(currentPrefix, true, metadataDetails, options, operationContext);

                foreach (ICloudBlob log in currentLogs)
                {
                    if (!utcEndTime.HasValue || string.Compare(log.Parent.Prefix, endPrefix) <= 0)
                    {
                        if (IsCorrectLogType(log, operations))
                        {
                            yield return(log);
                        }
                    }
                    else
                    {
                        yield break;
                    }
                }

                dateCounter = dateCounter.AddYears(1);
                if (dateCounter > DateTimeOffset.UtcNow.AddHours(1))
                {
                    yield break;
                }
            }
        }
Пример #33
0
        public ICancellableAsyncResult BeginListBlobsSegmented(string prefix, bool useFlatBlobListing, BlobListingDetails blobListingDetails, int? maxResults, BlobContinuationToken currentToken, BlobRequestOptions options, OperationContext operationContext, AsyncCallback callback, object state)
        {
            string containerName;
            string listingPrefix;
            CloudBlobClient.ParseUserPrefix(prefix, out containerName, out listingPrefix);

            CloudBlobContainer container = this.GetContainerReference(containerName);
            ChainedAsyncResult<BlobResultSegment> result = new ChainedAsyncResult<BlobResultSegment>(callback, state);
            ICancellableAsyncResult asyncResult = container.BeginListBlobsSegmented(
                listingPrefix,
                useFlatBlobListing,
                blobListingDetails,
                maxResults,
                currentToken,
                options,
                operationContext,
                ar =>
                {
                    result.UpdateCompletedSynchronously(ar.CompletedSynchronously);

                    try
                    {
                        result.Result = container.EndListBlobsSegmented(ar);
                        result.OnComplete();
                    }
                    catch (Exception e)
                    {
                        result.OnComplete(e);
                    }
                },
                null /* state */);

            result.CancelDelegate = asyncResult.Cancel;
            return result;
        }
        public async Task <List <IListBlobItem> > ListBlobsAsync(string prefix, bool useFlatBlobListing, BlobListingDetails blobListingDetails, CancellationToken cancellationToken)
        {
            BlobContinuationToken continuationToken = null;
            var results = new List <IListBlobItem>();

            do
            {
                var response = await Container.ListBlobsSegmentedAsync(prefix, useFlatBlobListing, blobListingDetails,
                                                                       maxResults : null,
                                                                       currentToken : continuationToken,
                                                                       options : null,
                                                                       operationContext : null,
                                                                       cancellationToken : cancellationToken);

                continuationToken = response.ContinuationToken;
                results.AddRange(response.Results);
            } while (continuationToken != null);

            return(results);
        }
Пример #35
0
        /// <summary>
        /// Returns an enumerable collection of log blobs containing Analytics log records. The blobs are retrieved lazily.
        /// </summary>
        /// <param name="service">A <see cref="StorageService"/> enumeration value.</param>
        /// <param name="operations">A <see cref="LoggingOperations"/> enumeration value that indicates the types of logging operations on which to filter the log blobs.</param>
        /// <param name="details">A <see cref="BlobListingDetails"/> enumeration value that indicates whether or not blob metadata should be returned. Only <c>None</c> and <c>Metadata</c> are valid values. </param>
        /// <param name="options">A <see cref="BlobRequestOptions"/> object that specifies additional options for the request.</param>
        /// <param name="operationContext">An <see cref="OperationContext"/> object that represents the context for the current operation.</param>
        /// <returns>An enumerable collection of objects that implement <see cref="ICloudBlob"/> and are retrieved lazily.</returns>
        /// <remarks>Note that specifying a logging operation type for the <paramref name="operations"/> parameter will return any Analytics log blob that contains the specified logging operation,
        /// even if that log blob also includes other types of logging operations. Also note that the only currently supported values for the <paramref name="details"/>
        /// parameter are <c>None</c> and <c>Metadata</c>.</remarks>
        public IEnumerable <ICloudBlob> ListLogs(StorageService service, LoggingOperations operations, BlobListingDetails details, BlobRequestOptions options, OperationContext operationContext)
        {
            BlobListingDetails metadataDetails = BlobListingDetails.None;

            // Currently only support the ability to retrieve metadata on logs.
            if (details.HasFlag(BlobListingDetails.Copy) || details.HasFlag(BlobListingDetails.Snapshots) || details.HasFlag(BlobListingDetails.UncommittedBlobs))
            {
                throw new ArgumentException(SR.InvalidListingDetails);
            }

            // At least one LogType must be specified.
            if (operations == LoggingOperations.None)
            {
                throw new ArgumentException(SR.InvalidLoggingLevel);
            }

            if (details.HasFlag(BlobListingDetails.Metadata) || !operations.HasFlag(LoggingOperations.All))
            {
                metadataDetails = BlobListingDetails.Metadata;
            }

            IEnumerable <IListBlobItem> logs = this.GetLogDirectory(service).ListBlobs(true, metadataDetails, options, operationContext);

            return(logs.Select(log => (ICloudBlob)log).Where(log => IsCorrectLogType(log, operations)));
        }
Пример #36
0
        public async Task ContainerWillNotLoadMetadataIfNotSpecifiedForHierarchicalListing(BlobListingDetails blobListingDetails)
        {
            var results = await new StandaloneAzureBlobContainer(BasePath)
                          .ListBlobsSegmentedAsync(
                "",
                BlobListing.Hierarchical,
                blobListingDetails,
                null,
                null);

            Assert.Empty(results.Results.OfType <IAzureBlockBlob>().First(r => r.Name == "flat").Metadata);
        }
Пример #37
0
 /// <summary>
 /// List part of blobs.
 /// </summary>
 /// <param name="prefix">Blob prefix</param>
 /// <param name="useFlatBlobListing">Use flat blob listing</param>
 /// <param name="blobListingDetails">Blob listing details.</param>
 /// <param name="maxResults">Max results.</param>
 /// <param name="currentToken">Current token.</param>
 /// <param name="options">Request options</param>
 /// <param name="operationContext">Operation Context.</param>
 /// <returns>BlobResultSegment object</returns>
 public BlobResultSegment ListBlobsSegmented(CloudBlobContainer container, string prefix, bool useFlatBlobListing, BlobListingDetails blobListingDetails, int?maxResults, BlobContinuationToken currentToken, BlobRequestOptions options, OperationContext operationContext)
 {
     throw new NotImplementedException("Can not create a BlobResultSegment object");
 }
 /// List part of blobs.
 /// </summary>
 /// <param name="prefix">Blob prefix</param>
 /// <param name="useFlatBlobListing">Use flat blob listing</param>
 /// <param name="blobListingDetails">Blob listing details.</param>
 /// <param name="maxResults">Max results.</param>
 /// <param name="currentToken">Current token.</param>
 /// <param name="options">Request options</param>
 /// <param name="operationContext">Operation Context.</param>
 /// <returns>BlobResultSegment object</returns>
 public BlobResultSegment ListBlobsSegmented(CloudBlobContainer container, string prefix, bool useFlatBlobListing,
                                             BlobListingDetails blobListingDetails, int?maxResults, BlobContinuationToken currentToken, BlobRequestOptions options, OperationContext operationContext)
 {
     return(container.ListBlobsSegmentedAsync(prefix, useFlatBlobListing, blobListingDetails, maxResults, currentToken, options, operationContext).Result);
 }
        /// <summary>
        /// Returns an enumerable collection of log blobs containing Analytics log records. The blobs are retrieved lazily.
        /// </summary>
        /// <param name="service">A <see cref="StorageService"/> enumeration value.</param>
        /// <param name="operations">A <see cref="LoggingOperations"/> enumeration value that indicates the types of logging operations on which to filter the log blobs.</param>
        /// <param name="details">A <see cref="BlobListingDetails"/> enumeration value that indicates whether or not blob metadata should be returned. Only <c>None</c> and <c>Metadata</c> are valid values. </param>
        /// <param name="options">A <see cref="BlobRequestOptions"/> object that specifies additional options for the request.</param>
        /// <param name="operationContext">An <see cref="OperationContext"/> object that represents the context for the current operation.</param>
        /// <returns>An enumerable collection of objects that implement <see cref="ICloudBlob"/> and are retrieved lazily.</returns>
        /// <remarks>Note that specifying a logging operation type for the <paramref name="operations"/> parameter will return any Analytics log blob that contains the specified logging operation,
        /// even if that log blob also includes other types of logging operations. Also note that the only currently supported values for the <paramref name="details"/> 
        /// parameter are <c>None</c> and <c>Metadata</c>.</remarks>
        public IEnumerable<ICloudBlob> ListLogs(StorageService service, LoggingOperations operations, BlobListingDetails details, BlobRequestOptions options, OperationContext operationContext)
        {
            BlobListingDetails metadataDetails = BlobListingDetails.None;

            // Currently only support the ability to retrieve metadata on logs.
            if (details.HasFlag(BlobListingDetails.Copy) || details.HasFlag(BlobListingDetails.Snapshots) || details.HasFlag(BlobListingDetails.UncommittedBlobs))
            {
                throw new ArgumentException(SR.InvalidListingDetails);
            }

            // At least one LogType must be specified.
            if (operations == LoggingOperations.None)
            {
                throw new ArgumentException(SR.InvalidLoggingLevel);
            }

            if (details.HasFlag(BlobListingDetails.Metadata) || !operations.HasFlag(LoggingOperations.All))
            {
                metadataDetails = BlobListingDetails.Metadata;
            }

            IEnumerable<IListBlobItem> logs = this.GetLogDirectory(service).ListBlobs(true, metadataDetails, options, operationContext);
            return logs.Select(log => (ICloudBlob)log).Where(log => IsCorrectLogType(log, operations));
        }
        /// <summary>
        /// List all blobs in specified containers
        /// </summary>
        /// <param name="container">A cloudblobcontainer object</param>
        /// <param name="prefix">Blob prefix</param>
        /// <param name="useFlatBlobListing">Use flat blob listing(whether treat "container/" as directory)</param>
        /// <param name="blobListingDetails">Blob listing details</param>
        /// <param name="options">Blob request option</param>
        /// <param name="operationContext">Operation context</param>
        /// <returns>An enumerable collection of CloudBlob</returns>
        public IEnumerable <IListBlobItem> ListBlobs(CloudBlobContainer container, string prefix, bool useFlatBlobListing, BlobListingDetails blobListingDetails, BlobRequestOptions options, OperationContext operationContext)
        {
            //https://ahmet.im/blog/azure-listblobssegmentedasync-listcontainerssegmentedasync-how-to/
            BlobContinuationToken continuationToken = null;
            var results = new List <IListBlobItem>();

            do
            {
                var response = container.ListBlobsSegmentedAsync(prefix, useFlatBlobListing, blobListingDetails, null, continuationToken, options, operationContext).Result;
                continuationToken = response.ContinuationToken;
                results.AddRange(response.Results);
            } while (continuationToken != null);
            return(results);
        }
        /// <summary>
        /// List all blobs in specified containers
        /// </summary>
        /// <param name="container">A cloudblobcontainer object</param>
        /// <param name="prefix">Blob prefix</param>
        /// <param name="useFlatBlobListing">Use flat blob listing(whether treat "container/" as directory)</param>
        /// <param name="blobListingDetails">Blob listing details</param>
        /// <param name="options">Blob request option</param>
        /// <param name="operationContext">Operation context</param>
        /// <returns>An enumerable collection of icloudblob</returns>
        public IEnumerable<IListBlobItem> ListBlobs(CloudBlobContainer container, string prefix, bool useFlatBlobListing, BlobListingDetails blobListingDetails, BlobRequestOptions options, OperationContext operationContext)
        {
            string containerName = container.Name;

            if (ContainerBlobs.ContainsKey(containerName))
            {
                List<ICloudBlob> blobList = ContainerBlobs[containerName];

                if (string.IsNullOrEmpty(prefix))
                {
                    return blobList;
                }

                List<ICloudBlob> prefixBlobs = new List<ICloudBlob>();

                foreach (ICloudBlob blob in blobList)
                {
                    if (blob.Name.StartsWith(prefix))
                    {
                        prefixBlobs.Add(blob);
                    }
                }

                return prefixBlobs;
            }
            else
            {
                return new List<ICloudBlob>();
            }
        }
 /// <summary>
 /// List all blobs in specified containers
 /// </summary>
 /// <param name="container">A cloudblobcontainer object</param>
 /// <param name="prefix">Blob prefix</param>
 /// <param name="useFlatBlobListing">Use flat blob listing(whether treat "container/" as directory)</param>
 /// <param name="blobListingDetails">Blob listing details</param>
 /// <param name="options">Blob request option</param>
 /// <param name="operationContext">Operation context</param>
 /// <returns>An enumerable collection of CloudBlob</returns>
 public IEnumerable <IListBlobItem> ListBlobs(CloudBlobContainer container, string prefix, bool useFlatBlobListing, BlobListingDetails blobListingDetails, BlobRequestOptions options, OperationContext operationContext)
 {
     return(container.ListBlobs(prefix, useFlatBlobListing, blobListingDetails, options, operationContext));
 }
 /// <summary>
 /// List the blobs segmented in specified containers
 /// </summary>
 /// <param name="container">A cloudblobcontainer object</param>
 /// <param name="prefix">Blob prefix</param>
 /// <param name="useFlatBlobListing">Use flat blob listing(whether treat "container/" as directory)</param>
 /// <param name="blobListingDetails">Blob listing details</param>
 /// <param name="options">Blob request option</param>
 /// <param name="operationContext">Operation context</param>
 public Task<BlobResultSegment> ListBlobsSegmentedAsync(CloudBlobContainer container, string prefix, bool useFlatBlobListing, BlobListingDetails blobListingDetails, int? maxResults, BlobContinuationToken currentToken, BlobRequestOptions options, OperationContext operationContext, CancellationToken cancellationToken)
 {
     return container.ListBlobsSegmentedAsync(prefix, useFlatBlobListing, blobListingDetails, maxResults, currentToken, options, operationContext, cancellationToken);
 }
Пример #44
0
        protected static async Task <List <T> > GetBlobs <T>(string containerName, string prefix = "", int?maxresultsPerQuery = null, BlobListingDetails blobListingDetails = BlobListingDetails.None) where T : ICloudBlob
        {
            var blobContainer = GetBlobContainer(containerName);

            var blobList = new List <T>();
            BlobContinuationToken continuationToken = null;

            try
            {
                do
                {
                    var response = await blobContainer.ListBlobsSegmentedAsync(prefix,
                                                                               true,
                                                                               blobListingDetails,
                                                                               maxresultsPerQuery,
                                                                               continuationToken,
                                                                               null,
                                                                               null).ConfigureAwait(false);

                    continuationToken = response?.ContinuationToken;

                    foreach (var blob in response?.Results?.OfType <T>())
                    {
                        blobList.Add(blob);
                    }
                } while (continuationToken != null);
            }
            catch (Exception e)
            {
                DebugServices.Log(e);
            }

            return(blobList);
        }
 public Task<BlobResultSegment> ListBlobsSegmentedAsync(string prefix, bool useFlatBlobListing, BlobListingDetails blobListingDetails, int? maxResults, BlobContinuationToken currentToken, BlobRequestOptions options, OperationContext operationContext)
Пример #46
0
        public IAsyncOperation <BlobResultSegment> ListBlobsSegmentedAsync(string prefix, bool useFlatBlobListing, BlobListingDetails blobListingDetails, int?maxResults, BlobContinuationToken currentToken, BlobRequestOptions options, OperationContext operationContext)
#endif
        {
            string containerName;
            string listingPrefix;

            CloudBlobClient.ParseUserPrefix(prefix, out containerName, out listingPrefix);

            CloudBlobContainer container = this.GetContainerReference(containerName);

            return(container.ListBlobsSegmentedAsync(listingPrefix, useFlatBlobListing, blobListingDetails, maxResults, currentToken, options, operationContext));
        }
        public IAsyncOperation<BlobResultSegment> ListBlobsSegmentedAsync(string prefix, bool useFlatBlobListing, BlobListingDetails blobListingDetails, int? maxResults, BlobContinuationToken currentToken, BlobRequestOptions options, OperationContext operationContext)
        {
            BlobRequestOptions modifiedOptions = BlobRequestOptions.ApplyDefaults(options, BlobType.Unspecified, this.ServiceClient);
            return AsyncInfo.Run(async (token) =>
            {
                ResultSegment<IListBlobItem> resultSegment = await Executor.ExecuteAsync(
                    this.ListBlobsImpl(prefix, maxResults, useFlatBlobListing, blobListingDetails, modifiedOptions, currentToken),
                    modifiedOptions.RetryPolicy,
                    operationContext,
                    token);

                return new BlobResultSegment(resultSegment.Results, (BlobContinuationToken)resultSegment.ContinuationToken);
            });
        }
Пример #48
0
 public IEnumerable <IListBlobItem> ListBlobs(string prefix, bool useFlatBlobListing = false, BlobListingDetails blobListingDetails = BlobListingDetails.None,
                                              BlobRequestOptions options             = null, OperationContext operationContext = null)
 {
     throw new NotImplementedException();
 }
Пример #49
0
        public BlobResultSegment ListBlobsSegmented(string prefix, bool useFlatBlobListing, BlobListingDetails blobListingDetails, int? maxResults, BlobContinuationToken currentToken, BlobRequestOptions options, OperationContext operationContext)
        {
            string containerName;
            string listingPrefix;
            CloudBlobClient.ParseUserPrefix(prefix, out containerName, out listingPrefix);

            CloudBlobContainer container = this.GetContainerReference(containerName);
            return container.ListBlobsSegmented(listingPrefix, useFlatBlobListing, blobListingDetails, maxResults, currentToken, options, operationContext);
        }
Пример #50
0
 public BlobResultSegment ListBlobsSegmented(string prefix, bool useFlatBlobListing, BlobListingDetails blobListingDetails,
                                             int?maxResults, BlobContinuationToken currentToken, BlobRequestOptions options,
                                             OperationContext operationContext)
 {
     throw new NotImplementedException();
 }
Пример #51
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BlobListingContext"/> class.
 /// </summary>
 /// <param name="prefix">The blob prefix.</param>
 /// <param name="maxResults">The maximum number of results to return.</param>
 /// <param name="delimiter">The blob delimiter.</param>
 /// <param name="details">The include parameter.</param>
 public BlobListingContext(string prefix, int?maxResults, string delimiter, BlobListingDetails details)
     : base(prefix, maxResults)
 {
     this.Delimiter = delimiter;
     this.Details   = details;
 }
Пример #52
0
        public async Task DirectoryWillNotLoadMetadataIfNotSpecifiedForHierarchicalListing(BlobListingDetails blobListingDetails)
        {
            var results = await new StandaloneAzureBlobDirectory(BasePath, Path.Combine(BasePath, @"random\path"))
                          .ListBlobsSegmentedAsync(
                BlobListing.Hierarchical,
                blobListingDetails,
                null,
                null);

            Assert.Empty(results.Results.OfType <IAzureBlockBlob>().First(r => r.Name == @"random\path\blob").Metadata);
        }