Example #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ODataReaderEntityMaterializer" /> class.
 /// </summary>
 /// <param name="odataMessageReader">The odata message reader.</param>
 /// <param name="reader">The reader.</param>
 /// <param name="materializerContext">The materializer context.</param>
 /// <param name="entityTrackingAdapter">The entity tracking adapter.</param>
 /// <param name="queryComponents">The query components.</param>
 /// <param name="expectedType">The expected type.</param>
 /// <param name="materializeEntryPlan">The materialize entry plan.</param>
 public ODataReaderEntityMaterializer(
     ODataMessageReader odataMessageReader,
     ODataReaderWrapper reader,
     IODataMaterializerContext materializerContext,
     EntityTrackingAdapter entityTrackingAdapter,
     QueryComponents queryComponents,
     Type expectedType,
     ProjectionPlan materializeEntryPlan)
     : base(materializerContext, entityTrackingAdapter, queryComponents, expectedType, materializeEntryPlan)
 {
     this.messageReader    = odataMessageReader;
     this.feedEntryAdapter = new FeedAndEntryMaterializerAdapter(odataMessageReader, reader, materializerContext.Model, entityTrackingAdapter.MergeOption);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ODataReaderEntityMaterializer" /> class.
 /// </summary>
 /// <param name="odataMessageReader">The odata message reader.</param>
 /// <param name="reader">The reader.</param>
 /// <param name="materializerContext">The materializer context.</param>
 /// <param name="entityTrackingAdapter">The entity tracking adapter.</param>
 /// <param name="queryComponents">The query components.</param>
 /// <param name="expectedType">The expected type.</param>
 /// <param name="materializeEntryPlan">The materialize entry plan.</param>
 public ODataReaderEntityMaterializer(
     ODataMessageReader odataMessageReader,
     ODataReaderWrapper reader,
     IODataMaterializerContext materializerContext,
     EntityTrackingAdapter entityTrackingAdapter,
     QueryComponents queryComponents,
     Type expectedType,
     ProjectionPlan materializeEntryPlan)
     : base(materializerContext, entityTrackingAdapter, queryComponents, expectedType, materializeEntryPlan)
 {
     this.messageReader = odataMessageReader;
     this.feedEntryAdapter = new FeedAndEntryMaterializerAdapter(odataMessageReader, reader, materializerContext.Model, entityTrackingAdapter.MergeOption);
 }
        public void ValidateShortIntegrationFeedReading()
        {
            var initialFeed = new ODataFeed() {Id = new Uri("http://services.odata.org/OData/OData.svc/Products")};
            
            var productItem = new ODataEntry() {Id = new Uri("http://services.odata.org/OData/OData.svc/Products(0)")};
            productItem.Properties = new ODataProperty[] {new ODataProperty() {Name = "Id", Value = 0}};

            var categoryNavigationLink = new ODataNavigationLink() {Name = "Category"};

            var categoryItem = new ODataEntry() { Id = new Uri("http://services.odata.org/OData/OData.svc/Categories(0)") };
            categoryItem.Properties = new ODataProperty[] { new ODataProperty() { Name = "Id", Value = 0 } };

            var productsNavigationLink = new ODataNavigationLink() { Name = "Products" };

            var supplierNavigationLink = new ODataNavigationLink() { Name = "Supplier" };

            var testODataReader = new TestODataReader()
            {
               new TestODataReaderItem(ODataReaderState.FeedStart, initialFeed),
               new TestODataReaderItem(ODataReaderState.EntryStart, productItem),
               new TestODataReaderItem(ODataReaderState.NavigationLinkStart, categoryNavigationLink),
               new TestODataReaderItem(ODataReaderState.EntryStart, categoryItem),
               new TestODataReaderItem(ODataReaderState.NavigationLinkStart, productsNavigationLink),
               new TestODataReaderItem(ODataReaderState.NavigationLinkEnd, productsNavigationLink),
               new TestODataReaderItem(ODataReaderState.EntryEnd, categoryItem),
               new TestODataReaderItem(ODataReaderState.NavigationLinkEnd, categoryNavigationLink),
               new TestODataReaderItem(ODataReaderState.NavigationLinkStart, supplierNavigationLink),
               new TestODataReaderItem(ODataReaderState.NavigationLinkEnd, supplierNavigationLink),
               new TestODataReaderItem(ODataReaderState.EntryEnd, productItem),
               new TestODataReaderItem(ODataReaderState.FeedEnd, initialFeed),
            };

            ClientEdmModel clientEdmModel = new ClientEdmModel(ODataProtocolVersion.V4);

            var responsePipeline = new DataServiceClientResponsePipelineConfiguration(new DataServiceContext());
            var odataReaderWrapper = ODataReaderWrapper.CreateForTest(testODataReader, responsePipeline);
            FeedAndEntryMaterializerAdapter reader = new FeedAndEntryMaterializerAdapter(ODataFormat.Atom, odataReaderWrapper, clientEdmModel, MergeOption.OverwriteChanges);

            int readCounter = 0;

            while (reader.Read())
            {
                readCounter++;
            }

            readCounter.Should().Be(2);
        }
Example #4
0
        /// <summary>
        /// This method is for parsing CUD operation payloads which should contain
        /// 1 a single entry
        /// 2 An Error
        /// </summary>
        /// <param name="message">the message for the payload</param>
        /// <param name="responseInfo">The current ResponseInfo object</param>
        /// <param name="expectedType">The expected type</param>
        /// <returns>the MaterializerEntry that was read</returns>
        internal static MaterializerEntry ParseSingleEntityPayload(IODataResponseMessage message, ResponseInfo responseInfo, Type expectedType)
        {
            ODataPayloadKind messageType = ODataPayloadKind.Resource;

            using (ODataMessageReader messageReader = CreateODataMessageReader(message, responseInfo, ref messageType))
            {
                IEdmType           edmType = responseInfo.TypeResolver.ResolveExpectedTypeForReading(expectedType);
                ODataReaderWrapper reader  = ODataReaderWrapper.Create(messageReader, messageType, edmType, responseInfo.ResponsePipeline);

                FeedAndEntryMaterializerAdapter parser = new FeedAndEntryMaterializerAdapter(messageReader, reader, responseInfo.Model, responseInfo.MergeOption);

                ODataResource entry    = null;
                bool          readFeed = false;
                while (parser.Read())
                {
                    readFeed |= parser.CurrentFeed != null;
                    if (parser.CurrentEntry != null)
                    {
                        if (entry != null)
                        {
                            throw new InvalidOperationException(DSClient.Strings.AtomParser_SingleEntry_MultipleFound);
                        }

                        entry = parser.CurrentEntry;
                    }
                }

                if (entry == null)
                {
                    if (readFeed)
                    {
                        throw new InvalidOperationException(DSClient.Strings.AtomParser_SingleEntry_NoneFound);
                    }
                    else
                    {
                        throw new InvalidOperationException(DSClient.Strings.AtomParser_SingleEntry_ExpectedFeedOrEntry);
                    }
                }

                return(MaterializerEntry.GetEntry(entry));
            }
        }
        /// <summary>
        /// This method is for parsing CUD operation payloads which should contain
        /// 1 a single entry
        /// 2 An Error
        /// </summary>
        /// <param name="message">the message for the payload</param>
        /// <param name="responseInfo">The current ResponseInfo object</param>
        /// <param name="expectedType">The expected type</param>
        /// <returns>the MaterializerEntry that was read</returns>
        internal static MaterializerEntry ParseSingleEntityPayload(IODataResponseMessage message, ResponseInfo responseInfo, Type expectedType)
        {
            ODataPayloadKind messageType = ODataPayloadKind.Entry;
            using (ODataMessageReader messageReader = CreateODataMessageReader(message, responseInfo, ref messageType))
            {
                IEdmType edmType = responseInfo.TypeResolver.ResolveExpectedTypeForReading(expectedType);
                ODataReaderWrapper reader = ODataReaderWrapper.Create(messageReader, messageType, edmType, responseInfo.ResponsePipeline);

                FeedAndEntryMaterializerAdapter parser = new FeedAndEntryMaterializerAdapter(messageReader, reader, responseInfo.Model, responseInfo.MergeOption);

                ODataEntry entry = null;
                bool readFeed = false;
                while (parser.Read())
                {
                    readFeed |= parser.CurrentFeed != null;
                    if (parser.CurrentEntry != null)
                    {
                        if (entry != null)
                        {
                            throw new InvalidOperationException(DSClient.Strings.AtomParser_SingleEntry_MultipleFound);
                        }

                        entry = parser.CurrentEntry;
                    }
                }

                if (entry == null)
                {
                    if (readFeed)
                    {
                        throw new InvalidOperationException(DSClient.Strings.AtomParser_SingleEntry_NoneFound);
                    }
                    else
                    {
                        throw new InvalidOperationException(DSClient.Strings.AtomParser_SingleEntry_ExpectedFeedOrEntry);
                    }
                }

                return MaterializerEntry.GetEntry(entry);
            }
        }