コード例 #1
0
        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);
                }
            }
        }
コード例 #2
0
        public OeQueryContext CreateQueryContext(ODataUri odataUri, OeMetadataLevel metadataLevel, Type returnClrType)
        {
            String        entitySetName = _dataAdapter.EntitySetMetaAdapters.FindByClrType(returnClrType).EntitySetName;
            IEdmEntitySet entitySet     = _model.FindDeclaredEntitySet(entitySetName);

            OePropertyAccessor[] accessors = OePropertyAccessor.CreateFromType(returnClrType, entitySet);

            Db.OeEntitySetAdapter entitySetAdapter = _dataAdapter.GetEntitySetAdapter(entitySet.Name);
            return(new OeQueryContext(_model, odataUri, entitySet, null, false, 0, false,
                                      _dataAdapter.IsDatabaseNullHighestValue, metadataLevel, ref entitySetAdapter)
            {
                EntryFactory = OeEntryFactory.CreateEntryFactory(entitySet, accessors),
            });
        }
コード例 #3
0
ファイル: OeGetParser.cs プロジェクト: genusP/OdataToEntity
        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);
                }
            }
        }
コード例 #4
0
        public OeQueryContext CreateQueryContext(ODataUri odataUri, int pageSize, bool navigationNextLink, OeMetadataLevel metadataLevel)
        {
            List <OeParseNavigationSegment> navigationSegments = null;

            if (odataUri.Path.LastSegment is KeySegment ||
                odataUri.Path.LastSegment is NavigationPropertySegment)
            {
                navigationSegments = new List <OeParseNavigationSegment>();
                ODataPathSegment previousSegment = null;
                foreach (ODataPathSegment segment in odataUri.Path)
                {
                    if (segment is NavigationPropertySegment)
                    {
                        var navigationSegment = segment as NavigationPropertySegment;
                        if (navigationSegment == odataUri.Path.LastSegment)
                        {
                            navigationSegments.Add(new OeParseNavigationSegment(navigationSegment, null));
                        }
                        else
                        {
                            navigationSegments.Add(new OeParseNavigationSegment(navigationSegment, null));
                        }
                    }
                    else if (segment is KeySegment)
                    {
                        IEdmEntitySet             previousEntitySet;
                        var                       keySegment        = segment as KeySegment;
                        NavigationPropertySegment navigationSegment = null;
                        if (previousSegment is EntitySetSegment)
                        {
                            var previousEntitySetSegment = previousSegment as EntitySetSegment;
                            previousEntitySet = previousEntitySetSegment.EntitySet;
                        }
                        else if (previousSegment is NavigationPropertySegment)
                        {
                            navigationSegment = previousSegment as NavigationPropertySegment;
                            previousEntitySet = (IEdmEntitySet)navigationSegment.NavigationSource;
                        }
                        else
                        {
                            throw new InvalidOperationException("invalid segment");
                        }

                        FilterClause keyFilter = CreateFilterClause(previousEntitySet, keySegment.Keys);
                        navigationSegments.Add(new OeParseNavigationSegment(navigationSegment, keyFilter));
                    }
                    previousSegment = segment;
                }
            }

            if (pageSize > 0)
            {
                odataUri.Top = pageSize;
                IEdmEntityType edmEntityType = GetEntityType(odataUri.Path, navigationSegments);
                odataUri.OrderBy = OeSkipTokenParser.GetUniqueOrderBy(_edmModel, edmEntityType, odataUri.OrderBy);
            }

            var           entitySetSegment = (EntitySetSegment)odataUri.Path.FirstSegment;
            IEdmEntitySet entitySet        = entitySetSegment.EntitySet;

            Db.OeEntitySetAdapter entitySetAdapter = _dataAdapter.GetEntitySetAdapter(entitySet.Name);
            bool isCountSegment = odataUri.Path.LastSegment is CountSegment;

            return(new OeQueryContext(_edmModel, odataUri, entitySet, navigationSegments,
                                      isCountSegment, pageSize, navigationNextLink, _dataAdapter.IsDatabaseNullHighestValue, metadataLevel, ref entitySetAdapter));
        }