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(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); } } }
public async Task ExecuteAsync(ODataUri odataUri, Stream requestStream, OeRequestHeaders headers, Stream responseStream, CancellationToken cancellationToken) { var importSegment = (OperationImportSegment)odataUri.Path.LastSegment; List <KeyValuePair <String, Object> > parameters = GetParameters(importSegment, requestStream, headers.ContentType); Object dataContext = null; try { dataContext = _dataAdapter.CreateDataContext(); var operation = (EdmOperation)importSegment.OperationImports.Single().Operation; String procedureName; if (String.IsNullOrEmpty(operation.Namespace)) { procedureName = operation.Name; } else { procedureName = operation.Namespace + "." + operation.Name; } Type returnClrType = null; if (operation.ReturnType != null) { IEdmTypeReference returnEdmTypeReference = operation.ReturnType; if (returnEdmTypeReference is IEdmCollectionTypeReference) { returnEdmTypeReference = (returnEdmTypeReference.Definition as IEdmCollectionType).ElementType; } returnClrType = OeEdmClrHelper.GetClrType(_model, returnEdmTypeReference.Definition); } using (Db.OeEntityAsyncEnumerator asyncEnumerator = _dataAdapter.ExecuteProcedure(dataContext, procedureName, parameters, returnClrType)) { if (returnClrType == null) { if (await asyncEnumerator.MoveNextAsync() && asyncEnumerator.Current != null) { byte[] buffer = System.Text.Encoding.UTF8.GetBytes(asyncEnumerator.Current.ToString()); responseStream.Write(buffer, 0, buffer.Length); } } else { String entitySetName = _dataAdapter.EntitySetMetaAdapters.FindByClrType(returnClrType).EntitySetName; IEdmEntitySet entitySet = _model.FindDeclaredEntitySet(entitySetName); Parsers.OePropertyAccessor[] accessors = Parsers.OePropertyAccessor.CreateFromType(returnClrType, entitySet); Parsers.OeEntryFactory entryFactory = Parsers.OeEntryFactory.CreateEntryFactory(entitySet, accessors); var parseUriContext = new Parsers.OeParseUriContext(_model, odataUri, entitySet, null, false) { EntryFactory = entryFactory, Headers = headers }; await Writers.OeGetWriter.SerializeAsync(_baseUri, parseUriContext, asyncEnumerator, responseStream).ConfigureAwait(false); } } } finally { if (dataContext != null) { _dataAdapter.CloseDataContext(dataContext); } } await Task.CompletedTask; }