Exemplo n.º 1
0
        internal async Task <List <T> > ExecuteAllAsync(CancellationToken cancellationToken = default)
        {
            List <T> result = new List <T>();

            using (IDocumentQueryExecutionContext localQueryExecutionContext =
                       await TaskHelper.InlineIfPossible(() => this.CreateDocumentQueryExecutionContextAsync(false, cancellationToken), null, cancellationToken))
            {
                while (!localQueryExecutionContext.IsDone)
                {
                    DocumentFeedResponse <T> partialResult = await(dynamic) TaskHelper.InlineIfPossible(() => localQueryExecutionContext.ExecuteNextFeedResponseAsync(cancellationToken), null, cancellationToken);
                    result.AddRange(partialResult);
                }
            }

            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Retrieves an object that can iterate through the individual results of the query.
        /// </summary>
        /// <remarks>
        /// This triggers a synchronous multi-page load.
        /// </remarks>
        public IEnumerator <T> GetEnumerator()
        {
            using (IDocumentQueryExecutionContext localQueryExecutionContext =
#pragma warning disable VSTHRD002 // Avoid problematic synchronous waits
                       TaskHelper.InlineIfPossible(() => this.CreateDocumentQueryExecutionContextAsync(false, CancellationToken.None), null).Result)
#pragma warning restore VSTHRD002 // Avoid problematic synchronous waits
            {
                while (!localQueryExecutionContext.IsDone)
                {
#pragma warning disable VSTHRD002 // Avoid problematic synchronous waits
                    DocumentFeedResponse <CosmosElement> feedResponse = TaskHelper.InlineIfPossible(() => localQueryExecutionContext.ExecuteNextFeedResponseAsync(CancellationToken.None), null).Result;
#pragma warning restore VSTHRD002 // Avoid problematic synchronous waits
                    DocumentFeedResponse <T> typedFeedResponse = FeedResponseBinder.ConvertCosmosElementFeed <T>(
                        feedResponse,
                        this.resourceTypeEnum,
                        this.feedOptions.JsonSerializerSettings);
                    foreach (T item in typedFeedResponse)
                    {
                        yield return(item);
                    }
                }
            }
        }