コード例 #1
0
        /// <summary>
        /// Creates the materializer feed.
        /// </summary>
        /// <param name="feed">The feed.</param>
        /// <param name="entries">The entries.</param>
        /// <returns>The materializer feed.</returns>
        public static MaterializerFeed CreateFeed(ODataResourceSet feed, IEnumerable <ODataResource> entries)
        {
            Debug.Assert(feed.GetAnnotation <IEnumerable <ODataResource> >() == null, "Feed state has already been created.");
            if (entries == null)
            {
                entries = Enumerable.Empty <ODataResource>();
            }
            else
            {
                feed.SetAnnotation <IEnumerable <ODataResource> >(entries);
            }

            return(new MaterializerFeed(feed, entries));
        }
コード例 #2
0
        private void WriteFeed(ODataWriter writer, ODataResourceSet resourceCollection)
        {
            writer.WriteStart(resourceCollection);
            var annotation = resourceCollection.GetAnnotation <ODataFeedEntriesObjectModelAnnotation>();

            if (annotation != null)
            {
                foreach (var entry in annotation)
                {
                    this.WriteEntry(writer, entry);
                }
            }

            writer.WriteEnd();
        }
コード例 #3
0
        private void WriteFeed(ODataWriter writer, Lazy <ODataReader> lazyReader, ODataResourceSet feed)
        {
            this.WriteStart(writer, feed);
            var annotation = feed.GetAnnotation <ODataFeedEntriesObjectModelAnnotation>();

            if (annotation != null)
            {
                int count = annotation.Count;
                for (int i = 0; i < count; ++i)
                {
                    this.WriteEntry(writer, lazyReader, annotation[i]);
                }
            }

            this.WriteEnd(writer, ODataReaderState.ResourceSetEnd);
            this.Read(lazyReader);
        }
コード例 #4
0
 /// <summary>
 /// Gets all entries attached to the <paramref name="feed"/> via the
 /// <see cref="ODataFeedEntriesObjectModelAnnotation"/> annotation.
 /// </summary>
 /// <param name="feed">The <see cref="ODataResourceSet"/> to get the entries for.</param>
 /// <returns>A list of entries or null if none were found.</returns>
 public static IList <ODataItem> Entries(this ODataResourceSet resourceCollection)
 {
     ExceptionUtilities.CheckArgumentNotNull(resourceCollection, "feed");
     return(resourceCollection.GetAnnotation <ODataFeedEntriesObjectModelAnnotation>());
 }
コード例 #5
0
            /// <summary>
            /// Visits a feed item.
            /// </summary>
            /// <param name="feed">The feed to visit.</param>
            protected override ODataPayloadElement VisitFeed(ODataResourceSet resourceCollection)
            {
                ODataPayloadElement payloadElement = base.VisitFeed(resourceCollection);
                ODataFeedPayloadOrderObjectModelAnnotation payloadOrderFeedAnnotation = resourceCollection.GetAnnotation <ODataFeedPayloadOrderObjectModelAnnotation>();

                if (payloadOrderFeedAnnotation != null)
                {
                    PayloadOrderODataPayloadElementAnnotation payloadOrderElementAnnotation = new PayloadOrderODataPayloadElementAnnotation();
                    payloadOrderElementAnnotation.PayloadItems.AddRange(payloadOrderFeedAnnotation.PayloadItems);
                    payloadElement.Add(payloadOrderElementAnnotation);
                }

                return(payloadElement);
            }
コード例 #6
0
        /// <summary>
        /// Gets the materializer feed.
        /// </summary>
        /// <param name="feed">The feed.</param>
        /// <returns>The materializer feed.</returns>
        public static MaterializerFeed GetFeed(ODataResourceSet feed)
        {
            IEnumerable <ODataResource> entries = feed.GetAnnotation <IEnumerable <ODataResource> >();

            return(new MaterializerFeed(feed, entries));
        }
コード例 #7
0
        private void Read(Lazy <ODataReader> lazyReader)
        {
            foreach (var state in this.expectedStates)
            {
                lazyReader.Value.Read();
                ExceptionUtilities.Assert(lazyReader.Value.State == state, "Expected %1, Found %2", state, lazyReader.Value.State);
                switch (state)
                {
                case ODataReaderState.ResourceSetStart:
                    if (readItems.Count > 0)
                    {
                        ODataNestedResourceInfo navLink = (ODataNestedResourceInfo)readItems.Peek();
                        var annotation = navLink.GetAnnotation <ODataNavigationLinkExpandedItemObjectModelAnnotation>();
                        if (annotation == null)
                        {
                            annotation = new ODataNavigationLinkExpandedItemObjectModelAnnotation();
                            navLink.SetAnnotation(annotation);
                        }

                        annotation.ExpandedItem = lazyReader.Value.Item;
                    }

                    readItems.Push(lazyReader.Value.Item);
                    break;

                case ODataReaderState.ResourceStart:
                    var currentEntry = (ODataResource)lazyReader.Value.Item;
                    if (readItems.Count > 0)
                    {
                        ODataResourceSet feed = readItems.Peek() as ODataResourceSet;
                        if (feed != null)
                        {
                            var annotation = feed.GetAnnotation <ODataFeedEntriesObjectModelAnnotation>();
                            if (annotation == null)
                            {
                                annotation = new ODataFeedEntriesObjectModelAnnotation();
                                feed.SetAnnotation(annotation);
                            }
                            annotation.Add((ODataResource)lazyReader.Value.Item);
                        }
                        else
                        {
                            ODataNestedResourceInfo navLink = (ODataNestedResourceInfo)readItems.Peek();
                            var annotation = navLink.GetAnnotation <ODataNavigationLinkExpandedItemObjectModelAnnotation>();
                            if (annotation == null)
                            {
                                annotation = new ODataNavigationLinkExpandedItemObjectModelAnnotation();
                                navLink.SetAnnotation(annotation);
                            }

                            annotation.ExpandedItem = currentEntry;
                        }
                    }

                    readItems.Push(currentEntry);
                    break;

                case ODataReaderState.NestedResourceInfoStart:
                    ODataResource entry = (ODataResource)readItems.Peek();
                    var           navLinksAnnotation = entry.GetAnnotation <ODataEntryNavigationLinksObjectModelAnnotation>();
                    if (navLinksAnnotation == null)
                    {
                        navLinksAnnotation = new ODataEntryNavigationLinksObjectModelAnnotation();
                        entry.SetAnnotation(navLinksAnnotation);
                    }

                    navLinksAnnotation.Add((ODataNestedResourceInfo)lazyReader.Value.Item, entry.Properties.Count() + navLinksAnnotation.Count);
                    readItems.Push(lazyReader.Value.Item);
                    break;

                case ODataReaderState.ResourceEnd:
                case ODataReaderState.ResourceSetEnd:
                case ODataReaderState.NestedResourceInfoEnd:
                    if (readItems.Count() > 1)
                    {
                        readItems.Pop();
                    }
                    break;
                }
            }

            this.expectedStates.Clear();
        }