Ejemplo n.º 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);
 }
Ejemplo n.º 2
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.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));
            }
        }