示例#1
0
        public async Task WriteAsync(OeEntryFactory entryFactory, IAsyncEnumerator <Object> asyncEnumerator)
        {
            var resourceSet = new ODataResourceSet()
            {
                Count = _queryContext.TotalCountOfItems
            };
            await _writer.WriteStartAsync(resourceSet).ConfigureAwait(false);

            Object?rawValue  = null;
            int    readCount = 0;

            Db.IOeDbEnumerator dbEnumerator = entryFactory.IsTuple ?
                                              (Db.IOeDbEnumerator) new Db.OeDbEnumerator(asyncEnumerator, entryFactory) : new Db.OeEntityDbEnumerator(asyncEnumerator, entryFactory);
            while (await dbEnumerator.MoveNextAsync().ConfigureAwait(false))
            {
                await WriteEntry(dbEnumerator, dbEnumerator.Current).ConfigureAwait(false);

                readCount++;
                rawValue = dbEnumerator.RawValue;
                dbEnumerator.ClearBuffer();
            }

            if (rawValue != null)
            {
                var nextPageLinkBuilder = new OeNextPageLinkBuilder(_queryContext);
                resourceSet.NextPageLink = nextPageLinkBuilder.GetNextPageLinkRoot(entryFactory, readCount, _queryContext.TotalCountOfItems, rawValue);
            }

            await _writer.WriteEndAsync().ConfigureAwait(false);
        }
示例#2
0
        private async Task WriteNavigationNextLink(OeEntryFactory parentEntryFactory, ExpandedNavigationSelectItem item, Object value)
        {
            Uri?nextPageLink = new OeNextPageLinkBuilder(_queryContext).GetNavigationUri(parentEntryFactory, item, value);

            if (nextPageLink == null)
            {
                return;
            }

            var  segment      = (NavigationPropertySegment)item.PathToNavigationProperty.LastSegment;
            bool isCollection = segment.NavigationProperty.Type.IsCollection();
            var  resourceInfo = new ODataNestedResourceInfo()
            {
                IsCollection = isCollection,
                Name         = segment.NavigationProperty.Name
            };
            await _writer.WriteStartAsync(resourceInfo).ConfigureAwait(false);

            if (isCollection)
            {
                var resourceSet = new ODataResourceSet()
                {
                    NextPageLink = nextPageLink
                };
                await _writer.WriteStartAsync(resourceSet).ConfigureAwait(false);

                await _writer.WriteEndAsync().ConfigureAwait(false);
            }
            else
            {
                resourceInfo.Url = nextPageLink;
            }

            await _writer.WriteEndAsync().ConfigureAwait(false);
        }
        private async Task WriteNavigationCollection(Db.IOeDbEnumerator dbEnumerator)
        {
            var              entryFactory = (OeNavigationEntryFactory)dbEnumerator.EntryFactory;
            Object           value;
            int              readCount   = 0;
            ODataResourceSet?resourceSet = null;

            do
            {
                value = dbEnumerator.Current;
                if (value != null)
                {
                    if (resourceSet == null)
                    {
                        resourceSet = new ODataResourceSet();
                        if (entryFactory.NavigationSelectItem.CountOption.GetValueOrDefault())
                        {
                            resourceSet.Count = OeNextPageLinkBuilder.GetNestedCount(_queryContext.EdmModel, dbEnumerator);
                        }
                        await _writer.WriteStartAsync(resourceSet).ConfigureAwait(false);
                    }

                    await WriteEntry(dbEnumerator, value).ConfigureAwait(false);

                    readCount++;
                }
            }while (await dbEnumerator.MoveNextAsync().ConfigureAwait(false));

            if (resourceSet == null)
            {
                resourceSet = new ODataResourceSet();
                if (entryFactory.NavigationSelectItem.CountOption.GetValueOrDefault())
                {
                    resourceSet.Count = 0;
                }
                await _writer.WriteStartAsync(resourceSet).ConfigureAwait(false);
            }
            else
            {
                var nextPageLinkBuilder = new OeNextPageLinkBuilder(_queryContext);
                resourceSet.NextPageLink = nextPageLinkBuilder.GetNextPageLinkNavigation(dbEnumerator, readCount, resourceSet.Count, value !);
            }

            await _writer.WriteEndAsync().ConfigureAwait(false);
        }
        public static int GetNestedCount(IEdmModel edmModel, Db.IOeDbEnumerator dbEnumerator)
        {
            Db.IOeDbEnumerator parentEnumerator = dbEnumerator.ParentEnumerator;
            ODataUri           odataUri         = OeNextPageLinkBuilder.GetCountODataUri(edmModel, parentEnumerator.EntryFactory, dbEnumerator.EntryFactory.NavigationSelectItem, parentEnumerator.Current);
            var queryContext = new OeQueryContext(edmModel, odataUri);

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

            Db.OeDataAdapter dataAdapter = edmModel.GetDataAdapter(entitySet.Container);
            Object           dataContext = null;

            try
            {
                dataContext = dataAdapter.CreateDataContext();
                return(dataAdapter.ExecuteScalar <int>(dataContext, queryContext));
            }
            finally
            {
                if (dataContext != null)
                {
                    dataAdapter.CloseDataContext(dataContext);
                }
            }
        }