コード例 #1
0
        public OeDbEnumerator(OeAsyncEnumerator asyncEnumerator, OeEntryFactory entryFactory)
        {
            Context      = new DataContext(asyncEnumerator);
            EntryFactory = entryFactory;

            _bufferPosition = -1;
        }
コード例 #2
0
        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);
                }
            }
        }
コード例 #3
0
            public DataContext(OeAsyncEnumerator asyncEnumerator)
            {
                AsyncEnumerator = asyncEnumerator;
                Buffer          = new List <Object>(1024);

                _pool = new Dictionary <OeEntryFactory, OeDbEnumerator>();
            }
コード例 #4
0
 public OeEntityAsyncEnumeratorAdapter(OeAsyncEnumerator asyncEnumerator, OeQueryContext queryContext)
     : base(asyncEnumerator.CancellationToken)
 {
     _asyncEnumerator = asyncEnumerator;
     _dbEnumerator    = new OeDbEnumerator(asyncEnumerator, queryContext.EntryFactory);
     _queryContext    = queryContext;
     _isFirstMoveNext = true;
 }
コード例 #5
0
 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;
 }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
                }
            }
        }
コード例 #8
0
 public OeAsyncEnumeratorAdapter(OeAsyncEnumerator asyncEnumerator)
 {
     _asyncEnumerator = asyncEnumerator;
 }
コード例 #9
0
 public OeEntityDbEnumerator(OeAsyncEnumerator asyncEnumerator, OeEntryFactory entryFactory)
 {
     _asyncEnumerator = asyncEnumerator;
     EntryFactory     = entryFactory;
 }
コード例 #10
0
 public OeEntityAsyncEnumeratorAdapter(OeAsyncEnumerator asyncEnumerator, OeEntryFactory entryFactory)
     : this(asyncEnumerator, entryFactory, null)
 {
 }
コード例 #11
0
 public OeEntityAsyncEnumeratorAdapter(OeAsyncEnumerator asyncEnumerator, OeQueryContext queryContext)
     : this(asyncEnumerator, queryContext.EntryFactory, queryContext)
 {
 }