/// <summary>
        /// List containers by container name prefix
        /// </summary>
        /// <param name="prefix">Container name prefix</param>
        /// <returns>An enumerable collection of cloudblobcontainer</returns>
        internal IEnumerable <Tuple <AzureStorageContainer, BlobContinuationToken> > ListContainersByPrefix(string prefix, Func <string, bool> containerFilter = null)
        {
            BlobServiceClient   blobServiceClient = Util.GetTrack2BlobServiceClient(this.Channel.StorageContext, ClientOptions);
            BlobContainerTraits traits            = BlobContainerTraits.Metadata;
            BlobContainerStates states            = BlobContainerStates.None;

            if (this.IncludeDeleted.IsPresent)
            {
                states = BlobContainerStates.Deleted;
            }
            if (!string.IsNullOrEmpty(prefix) && !NameUtil.IsValidContainerPrefix(prefix))
            {
                throw new ArgumentException(String.Format(Resources.InvalidContainerName, prefix));
            }

            int    listCount         = InternalMaxCount;
            int    MaxListCount      = 5000;
            int    requestCount      = MaxListCount;
            int    realListCount     = 0;
            string continuationToken = this.ContinuationToken is null ? null : this.ContinuationToken.NextMarker;

            do
            {
                requestCount  = Math.Min(listCount, MaxListCount);
                realListCount = 0;

                IEnumerator <Page <BlobContainerItem> > enumerator = blobServiceClient.GetBlobContainers(traits, states, prefix, this.CmdletCancellationToken)
                                                                     .AsPages(continuationToken, requestCount)
                                                                     .GetEnumerator();

                Page <BlobContainerItem> page;
                enumerator.MoveNext();
                page = enumerator.Current;

                foreach (BlobContainerItem item in page.Values)
                {
                    if (containerFilter == null || containerFilter(item.Name))
                    {
                        yield return(new Tuple <AzureStorageContainer, BlobContinuationToken>(
                                         new AzureStorageContainer(item, Channel.StorageContext, blobServiceClient),
                                         string.IsNullOrEmpty(page.ContinuationToken) ? null : new BlobContinuationToken()
                        {
                            NextMarker = page.ContinuationToken
                        }));

                        realListCount++;
                    }
                    realListCount++;
                }
                continuationToken = page.ContinuationToken;

                if (InternalMaxCount != int.MaxValue)
                {
                    listCount -= realListCount;
                }
            }while (listCount > 0 && !string.IsNullOrEmpty(continuationToken));
        }
예제 #2
0
        /// <summary>
        /// List containers by container name prefix
        /// </summary>
        /// <param name="prefix">Container name prefix</param>
        /// <returns>An enumerable collection of cloudblobcontainer</returns>
        internal IEnumerable <CloudBlobContainer> ListContainersByPrefix(string prefix)
        {
            ContainerListingDetails details        = ContainerListingDetails.Metadata;
            BlobRequestOptions      requestOptions = null;

            if (!NameUtil.IsValidContainerPrefix(prefix))
            {
                throw new ArgumentException(String.Format(Resources.InvalidContainerName, prefix));
            }

            IEnumerable <CloudBlobContainer> containers = Channel.ListContainers(prefix, details, requestOptions, OperationContext);

            return(containers);
        }
        /// <summary>
        /// List containers by container name prefix
        /// </summary>
        /// <param name="prefix">Container name prefix</param>
        /// <returns>An enumerable collection of cloudblobcontainer</returns>
        internal IEnumerable <Tuple <CloudBlobContainer, BlobContinuationToken> > ListContainersByPrefix(string prefix, Func <CloudBlobContainer, bool> containerFilter = null)
        {
            ContainerListingDetails details        = ContainerListingDetails.Metadata;
            BlobRequestOptions      requestOptions = RequestOptions;

            if (!string.IsNullOrEmpty(prefix) && !NameUtil.IsValidContainerPrefix(prefix))
            {
                throw new ArgumentException(String.Format(Resources.InvalidContainerName, prefix));
            }

            int listCount     = InternalMaxCount;
            int MaxListCount  = 5000;
            int requestCount  = MaxListCount;
            int realListCount = 0;
            BlobContinuationToken continuationToken = ContinuationToken;

            do
            {
                requestCount  = Math.Min(listCount, MaxListCount);
                realListCount = 0;

                ContainerResultSegment containerResult = Channel.ListContainersSegmented(prefix, details, requestCount, continuationToken, requestOptions, OperationContext);

                foreach (CloudBlobContainer container in containerResult.Results)
                {
                    if (containerFilter == null || containerFilter(container))
                    {
                        yield return(new Tuple <CloudBlobContainer, BlobContinuationToken>(container, containerResult.ContinuationToken));

                        realListCount++;
                    }
                }

                if (InternalMaxCount != int.MaxValue)
                {
                    listCount -= realListCount;
                }

                continuationToken = containerResult.ContinuationToken;
            }while (listCount > 0 && continuationToken != null);
        }