Ejemplo n.º 1
0
        public async Task <IEnumerable <T> > ConvertAsync(CosmosAttribute attribute, CancellationToken cancellationToken)
        {
            CosmosContext context = configProvider.CreateContext(attribute);

            List <T> finalResults = new List <T>();

            string continuation = null;

            QueryDefinition query = new QueryDefinition(context.ResolvedAttribute.SqlQuery);

            if ((context.ResolvedAttribute.SqlQueryParameters?.Count ?? 0) > 0)
            {
                foreach (var parameter in context.ResolvedAttribute.SqlQueryParameters)
                {
                    query = query.WithParameter(parameter.Key, parameter.Value);
                }
            }

            var response = context.Service.GetItemQueryIterator <T>(context.ResolvedAttribute.DatabaseName, context.ResolvedAttribute.ContainerName, query);

            do
            {
                await foreach (var page in response.AsPages(continuation))
                {
                    finalResults.AddRange(page.Values);
                    continuation = page.ContinuationToken;
                }
            }while (!string.IsNullOrEmpty(continuation));

            return(finalResults);
        }
        public IAsyncCollector <T> Convert(CosmosAttribute attribute)
        {
            CosmosContext context = configProvider.CreateContext(attribute);

            return(new CosmosAsyncCollector <T>(context));
        }