public async Task ExecuteAsync(ODataUri odataUri, OeRequestHeaders headers, Stream stream, CancellationToken cancellationToken) { OeParseUriContext parseUriContext = ParseUri(odataUri); parseUriContext.Headers = headers; parseUriContext.EntitySetAdapter = _dataAdapter.GetEntitySetAdapter(parseUriContext.EntitySet.Name); Object dataContext = null; try { dataContext = _dataAdapter.CreateDataContext(); if (parseUriContext.IsCountSegment) { int count = _dataAdapter.ExecuteScalar <int>(dataContext, parseUriContext); byte[] buffer = System.Text.Encoding.UTF8.GetBytes(count.ToString()); stream.Write(buffer, 0, buffer.Length); } else { using (Db.OeEntityAsyncEnumerator asyncEnumerator = _dataAdapter.ExecuteEnumerator(dataContext, parseUriContext, cancellationToken)) await Writers.OeGetWriter.SerializeAsync(BaseUri, parseUriContext, asyncEnumerator, stream).ConfigureAwait(false); } } finally { if (dataContext != null) { _dataAdapter.CloseDataContext(dataContext); } } }
public async Task ExecuteAsync(ODataUri odataUri, OeRequestHeaders headers, Stream stream, CancellationToken cancellationToken) { Object dataContext = null; try { dataContext = _dataAdapter.CreateDataContext(); OeQueryContext queryContext = CreateQueryContext(odataUri, headers.MaxPageSize, headers.NavigationNextLink, headers.MetadataLevel); if (queryContext.IsCountSegment) { headers.ResponseContentType = OeRequestHeaders.TextDefault.ContentType; int count = _dataAdapter.ExecuteScalar <int>(dataContext, queryContext); byte[] buffer = System.Text.Encoding.UTF8.GetBytes(count.ToString(CultureInfo.InvariantCulture)); stream.Write(buffer, 0, buffer.Length); } else { using (Db.OeAsyncEnumerator asyncEnumerator = _dataAdapter.ExecuteEnumerator(dataContext, queryContext, cancellationToken)) await Writers.OeGetWriter.SerializeAsync(queryContext, asyncEnumerator, headers.ContentType, stream).ConfigureAwait(false); } } finally { if (dataContext != null) { _dataAdapter.CloseDataContext(dataContext); } } }
public async Task ExecuteAsync(Uri requestUri, OeRequestHeaders headers, Stream stream, CancellationToken cancellationToken) { OeParseUriContext parseUriContext = ParseUri(requestUri); parseUriContext.Headers = headers; parseUriContext.EntitySetAdapter = _dataAdapter.GetEntitySetAdapter(parseUriContext.EntitySet.Name); Object dataContext = null; try { dataContext = _dataAdapter.CreateDataContext(); if (parseUriContext.IsCountSegment) { int count = _dataAdapter.ExecuteScalar <int>(parseUriContext, dataContext); byte[] buffer = System.Text.Encoding.UTF8.GetBytes(count.ToString()); stream.Write(buffer, 0, buffer.Length); } else { long?count = null; if (parseUriContext.ODataUri.QueryCount.GetValueOrDefault()) { var countParseUriContext = new OeParseUriContext(parseUriContext.EdmModel , parseUriContext.ODataUri , parseUriContext.EntitySet , parseUriContext.ParseNavigationSegments , true); countParseUriContext.Headers = parseUriContext.Headers; countParseUriContext.EntitySetAdapter = parseUriContext.EntitySetAdapter; count = _dataAdapter.ExecuteScalar <int>(countParseUriContext, dataContext); } using (Db.OeEntityAsyncEnumerator asyncEnumerator = _dataAdapter.ExecuteEnumerator(parseUriContext, dataContext, cancellationToken)) await Writers.OeGetWriter.SerializeAsync(BaseUri, parseUriContext, asyncEnumerator, stream, count).ConfigureAwait(false); } } finally { if (dataContext != null) { _dataAdapter.CloseDataContext(dataContext); } } }