コード例 #1
0
                public bool MoveNext()
                {
                    if (_jsonReader == null)
                    {
                        _query ??= _cosmosClientWrapper.CreateQuery(_containerId, _partitionKey, _cosmosSqlQuery);

                        if (!_query.HasMoreResults)
                        {
                            Current = default;
                            return(false);
                        }

                        _responseMessage = _query.ReadNextAsync().GetAwaiter().GetResult();
                        _responseMessage.EnsureSuccessStatusCode();

                        _responseStream = _responseMessage.Content;
                        _reader         = new StreamReader(_responseStream);
                        _jsonReader     = CreateJsonReader(_reader);
                    }

                    if (TryReadJObject(_jsonReader, out var jObject))
                    {
                        Current = jObject;
                        return(true);
                    }

                    ResetRead();

                    return(MoveNext());
                }
コード例 #2
0
                public async ValueTask <bool> MoveNextAsync()
                {
                    _cancellationToken.ThrowIfCancellationRequested();

                    if (_jsonReader == null)
                    {
                        _query ??= _cosmosClientWrapper.CreateQuery(_containerId, _partitionKey, _cosmosSqlQuery);

                        if (!_query.HasMoreResults)
                        {
                            Current = default;
                            return(false);
                        }

                        _responseMessage = await _query.ReadNextAsync(_cancellationToken).ConfigureAwait(false);

                        _responseMessage.EnsureSuccessStatusCode();

                        _responseStream = _responseMessage.Content;
                        _reader         = new StreamReader(_responseStream);
                        _jsonReader     = CreateJsonReader(_reader);
                    }

                    if (TryReadJObject(_jsonReader, out var jObject))
                    {
                        Current = jObject;
                        return(true);
                    }

                    await ResetReadAsync().ConfigureAwait(false);

                    return(await MoveNextAsync().ConfigureAwait(false));
                }
コード例 #3
0
                public async Task <bool> MoveNext(CancellationToken cancellationToken)
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    if (_underlyingEnumerator == null)
                    {
                        if (_query == null)
                        {
                            _query = _cosmosClient.CreateQuery <JObject>(_containerId, _cosmosSqlQuery);
                        }

                        if (!_query.HasMoreResults)
                        {
                            Current = default;
                            return(false);
                        }

                        _underlyingEnumerator = (await _query.FetchNextSetAsync(cancellationToken)).GetEnumerator();
                    }

                    var hasNext = _underlyingEnumerator.MoveNext();

                    if (hasNext)
                    {
                        Current = (JObject)_underlyingEnumerator.Current.First.First;
                        return(true);
                    }

                    _underlyingEnumerator.Dispose();
                    _underlyingEnumerator = null;
                    return(await MoveNext(cancellationToken));
                }
コード例 #4
0
                public bool MoveNext()
                {
                    if (_underlyingEnumerator == null)
                    {
                        if (_query == null)
                        {
                            _query = _cosmosClient.CreateQuery <JObject>(_containerId, _cosmosSqlQuery);
                        }

                        if (!_query.HasMoreResults)
                        {
                            Current = default;
                            return(false);
                        }

                        _underlyingEnumerator = _query.FetchNextSetAsync().GetAwaiter().GetResult().GetEnumerator();
                    }

                    var hasNext = _underlyingEnumerator.MoveNext();

                    if (hasNext)
                    {
                        Current = (JObject)_underlyingEnumerator.Current.First.First;
                        return(true);
                    }

                    _underlyingEnumerator.Dispose();
                    _underlyingEnumerator = null;

                    return(MoveNext());
                }
コード例 #5
0
                public bool MoveNext()
                {
                    if (_jsonReader == null)
                    {
                        if (_query == null)
                        {
                            _query = _cosmosClient.CreateQuery(_containerId, _partitionKey, _cosmosSqlQuery);
                        }

                        if (!_query.HasMoreResults)
                        {
                            Current = default;
                            return(false);
                        }

                        _responseMessage = _query.ReadNextAsync().GetAwaiter().GetResult();
                        _responseMessage.EnsureSuccessStatusCode();

                        _responseStream = _responseMessage.Content;
                        _reader         = new StreamReader(_responseStream);
                        _jsonReader     = new JsonTextReader(_reader);

                        while (_jsonReader.Read())
                        {
                            if (_jsonReader.TokenType == JsonToken.StartObject)
                            {
                                while (_jsonReader.Read())
                                {
                                    if (_jsonReader.TokenType == JsonToken.StartArray)
                                    {
                                        goto ObjectFound;
                                    }
                                }
                            }
                        }

                        ObjectFound :;
                    }

                    while (_jsonReader.Read())
                    {
                        if (_jsonReader.TokenType == JsonToken.StartObject)
                        {
                            Current = new JsonSerializer().Deserialize <JObject>(_jsonReader);

                            return(true);
                        }
                    }

                    _jsonReader.Close();
                    _jsonReader = null;
                    _reader.Dispose();
                    _reader = null;
                    _responseStream.Dispose();
                    _responseStream = null;

                    return(MoveNext());
                }
コード例 #6
0
                public async ValueTask <bool> MoveNextAsync()
                {
                    _cancellationToken.ThrowIfCancellationRequested();

                    if (_jsonReader == null)
                    {
                        if (_query == null)
                        {
                            _query = _cosmosClient.CreateQuery(_containerId, _cosmosSqlQuery);
                        }

                        if (!_query.HasMoreResults)
                        {
                            Current = default;
                            return(false);
                        }

                        _responseStream = (await _query.ReadNextAsync(_cancellationToken)).Content;
                        _reader         = new StreamReader(_responseStream);
                        _jsonReader     = new JsonTextReader(_reader);

                        while (_jsonReader.Read())
                        {
                            if (_jsonReader.TokenType == JsonToken.StartObject)
                            {
                                while (_jsonReader.Read())
                                {
                                    if (_jsonReader.TokenType == JsonToken.StartArray)
                                    {
                                        goto ObjectFound;
                                    }
                                }
                            }
                        }

ObjectFound:
                        ;
                    }

                    while (_jsonReader.Read())
                    {
                        if (_jsonReader.TokenType == JsonToken.StartObject)
                        {
                            Current = new JsonSerializer().Deserialize <JObject>(_jsonReader);
                            return(true);
                        }
                    }

                    _jsonReader.Close();
                    _jsonReader = null;
                    await _reader.DisposeAsyncIfAvailable();

                    _reader = null;
                    await _responseStream.DisposeAsync();

                    _responseStream = null;
                    return(await MoveNextAsync());
                }
コード例 #7
0
                public async ValueTask <bool> MoveNextAsync()
                {
                    _cancellationToken.ThrowIfCancellationRequested();

                    if (_jsonReader == null)
                    {
                        if (_query == null)
                        {
                            _query = _cosmosClient.CreateQuery(_containerId, _cosmosSqlQuery);
                        }

                        if (!_query.HasMoreResults)
                        {
                            Current = default;
                            return(false);
                        }

                        _responseMessage = await _query.ReadNextAsync(_cancellationToken);

                        if (!_responseMessage.IsSuccessStatusCode)
                        {
                            throw new InvalidOperationException(CosmosStrings.QueryFailed(_responseMessage.StatusCode, _responseMessage.ErrorMessage));
                        }

                        _responseStream = _responseMessage.Content;
                        _reader         = new StreamReader(_responseStream);
                        _jsonReader     = new JsonTextReader(_reader);

                        while (_jsonReader.Read())
                        {
                            if (_jsonReader.TokenType == JsonToken.StartObject)
                            {
                                while (_jsonReader.Read())
                                {
                                    if (_jsonReader.TokenType == JsonToken.StartArray)
                                    {
                                        goto ObjectFound;
                                    }
                                }
                            }
                        }

                        ObjectFound :;
                    }

                    while (_jsonReader.Read())
                    {
                        if (_jsonReader.TokenType == JsonToken.StartObject)
                        {
                            Current = new JsonSerializer().Deserialize <JObject>(_jsonReader);
                            return(true);
                        }
                    }

                    await DisposeAsync();

                    return(await MoveNextAsync());
                }
コード例 #8
0
ファイル: CosmosClientWrapper.cs プロジェクト: yesmey/efcore
                public async ValueTask <bool> MoveNextAsync()
                {
                    _cancellationToken.ThrowIfCancellationRequested();

                    if (_jsonReader == null)
                    {
                        _query ??= _cosmosClientWrapper.CreateQuery(_containerId, _partitionKey, _cosmosSqlQuery);

                        if (!_query.HasMoreResults)
                        {
                            _current = null;
                            return(false);
                        }

                        _responseMessage = await _query.ReadNextAsync(_cancellationToken).ConfigureAwait(false);

                        _cosmosClientWrapper._commandLogger.ExecutedReadNext(
                            _responseMessage.Diagnostics.GetClientElapsedTime(),
                            _responseMessage.Headers.RequestCharge,
                            _responseMessage.Headers.ActivityId,
                            _containerId,
                            _partitionKey,
                            _cosmosSqlQuery);

                        _responseMessage.EnsureSuccessStatusCode();

                        _responseStream = _responseMessage.Content;
                        _reader         = new StreamReader(_responseStream);
                        _jsonReader     = CreateJsonReader(_reader);
                    }

                    if (TryReadJObject(_jsonReader, out var jObject))
                    {
                        _current = jObject;
                        return(true);
                    }

                    await ResetReadAsync().ConfigureAwait(false);

                    return(await MoveNextAsync().ConfigureAwait(false));
                }
コード例 #9
0
ファイル: CosmosClientWrapper.cs プロジェクト: yesmey/efcore
                public bool MoveNext()
                {
                    if (_jsonReader == null)
                    {
                        _query ??= _cosmosClientWrapper.CreateQuery(_containerId, _partitionKey, _cosmosSqlQuery);

                        if (!_query.HasMoreResults)
                        {
                            _current = null;
                            return(false);
                        }

                        _responseMessage = _query.ReadNextAsync().GetAwaiter().GetResult();

                        _cosmosClientWrapper._commandLogger.ExecutedReadNext(
                            _responseMessage.Diagnostics.GetClientElapsedTime(),
                            _responseMessage.Headers.RequestCharge,
                            _responseMessage.Headers.ActivityId,
                            _containerId,
                            _partitionKey,
                            _cosmosSqlQuery);

                        _responseMessage.EnsureSuccessStatusCode();

                        _responseStream = _responseMessage.Content;
                        _reader         = new StreamReader(_responseStream);
                        _jsonReader     = CreateJsonReader(_reader);
                    }

                    if (TryReadJObject(_jsonReader, out var jObject))
                    {
                        _current = jObject;
                        return(true);
                    }

                    ResetRead();

                    return(MoveNext());
                }