Exemplo n.º 1
0
        private async Task SetBodyAsync(ElasticsearchResponse <TReturn> response, Stream stream)
        {
            byte[] bytes = null;
            if (NeedsToEagerReadStream())
            {
                var inMemoryStream = this._requestData.MemoryStreamFactory.Create();
                await stream.CopyToAsync(inMemoryStream, BufferSize, this._requestData.CancellationToken).ConfigureAwait(false);

                bytes = this.SwapStreams(ref stream, ref inMemoryStream);
            }

            if (response.Success)
            {
                if (!SetSpecialTypes(stream, response, bytes))
                {
                    if (this._requestData.CustomConverter != null)
                    {
                        response.Body = this._requestData.CustomConverter(response, stream) as TReturn;
                    }
                    else
                    {
                        response.Body = await this._requestData.ConnectionSettings.Serializer.DeserializeAsync <TReturn>(stream, this._requestData.CancellationToken).ConfigureAwait(false);
                    }
                }
            }
            else if (response.HttpStatusCode != null)
            {
                response.ServerError = await ServerError.TryCreateAsync(stream, this._requestData.CancellationToken).ConfigureAwait(false);

                if (this._requestData.ConnectionSettings.DisableDirectStreaming)
                {
                    response.ResponseBodyInBytes = bytes;
                }
            }
        }
Exemplo n.º 2
0
        private async Task ReadServerErrorAsync(ElasticsearchResponse <TReturn> response, Stream stream, byte[] bytes)
        {
            response.ServerError = await ServerError.TryCreateAsync(stream, this._cancellationToken).ConfigureAwait(false);

            if (_disableDirectStreaming)
            {
                response.ResponseBodyInBytes = bytes;
            }
        }