Beispiel #1
0
        private async Task <FeedResponse <TResponse> > ExecuteNextPrivateAsync <TResponse>(CancellationToken cancellationToken)
        {
            if (this.queryExecutionContext == null)
            {
                this.queryExecutionContext = await this.CreateDocumentQueryExecutionContextAsync(true, cancellationToken);
            }
            else if (this.queryExecutionContext.IsDone)
            {
                this.queryExecutionContext.Dispose();
                this.queryExecutionContext = await this.CreateDocumentQueryExecutionContextAsync(true, cancellationToken);
            }

            FeedResponse <CosmosElement> response = await this.queryExecutionContext.ExecuteNextAsync(cancellationToken);

            FeedResponse <TResponse> typedFeedResponse = FeedResponseBinder.ConvertCosmosElementFeed <TResponse>(
                response,
                this.resourceTypeEnum,
                this.feedOptions.JsonSerializerSettings);

            if (!this.HasMoreResults && !tracedLastExecution)
            {
                DefaultTrace.TraceInformation(
                    string.Format(
                        CultureInfo.InvariantCulture,
                        "{0}, CorrelatedActivityId: {1} | Last ExecuteNextAsync with ExecuteNextAsyncMetrics: [{2}]",
                        DateTime.UtcNow.ToString("o", CultureInfo.InvariantCulture),
                        this.CorrelatedActivityId,
                        this.executeNextAysncMetrics));
                tracedLastExecution = true;
            }
            return(typedFeedResponse);
        }
Beispiel #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>
 /// <returns></returns>
 public IEnumerator <T> GetEnumerator()
 {
     using (IDocumentQueryExecutionContext localQueryExecutionContext =
                TaskHelper.InlineIfPossible(() => this.CreateDocumentQueryExecutionContextAsync(false, CancellationToken.None), null).Result)
     {
         while (!localQueryExecutionContext.IsDone)
         {
             FeedResponse <CosmosElement> feedResponse      = TaskHelper.InlineIfPossible(() => localQueryExecutionContext.ExecuteNextAsync(CancellationToken.None), null).Result;
             FeedResponse <T>             typedFeedResponse = FeedResponseBinder.ConvertCosmosElementFeed <T>(
                 feedResponse,
                 this.resourceTypeEnum,
                 this.feedOptions.JsonSerializerSettings);
             foreach (T item in typedFeedResponse)
             {
                 yield return(item);
             }
         }
     }
 }
Beispiel #3
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);
                    }
                }
            }
        }