internal static async Task <List <T> > QueryWithCosmosElementContinuationTokenAsync <T>( Container container, string query, QueryRequestOptions queryRequestOptions = null) { if (queryRequestOptions == null) { queryRequestOptions = new QueryRequestOptions(); } List <T> resultsFromCosmosElementContinuationToken = new List <T>(); CosmosElement continuationToken = null; do { QueryRequestOptions computeRequestOptions = queryRequestOptions.Clone(); computeRequestOptions.ExecutionEnvironment = Cosmos.Query.Core.ExecutionContext.ExecutionEnvironment.Compute; computeRequestOptions.CosmosElementContinuationToken = continuationToken; FeedIteratorInternal <T> itemQuery = (FeedIteratorInternal <T>)container.GetItemQueryIterator <T>( queryText: query, requestOptions: computeRequestOptions); try { FeedResponse <T> cosmosQueryResponse = await itemQuery.ReadNextAsync(); if (queryRequestOptions.MaxItemCount.HasValue) { Assert.IsTrue( cosmosQueryResponse.Count <= queryRequestOptions.MaxItemCount.Value, "Max Item Count is not being honored"); } resultsFromCosmosElementContinuationToken.AddRange(cosmosQueryResponse); // Force a rewrite of the continuation token, so that we test the case where we roundtrip it over the wire. // There was a bug where resuming from double.NaN lead to an exception, // since we parsed the type assuming it was always a double and not a string. CosmosElement originalContinuationToken = itemQuery.GetCosmosElementContinuationToken(); if (originalContinuationToken != null) { continuationToken = CosmosElement.Parse(originalContinuationToken.ToString()); } else { continuationToken = null; } } catch (CosmosException cosmosException) when(cosmosException.StatusCode == (HttpStatusCode)429) { itemQuery = (FeedIteratorInternal <T>)container.GetItemQueryIterator <T>( queryText: query, requestOptions: queryRequestOptions); } } while (continuationToken != null); return(resultsFromCosmosElementContinuationToken); }
internal static async Task <List <T> > QueryWithCosmosElementContinuationTokenAsync <T>( Container container, string query, QueryRequestOptions queryRequestOptions = null) { if (queryRequestOptions == null) { queryRequestOptions = new QueryRequestOptions(); } List <T> resultsFromCosmosElementContinuationToken = new List <T>(); CosmosElement continuationToken = null; do { QueryRequestOptions computeRequestOptions = queryRequestOptions.Clone(); computeRequestOptions.ExecutionEnvironment = Cosmos.Query.Core.ExecutionContext.ExecutionEnvironment.Compute; computeRequestOptions.CosmosElementContinuationToken = continuationToken; FeedIteratorInternal <T> itemQuery = (FeedIteratorInternal <T>)container.GetItemQueryIterator <T>( queryText: query, requestOptions: computeRequestOptions); try { FeedResponse <T> cosmosQueryResponse = await itemQuery.ReadNextAsync(); if (queryRequestOptions.MaxItemCount.HasValue) { Assert.IsTrue( cosmosQueryResponse.Count <= queryRequestOptions.MaxItemCount.Value, "Max Item Count is not being honored"); } resultsFromCosmosElementContinuationToken.AddRange(cosmosQueryResponse); continuationToken = itemQuery.GetCosmosElementContinuationToken(); } catch (CosmosException cosmosException) when(cosmosException.StatusCode == (HttpStatusCode)429) { itemQuery = (FeedIteratorInternal <T>)container.GetItemQueryIterator <T>( queryText: query, requestOptions: queryRequestOptions); } } while (continuationToken != null); return(resultsFromCosmosElementContinuationToken); }