public static async Task WriteCollectionAsync(IEdmModel model, ODataUri odataUri, Db.OeAsyncEnumerator asyncEnumerator, Stream responseStream) { var importSegment = (OperationImportSegment)odataUri.Path.LastSegment; IEdmOperationImport operationImport = importSegment.OperationImports.Single(); Type returnType = model.GetClrType(operationImport.Operation.ReturnType.Definition); IODataRequestMessage requestMessage = new Infrastructure.OeInMemoryMessage(responseStream, null); using (ODataMessageWriter messageWriter = new ODataMessageWriter(requestMessage, new ODataMessageWriterSettings() { EnableMessageStreamDisposal = false, ODataUri = odataUri }, model)) { IEdmTypeReference typeRef = OeEdmClrHelper.GetEdmTypeReference(model, returnType); ODataCollectionWriter writer = messageWriter.CreateODataCollectionWriter(typeRef); writer.WriteStart(new ODataCollectionStart()); while (await asyncEnumerator.MoveNextAsync().ConfigureAwait(false)) { Object value = asyncEnumerator.Current; if (value != null && value.GetType().IsEnum) { value = value.ToString(); } writer.WriteItem(value); } writer.WriteEnd(); } }
public async Task ExecuteAsync(ODataUri odataUri, Stream requestStream, OeRequestHeaders headers, Stream responseStream, CancellationToken cancellationToken) { Object dataContext = null; try { dataContext = _dataAdapter.CreateDataContext(); using (Db.OeAsyncEnumerator asyncEnumerator = GetAsyncEnumerator(odataUri, requestStream, headers, dataContext, out bool isScalar)) { if (isScalar) { if (await asyncEnumerator.MoveNextAsync().ConfigureAwait(false) && asyncEnumerator.Current != null) { headers.ResponseContentType = OeRequestHeaders.TextDefault.ContentType; byte[] buffer = System.Text.Encoding.UTF8.GetBytes(asyncEnumerator.Current.ToString()); responseStream.Write(buffer, 0, buffer.Length); } else headers.ResponseContentType = null; } else { OeQueryContext queryContext = CreateQueryContext(odataUri, headers.MetadataLevel); if (queryContext == null) await WriteCollectionAsync(_edmModel, odataUri, asyncEnumerator, responseStream).ConfigureAwait(false); else await Writers.OeGetWriter.SerializeAsync(queryContext, asyncEnumerator, headers.ContentType, responseStream).ConfigureAwait(false); } } } finally { if (dataContext != null) _dataAdapter.CloseDataContext(dataContext); } }
public async Task <bool> MoveNext(CancellationToken cancellationToken) { if (_isFirstMoveNext) { _isFirstMoveNext = false; _isMoveNext = await _asyncEnumerator.MoveNextAsync().ConfigureAwait(false); } if (!_isMoveNext) { return(false); } Object value = _asyncEnumerator.Current; Object entry = _entryFactory.GetValue(value, out int?dummy); if (OeExpressionHelper.IsTupleType(entry.GetType())) { Current = (T)CreateEntityFromTuple(typeof(T), entry, _entryFactory.Accessors); } else { Current = (T)entry; } foreach (OeEntryFactory navigationLink in _entryFactory.NavigationLinks) { SetNavigationProperty(navigationLink, value, Current); } _isMoveNext = await _asyncEnumerator.MoveNextAsync().ConfigureAwait(false); if (!_isMoveNext && _queryContext.SkipTokenNameValues != null && _queryContext.SkipTokenAccessors != null) { SetOrderByProperties(Current, value); } return(true); }
public async Task SerializeAsync(OeEntryFactory entryFactory, Db.OeAsyncEnumerator asyncEnumerator, OeQueryContext queryContext) { var resourceSet = new ODataResourceSet() { Count = asyncEnumerator.Count }; Writer.WriteStart(resourceSet); Object value = null; int count = 0; while (await asyncEnumerator.MoveNextAsync().ConfigureAwait(false)) { value = asyncEnumerator.Current; ODataResource entry = CreateEntry(entryFactory, entryFactory.GetValue(value, out _)); Writer.WriteStart(entry); foreach (OeEntryFactory navigationLink in entryFactory.NavigationLinks) { WriteNavigationLink(value, navigationLink, entry, entryFactory.EntitySet); } if (QueryContext.NavigationNextLink) { foreach (ExpandedNavigationSelectItem item in QueryContext.GetExpandedNavigationSelectItems()) { WriteNavigationNextLink(entry, item); } } Writer.WriteEnd(); count++; } if (queryContext.PageSize > 0 && count > 0 && (asyncEnumerator.Count ?? Int32.MaxValue) > count) { resourceSet.NextPageLink = BuildNextPageLink(queryContext, value); } Writer.WriteEnd(); }
public Task <bool> MoveNext(CancellationToken cancellationToken) { return(_asyncEnumerator.MoveNextAsync()); }