public OeDbEnumerator(OeAsyncEnumerator asyncEnumerator, OeEntryFactory entryFactory) { Context = new DataContext(asyncEnumerator); EntryFactory = entryFactory; _bufferPosition = -1; }
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 DataContext(OeAsyncEnumerator asyncEnumerator) { AsyncEnumerator = asyncEnumerator; Buffer = new List <Object>(1024); _pool = new Dictionary <OeEntryFactory, OeDbEnumerator>(); }
public OeEntityAsyncEnumeratorAdapter(OeAsyncEnumerator asyncEnumerator, OeQueryContext queryContext) : base(asyncEnumerator.CancellationToken) { _asyncEnumerator = asyncEnumerator; _dbEnumerator = new OeDbEnumerator(asyncEnumerator, queryContext.EntryFactory); _queryContext = queryContext; _isFirstMoveNext = true; }
private OeEntityAsyncEnumeratorAdapter(OeAsyncEnumerator asyncEnumerator, OeEntryFactory entryFactory, OeQueryContext queryContext) : base(asyncEnumerator.CancellationToken) { _asyncEnumerator = asyncEnumerator; _dbEnumerator = new OeDbEnumerator(asyncEnumerator, entryFactory); _queryContext = queryContext; _isFirstMoveNext = true; base.Count = asyncEnumerator.Count; }
public OeAsyncEnumerator ApplyBoundFunction(OeAsyncEnumerator asyncEnumerator, OeQueryContext queryContext) { if (queryContext.ODataUri.Path.LastSegment is OperationSegment operationSegment) { var edmFunction = (IEdmFunction)operationSegment.Operations.First(); MethodInfo methodInfo = queryContext.EdmModel.GetMethodInfo(edmFunction); IReadOnlyList <KeyValuePair <String, Object> > parameterList = OeOperationHelper.GetParameters( queryContext.EdmModel, operationSegment, queryContext.ODataUri.ParameterAliasNodes); Object boundParameter; Type boundParameterType = methodInfo.GetParameters()[1].ParameterType; if (boundParameterType.IsGenericType && boundParameterType.GetGenericTypeDefinition() == typeof(IAsyncEnumerator <>)) { boundParameterType = boundParameterType.GetGenericArguments()[0]; Type asyncEnumeratorAdapterType = typeof(OeAsyncEnumeratorAdapter <>).MakeGenericType(boundParameterType); ConstructorInfo ctor = asyncEnumeratorAdapterType.GetConstructor(new[] { typeof(OeAsyncEnumerator) }); boundParameter = ctor.Invoke(new Object[] { asyncEnumerator }); } else { boundParameter = asyncEnumerator.MoveNextAsync().GetAwaiter().GetResult() ? asyncEnumerator.Current : null; } var parameters = new Object[parameterList.Count + 2]; parameters[0] = queryContext.EdmModel; parameters[1] = boundParameter; for (int i = 2; i < parameters.Length; i++) { parameters[i] = parameterList[i - 2].Value; } Object result = methodInfo.Invoke(null, parameters); if (result is IEnumerable enumerable) { return(new OeAsyncEnumeratorAdapter(enumerable, asyncEnumerator.CancellationToken)); } else { return(new OeScalarAsyncEnumeratorAdapter(Task.FromResult(result), asyncEnumerator.CancellationToken)); } } return(asyncEnumerator); }
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 Type returnClrType)) { if (returnClrType == null || returnClrType.IsPrimitive || returnClrType == typeof(String)) { 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, returnClrType); await Writers.OeGetWriter.SerializeAsync(queryContext, asyncEnumerator, headers.ContentType, responseStream).ConfigureAwait(false); } } } finally { if (dataContext != null) { _dataAdapter.CloseDataContext(dataContext); } } }
public OeAsyncEnumeratorAdapter(OeAsyncEnumerator asyncEnumerator) { _asyncEnumerator = asyncEnumerator; }
public OeEntityDbEnumerator(OeAsyncEnumerator asyncEnumerator, OeEntryFactory entryFactory) { _asyncEnumerator = asyncEnumerator; EntryFactory = entryFactory; }
public OeEntityAsyncEnumeratorAdapter(OeAsyncEnumerator asyncEnumerator, OeEntryFactory entryFactory) : this(asyncEnumerator, entryFactory, null) { }
public OeEntityAsyncEnumeratorAdapter(OeAsyncEnumerator asyncEnumerator, OeQueryContext queryContext) : this(asyncEnumerator, queryContext.EntryFactory, queryContext) { }