/// <summary>
        /// Returns an enumerable collection of tables segmented implementation.
        /// </summary>
        /// <param name="prefix">The prefix.</param>
        /// <param name="continuationToken">The continuation token.</param>
        /// <param name="pagination">The pagination.</param>
        /// <param name="lastResult">The last result.</param>
        /// <param name="setResult">The set result.</param>
        /// <returns>A sequence of tasks to do the operation.</returns>
        private TaskSequence ListTablesSegmentedImplCore(
            string prefix,
            ResultContinuation continuationToken,
            ResultPagination pagination,
            ResultSegment <TableServiceTable> lastResult,
            Action <ResultSegment <string> > setResult)
        {
            CommonUtils.AssertContinuationType(continuationToken, ResultContinuation.ContinuationType.Table);

            InvokeTaskSequenceTask <ResultSegment <TableServiceTable> > listTablesSegmentedTask;

            if (lastResult == null)
            {
                var svc   = this.GetDataServiceContext();
                var query = from table in svc.CreateQuery <TableServiceTable>(Protocol.Constants.TableServiceTablesName)
                            select table;

                if (prefix != string.Empty)
                {
                    // Append Max char to end  '{' is 1 + 'z' in AsciiTable
                    string uppperBound = prefix + '{';

                    query = query.Where((table) => table.TableName.CompareTo(prefix) >= 0 && table.TableName.CompareTo(uppperBound) < 0);
                }

                if (pagination.IsPagingEnabled)
                {
                    query = query.Take(pagination.GetNextRequestPageSize().Value);
                }

                var listTablesQuery = query.AsTableServiceQuery();

                listTablesSegmentedTask = new InvokeTaskSequenceTask <ResultSegment <TableServiceTable> >(
                    (setResultInner) =>
                    listTablesQuery.ExecuteSegmentedImpl(continuationToken, setResultInner));
            }
            else
            {
                listTablesSegmentedTask = new InvokeTaskSequenceTask <ResultSegment <TableServiceTable> >(lastResult.GetNextImpl);
            }

            yield return(listTablesSegmentedTask);

            if (GetResultOrDefault <ResultSegment <TableServiceTable> >(listTablesSegmentedTask, out lastResult))
            {
                setResult(new ResultSegment <string>(
                              lastResult.Results.Select((table) => table.TableName),
                              lastResult.HasMoreResults,
                              (setResultInner) =>
                              this.ListTablesSegmentedImplCore(prefix, lastResult.ContinuationToken, pagination, lastResult, setResultInner),
                              RetryPolicy)
                {
                    ContinuationToken = lastResult.ContinuationToken
                });
            }
            else
            {
                setResult(new ResultSegment <string>(new List <string>(), false, null, RetryPolicy));
            }
        }
Пример #2
0
        /// <summary>
        /// Lists the queues impl core.
        /// </summary>
        /// <param name="prefix">The prefix.</param>
        /// <param name="detailsIncluded">The details included.</param>
        /// <param name="continuationToken">The continuation token.</param>
        /// <param name="pagination">The pagination.</param>
        /// <param name="setResult">The set result.</param>
        /// <returns>A <see cref="TaskSequence"/> for listing the queues.</returns>
        private TaskSequence ListQueuesImplCore(
            string prefix,
            QueueListingDetails detailsIncluded,
            ResultContinuation continuationToken,
            ResultPagination pagination,
            Action <ResultSegment <CloudQueue> > setResult)
        {
            CommonUtils.AssertContinuationType(continuationToken, ResultContinuation.ContinuationType.Queue);

            ListingContext listingContext = new ListingContext(prefix, pagination.GetNextRequestPageSize())
            {
                Marker = continuationToken != null ? continuationToken.NextMarker : null
            };

            var queueList = new List <CloudQueue>();

            var webRequest = QueueRequest.List(this.BaseUri, this.Timeout.RoundUpToSeconds(), listingContext, detailsIncluded);

            this.Credentials.SignRequest(webRequest);

            var listTask = webRequest.GetResponseAsyncWithTimeout(this, this.Timeout);

            yield return(listTask);

            string nextMarker;

            using (var response = listTask.Result as HttpWebResponse)
            {
                var parsedResponse = QueueResponse.List(response);

                // Materialize the results so that we can close the response
                queueList.AddRange(parsedResponse.Queues.Select((Func <QueueEntry, CloudQueue>) this.SelectResponse));

                nextMarker = parsedResponse.NextMarker;
            }

            ResultContinuation newContinuationToken = new ResultContinuation()
            {
                NextMarker = nextMarker, Type = ResultContinuation.ContinuationType.Queue
            };

            ResultSegment.CreateResultSegment(
                setResult,
                queueList,
                newContinuationToken,
                pagination,
                this.RetryPolicy,
                (paginationArg, continuationArg, resultSegment) =>
                this.ListQueuesImplCore(prefix, detailsIncluded, continuationArg, paginationArg, resultSegment));
        }
Пример #3
0
        /// <summary>
        /// Rewrites the query for take count.
        /// </summary>
        /// <param name="localQuery">The local query.</param>
        /// <param name="pagination">The pagination.</param>
        /// <returns>The rewritten query.</returns>
        private static DataServiceQuery <TElement> RewriteQueryForTakeCount(DataServiceQuery <TElement> localQuery, ResultPagination pagination)
        {
            int?nextRequestPageSize = pagination.GetNextRequestPageSize();

            if (pagination.IsPagingEnabled &&
                ((nextRequestPageSize != pagination.EffectivePageSize) ||
                 pagination.EffectivePageSize > TableServiceMaxResults))
            {
                var expression             = localQuery.Expression as MethodCallExpression;
                var adjustedTakeExpression = Expression.Call(
                    expression.Object,
                    expression.Method,
                    expression.Arguments[0],
                    Expression.Constant(Math.Min(nextRequestPageSize.Value, TableServiceMaxResults)));

                return(localQuery.Provider.CreateQuery <TElement>(adjustedTakeExpression) as DataServiceQuery <TElement>);
            }

            return(localQuery);
        }
        /// <summary>
        /// Core implementation of the ListBlobs method.
        /// </summary>
        /// <param name="prefix">The blob prefix.</param>
        /// <param name="options">An object that specifies any additional options for the request.</param>
        /// <param name="continuationToken">The continuation token.</param>
        /// <param name="pagination">The pagination.</param>
        /// <param name="setResult">The result report delegate.</param>
        /// <returns>A <see cref="TaskSequence"/> that lists the blobs.</returns>
        private TaskSequence ListBlobsImplCore(
            string prefix,
            BlobRequestOptions options,
            ResultContinuation continuationToken,
            ResultPagination pagination,
            Action<ResultSegment<IListBlobItem>> setResult)
        {
            CommonUtils.AssertContinuationType(continuationToken, ResultContinuation.ContinuationType.Blob);
            CommonUtils.AssertNotNull("options", options);

            if (!options.UseFlatBlobListing
                && (options.BlobListingDetails & BlobListingDetails.Snapshots) == BlobListingDetails.Snapshots)
            {
                throw new ArgumentException(SR.ListSnapshotsWithDelimiterError, "options");
            }

            var delimiter = options.UseFlatBlobListing ? null : this.ServiceClient.DefaultDelimiter;

            BlobListingContext listingContext = new BlobListingContext(prefix, pagination.GetNextRequestPageSize(), delimiter, options.BlobListingDetails)
            {
                Marker = continuationToken != null ? continuationToken.NextMarker : null
            };

            var blobList = new List<IListBlobItem>();

            var request = ProtocolHelper.GetWebRequest(this.ServiceClient, options, (timeout) => BlobRequest.List(this.TransformedAddress, timeout, listingContext));
            this.ServiceClient.Credentials.SignRequest(request);
            var listTask = request.GetResponseAsyncWithTimeout(this.ServiceClient, options.Timeout);
            yield return listTask;

            string nextMarker;
            using (var response = listTask.Result as HttpWebResponse)
            {
                ListBlobsResponse listBlobResponse = BlobResponse.List(response);
                blobList.AddRange(listBlobResponse.Blobs.Select(
                    (item) => CloudBlobClient.SelectProtocolResponse(item, this.ServiceClient, this)));

                nextMarker = listBlobResponse.NextMarker;
            }

            ResultContinuation newContinuationToken = new ResultContinuation() { NextMarker = nextMarker, Type = ResultContinuation.ContinuationType.Blob };

            ResultSegment.CreateResultSegment(
                setResult,
                blobList,
                newContinuationToken,
                pagination,
                options.RetryPolicy,
                (paginationArg, continuationArg, resultSegmentArg) =>
                    this.ListBlobsImplCore(prefix, options, continuationArg, paginationArg, resultSegmentArg));
        }
Пример #5
0
        /// <summary>
        /// Core implementation for the ListContainers method.
        /// </summary>
        /// <param name="prefix">The container prefix.</param>
        /// <param name="detailsIncluded">The details included.</param>
        /// <param name="continuationToken">The continuation token.</param>
        /// <param name="pagination">The pagination.</param>
        /// <param name="setResult">The result report delegate.</param>
        /// <returns>A <see cref="TaskSequence"/> that lists the containers.</returns>
        private TaskSequence ListContainersImplCore(
            string prefix,
            ContainerListingDetails detailsIncluded,
            ResultContinuation continuationToken,
            ResultPagination pagination,
            Action<ResultSegment<CloudBlobContainer>> setResult)
        {
            CommonUtils.AssertContinuationType(continuationToken, ResultContinuation.ContinuationType.Container);

            ListingContext listingContext = new ListingContext(prefix, pagination.GetNextRequestPageSize())
            {
                Marker = continuationToken != null ? continuationToken.NextMarker : null
            };

            var containersList = new List<CloudBlobContainer>();

            var request = ContainerRequest.List(this.BaseUri, this.Timeout.RoundUpToSeconds(), listingContext, detailsIncluded);

            this.Credentials.SignRequest(request);

            var listTask = request.GetResponseAsyncWithTimeout(this, this.Timeout);

            yield return listTask;

            string nextMarker;

            using (var response = listTask.Result as HttpWebResponse)
            {
                ListContainersResponse listContainersResponse = ContainerResponse.List(response);

                containersList.AddRange(listContainersResponse.Containers.Select((item) => new CloudBlobContainer(item.Attributes, this)));

                nextMarker = listContainersResponse.NextMarker;
            }

            ResultContinuation newContinuationToken = new ResultContinuation() { NextMarker = nextMarker, Type = ResultContinuation.ContinuationType.Container };

            ResultSegment.CreateResultSegment(
                setResult,
                containersList,
                newContinuationToken,
                pagination,
                this.RetryPolicy,
                (paginationArg, continuationArg, resultSegmentArg) =>
                    this.ListContainersImplCore(
                        prefix,
                        detailsIncluded,
                        continuationArg,
                        paginationArg,
                        resultSegmentArg));
        }
        /// <summary>
        /// Lists the queues impl core.
        /// </summary>
        /// <param name="prefix">The prefix.</param>
        /// <param name="detailsIncluded">The details included.</param>
        /// <param name="continuationToken">The continuation token.</param>
        /// <param name="pagination">The pagination.</param>
        /// <param name="setResult">The set result.</param>
        /// <returns>A <see cref="TaskSequence"/> for listing the queues.</returns>
        private TaskSequence ListQueuesImplCore(
            string prefix,
            QueueListingDetails detailsIncluded,
            ResultContinuation continuationToken,
            ResultPagination pagination,
            Action<ResultSegment<CloudQueue>> setResult)
        {
            CommonUtils.AssertContinuationType(continuationToken, ResultContinuation.ContinuationType.Queue);

            ListingContext listingContext = new ListingContext(prefix, pagination.GetNextRequestPageSize())
            {
                Marker = continuationToken != null ? continuationToken.NextMarker : null
            };

            var queueList = new List<CloudQueue>();

            var webRequest = QueueRequest.List(this.BaseUri, this.Timeout.RoundUpToSeconds(), listingContext, detailsIncluded);
            this.Credentials.SignRequest(webRequest);

            var listTask = webRequest.GetResponseAsyncWithTimeout(this, this.Timeout);
            yield return listTask;

            string nextMarker;

            using (var response = listTask.Result as HttpWebResponse)
            {
                var parsedResponse = QueueResponse.List(response);

                // Materialize the results so that we can close the response
                queueList.AddRange(parsedResponse.Queues.Select((Func<QueueEntry, CloudQueue>)this.SelectResponse));

                nextMarker = parsedResponse.NextMarker;
            }

            ResultContinuation newContinuationToken = new ResultContinuation() { NextMarker = nextMarker, Type = ResultContinuation.ContinuationType.Queue };

            ResultSegment.CreateResultSegment(
                setResult,
                queueList,
                newContinuationToken,
                pagination,
                this.RetryPolicy,
                (paginationArg, continuationArg, resultSegment) =>
                    this.ListQueuesImplCore(prefix, detailsIncluded, continuationArg, paginationArg, resultSegment));
        }