/// <summary>
        /// Verifies whether the table exist implementation.
        /// </summary>
        /// <param name="tableName">The table name.</param>
        /// <param name="setResult">The set result.</param>
        /// <returns>A sequence of tasks to do the operation.</returns>
        private TaskSequence DoesTableExistImpl(string tableName, Action <bool> setResult)
        {
            CommonUtils.CheckStringParameter(tableName, false, "tableName", Protocol.Constants.TableServiceMaxStringPropertySizeInChars);
            TableServiceUtilities.CheckTableName(tableName, "tableName");

            var svc = this.GetDataServiceContext();

            var tableExistsQuery = (from table in svc.CreateQuery <TableServiceTable>(Protocol.Constants.TableServiceTablesName)
                                    where table.TableName == tableName
                                    select table).AsTableServiceQuery();

            ResultSegment <TableServiceTable> segment = null;

            while (true)
            {
                Task <ResultSegment <TableServiceTable> > tableExistsSegmentTask;

                if (segment == null)
                {
                    tableExistsSegmentTask = TaskImplHelper.GetRetryableAsyncTask <ResultSegment <TableServiceTable> >(
                        (setResultInner) => tableExistsQuery.ExecuteSegmentedImpl(null, setResultInner), RetryPolicy);
                }
                else
                {
                    tableExistsSegmentTask = TaskImplHelper.GetRetryableAsyncTask <ResultSegment <TableServiceTable> >(segment.GetNextImpl, RetryPolicy);
                }

                yield return(tableExistsSegmentTask);

                if (GetResultOrDefault(tableExistsSegmentTask, out segment))
                {
                    if (segment.Results.Any())
                    {
                        setResult(true);

                        break;
                    }
                    else
                    {
                        setResult(false);

                        break;
                    }
                }
                else
                {
                    setResult(false);

                    break;
                }
            }
        }
Exemplo n.º 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));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Executes the segmented impl.
        /// </summary>
        /// <param name="continuationToken">The continuation token.</param>
        /// <param name="setResult">The set result.</param>
        /// <returns>A <see cref="TaskSequence"/> that executes the query and returns the first segment of results.</returns>
        internal TaskSequence ExecuteSegmentedImpl(ResultContinuation continuationToken, Action <ResultSegment <TElement> > setResult)
        {
            var localQuery = this.query;

            localQuery = RewriteQueryForTakeCount(localQuery, this.pagination);

            localQuery = ApplyContinuationToQuery(continuationToken, localQuery);

            var requestTask = localQuery.ExecuteAsync();

            yield return(requestTask);

            try
            {
                var responseResult = requestTask.Result;
                var response       = responseResult as QueryOperationResponse;

                ResultContinuation newContinuationToken = this.GetTableContinuationFromResponse(response);

                List <TElement> listResult = new List <TElement>(responseResult.ToList());

                ResultSegment.CreateResultSegment <TElement>(
                    setResult,
                    listResult,
                    newContinuationToken,
                    this.pagination,
                    this.RetryPolicy,
                    (scratch, continuationArg, setResultInnerArg) => this.ExecuteSegmentedImpl(continuationArg, setResultInnerArg));
            }
            catch (InvalidOperationException ex)
            {
                var dsce = CommonUtils.FindInnerDataServiceClientException(ex);

                if (dsce == null)
                {
                    throw;
                }

                if ((HttpStatusCode)dsce.StatusCode == HttpStatusCode.NotFound)
                {
                    setResult(new ResultSegment <TElement>(new List <TElement>(), false, null, null));
                }

                throw;
            }
        }