Beispiel #1
0
        internal IDocumentQuery <T> CreateDocumentQuery <T>(
            SqlQuerySpec sqlQuerySpec,
            FeedOptions feedOptions = null)
        {
            EnsureArg.IsNotNull(sqlQuerySpec, nameof(sqlQuerySpec));

            CosmosQueryContext context = new CosmosQueryContext(_collectionUri, sqlQuerySpec, feedOptions);

            return(_cosmosDocumentQueryFactory.Create <T>(_documentClient, context));
        }
Beispiel #2
0
        internal async Task <FeedResponse <T> > ExecuteDocumentQueryAsync <T>(QueryDefinition sqlQuerySpec, QueryRequestOptions feedOptions, string continuationToken = null, CancellationToken cancellationToken = default)
        {
            EnsureArg.IsNotNull(sqlQuerySpec, nameof(sqlQuerySpec));

            var context = new CosmosQueryContext(sqlQuerySpec, feedOptions, continuationToken);

            var documentQuery = _cosmosQueryFactory.Create <T>(_containerScope.Value, context);

            return(await documentQuery.ExecuteNextAsync(cancellationToken));
        }
        internal async Task <FeedResponse <T> > ExecuteDocumentQueryAsync <T>(SqlQuerySpec sqlQuerySpec, FeedOptions feedOptions, CancellationToken cancellationToken)
        {
            EnsureArg.IsNotNull(sqlQuerySpec, nameof(sqlQuerySpec));

            var context = new CosmosQueryContext(CollectionUri, sqlQuerySpec, feedOptions);

            IDocumentQuery <T> documentQuery = _cosmosDocumentQueryFactory.Create <T>(_documentClientScope.Value, context);

            using (documentQuery)
            {
                return(await documentQuery.ExecuteNextAsync <T>(cancellationToken));
            }
        }
        /// <inheritdoc />
        public IDocumentQuery <T> Create <T>(IDocumentClient documentClient, CosmosQueryContext context)
        {
            EnsureArg.IsNotNull(documentClient, nameof(documentClient));
            EnsureArg.IsNotNull(context, nameof(context));

            IDocumentQuery <T> documentQuery = documentClient.CreateDocumentQuery <T>(
                context.CollectionUri,
                context.SqlQuerySpec,
                context.FeedOptions)
                                               .AsDocumentQuery();

            return(new CosmosDocumentQuery <T>(
                       context,
                       documentQuery,
                       _logger));
        }
Beispiel #5
0
        internal async Task <FeedResponse <T> > ExecuteDocumentQueryAsync <T>(QueryDefinition sqlQuerySpec, QueryRequestOptions feedOptions, string continuationToken = null, CancellationToken cancellationToken = default)
        {
            EnsureArg.IsNotNull(sqlQuerySpec, nameof(sqlQuerySpec));

            var context = new CosmosQueryContext(sqlQuerySpec, feedOptions, continuationToken);

            var documentQuery = _cosmosQueryFactory.Create <T>(_containerScope.Value, context);

            try
            {
                return(await documentQuery.ExecuteNextAsync(cancellationToken));
            }
            catch (CosmosException e) when(e.StatusCode == HttpStatusCode.BadRequest && continuationToken != null && e.ResponseBody.StartsWith("Malformed continuation token", StringComparison.OrdinalIgnoreCase))
            {
                // there isn't a status code that indicates this condition, so we rely on the error message.
                throw new BadRequestException(Core.Resources.InvalidContinuationToken);
            }
        }