Exemplo n.º 1
0
        /// <summary>Scans blobs in a container and invokes a callback method for each blob passing the specified criteria.</summary>
        /// <param name="container">The container with the blobs to scan.</param>
        /// <param name="callback">The method to invoke for each blob discovered in the container.</param>
        /// <param name="prefix">The case-sensitive prefix indicating the subset of blobs to find.</param>
        /// <param name="blobListingDetails">What additional blob data to retrieve during the scan.</param>
        /// <param name="blobRequestOptions">Allows you to control retry and timeout options.</param>
        /// <param name="operationContext">The context for the operation.</param>
        /// <returns>A Task which you can use to track the scan operation.</returns>
        public static async Task ScanBlobsAsync(this CloudBlobContainer container, Func <CloudBlockBlob, Task <Boolean> > callback, String prefix = null,
                                                BlobListingDetails blobListingDetails = BlobListingDetails.None, BlobRequestOptions blobRequestOptions = null, OperationContext operationContext = null)
        {
            prefix = container.Name + "/" + prefix;
            for (BlobResultSegment brs = null; brs.HasMore();)
            {
                brs = await container.ServiceClient.ListBlobsSegmentedAsync(prefix, true, blobListingDetails, null, brs.SafeContinuationToken(),
                                                                            blobRequestOptions, operationContext);

                foreach (CloudBlockBlob blob in brs.Results)
                {
                    if (await callback(blob))
                    {
                        return;                   // Callback returns true to stop
                    }
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>Returns True for a null result segment or if the result segment has more.</summary>
 /// <param name="brs">A BlobResultSegment (can be null).</param>
 /// <returns>True if brs is null or if its continuation token is not null.</returns>
 public static Boolean HasMore(this BlobResultSegment brs)
 {
     return((brs == null) ? true : (brs.SafeContinuationToken() != null));
 }