/// <summary>
 /// Initializes a new instance of the <see cref="EntryValueMaterializationPolicy" /> class.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="entityTrackingAdapter">The entity tracking adapter.</param>
 /// <param name="lazyPrimitivePropertyConverter">The lazy primitive property converter.</param>
 /// <param name="nextLinkTable">The next link table.</param>
 internal EntryValueMaterializationPolicy(
     IODataMaterializerContext context,
     EntityTrackingAdapter entityTrackingAdapter,
     DSClient.SimpleLazy <PrimitivePropertyConverter> lazyPrimitivePropertyConverter,
     Dictionary <IEnumerable, DataServiceQueryContinuation> nextLinkTable)
     : base(context, lazyPrimitivePropertyConverter)
 {
     this.nextLinkTable         = nextLinkTable;
     this.EntityTrackingAdapter = entityTrackingAdapter;
 }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ODataEntriesEntityMaterializer" /> class.
 /// </summary>
 /// <param name="entries">The entries.</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>
 /// <param name="format">The format.</param>
 public ODataEntriesEntityMaterializer(
     IEnumerable <ODataEntry> entries,
     IODataMaterializerContext materializerContext,
     EntityTrackingAdapter entityTrackingAdapter,
     QueryComponents queryComponents,
     Type expectedType,
     ProjectionPlan materializeEntryPlan,
     ODataFormat format)
     : base(materializerContext, entityTrackingAdapter, queryComponents, expectedType, materializeEntryPlan)
 {
     this.format      = format;
     this.feedEntries = entries.GetEnumerator();
 }
Пример #3
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);
 }
Пример #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ODataLoadNavigationPropertyMaterializer" /> 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>
 /// <param name="responseInfo">LoadProperty Response Info object.</param>
 public ODataLoadNavigationPropertyMaterializer(
     ODataMessageReader odataMessageReader,
     ODataReaderWrapper reader,
     IODataMaterializerContext materializerContext,
     EntityTrackingAdapter entityTrackingAdapter,
     QueryComponents queryComponents,
     Type expectedType,
     ProjectionPlan materializeEntryPlan,
     LoadPropertyResponseInfo responseInfo)
     : base(odataMessageReader, reader, materializerContext, entityTrackingAdapter, queryComponents, expectedType, materializeEntryPlan)
 {
     this.responseInfo = responseInfo;
     this.items        = new List <object>();
 }
Пример #5
0
        public static ODataMaterializer CreateMaterializerForMessage(
            IODataResponseMessage responseMessage,
            ResponseInfo responseInfo,
            Type materializerType,
            QueryComponents queryComponents,
            ProjectionPlan plan,
            ODataPayloadKind payloadKind)
        {
            ODataMessageReader messageReader = CreateODataMessageReader(responseMessage, responseInfo, ref payloadKind);

            ODataMaterializer result;
            IEdmType          edmType = null;

            try
            {
                ODataMaterializerContext materializerContext = new ODataMaterializerContext(responseInfo);

                // Since in V1/V2, astoria client allowed Execute<object> and depended on the typeresolver or the wire type name
                // to get the clr type to materialize. Hence if we see the materializer type as object, we should set the edmtype
                // to null, since there is no expected type.
                if (materializerType != typeof(System.Object))
                {
                    edmType = responseInfo.TypeResolver.ResolveExpectedTypeForReading(materializerType);
                }

                if (payloadKind == ODataPayloadKind.Entry || payloadKind == ODataPayloadKind.Feed)
                {
                    // In V1/V2, we allowed System.Object type to be allowed to pass to ExecuteQuery.
                    // Hence we need to explicitly check for System.Object to allow this
                    if (edmType != null && edmType.TypeKind != EdmTypeKind.Entity)
                    {
                        throw DSClient.Error.InvalidOperation(DSClient.Strings.AtomMaterializer_InvalidNonEntityType(materializerType.FullName));
                    }

                    ODataReaderWrapper       reader = ODataReaderWrapper.Create(messageReader, payloadKind, edmType, responseInfo.ResponsePipeline);
                    EntityTrackingAdapter    entityTrackingAdapter    = new EntityTrackingAdapter(responseInfo.EntityTracker, responseInfo.MergeOption, responseInfo.Model, responseInfo.Context);
                    LoadPropertyResponseInfo loadPropertyResponseInfo = responseInfo as LoadPropertyResponseInfo;

                    if (loadPropertyResponseInfo != null)
                    {
                        result = new ODataLoadNavigationPropertyMaterializer(
                            messageReader,
                            reader,
                            materializerContext,
                            entityTrackingAdapter,
                            queryComponents,
                            materializerType,
                            plan,
                            loadPropertyResponseInfo);
                    }
                    else
                    {
                        result = new ODataReaderEntityMaterializer(
                            messageReader,
                            reader,
                            materializerContext,
                            entityTrackingAdapter,
                            queryComponents,
                            materializerType,
                            plan);
                    }
                }
                else
                {
                    switch (payloadKind)
                    {
                    case ODataPayloadKind.Value:
                        result = new ODataValueMaterializer(messageReader, materializerContext, materializerType, queryComponents.SingleResult);
                        break;

                    case ODataPayloadKind.Collection:
                        result = new ODataCollectionMaterializer(messageReader, materializerContext, materializerType, queryComponents.SingleResult);
                        break;

                    case ODataPayloadKind.Property:
                        // Top level properties cannot be of entity type.
                        if (edmType != null && edmType.TypeKind == EdmTypeKind.Entity)
                        {
                            throw DSClient.Error.InvalidOperation(DSClient.Strings.AtomMaterializer_InvalidEntityType(materializerType.FullName));
                        }

                        result = new ODataPropertyMaterializer(messageReader, materializerContext, materializerType, queryComponents.SingleResult);
                        break;

                    case ODataPayloadKind.EntityReferenceLinks:
                    case ODataPayloadKind.EntityReferenceLink:
                        result = new ODataLinksMaterializer(messageReader, materializerContext, materializerType, queryComponents.SingleResult);
                        break;

                    case ODataPayloadKind.Error:
                        var odataError = messageReader.ReadError();
                        throw new ODataErrorException(odataError.Message, odataError);

                    default:
                        throw DSClient.Error.InvalidOperation(DSClient.Strings.AtomMaterializer_InvalidResponsePayload(responseInfo.DataNamespace));
                    }
                }

                return(result);
            }
            catch (Exception ex)
            {
                if (CommonUtil.IsCatchableExceptionType(ex))
                {
                    // Dispose the message reader in all error scenarios.
                    messageReader.Dispose();
                }

                throw;
            }
        }