Ejemplo n.º 1
0
 internal AtomMaterializerLog(ResponseInfo responseInfo)
 {
     this.responseInfo = responseInfo;
     this.mergeOption = responseInfo.MergeOption;
     this.identityStack = new Dictionary<string, ODataEntry>(EqualityComparer<string>.Default);
     this.links = new List<LinkDescriptor>();
 }
Ejemplo n.º 2
0
 internal static MaterializerEntry ParseSingleEntityPayload(IODataResponseMessage message, ResponseInfo responseInfo, Type expectedType)
 {
     ODataPayloadKind payloadKind = ODataPayloadKind.Entry;
     using (ODataMessageReader reader = ODataMaterializer.CreateODataMessageReader(message, responseInfo, false, ref payloadKind))
     {
         IEdmType orCreateEdmType = ClientEdmModel.GetModel(responseInfo.MaxProtocolVersion).GetOrCreateEdmType(expectedType);
         ODataReader reader2 = ODataMaterializer.CreateODataReader(reader, payloadKind, orCreateEdmType, responseInfo.MaxProtocolVersion);
         ODataFeedOrEntryReader reader3 = new ODataFeedOrEntryReader(reader2, responseInfo);
         ODataEntry currentEntry = null;
         bool flag = false;
         while (reader3.Read())
         {
             flag |= reader3.CurrentFeed != null;
             if (reader3.CurrentEntry != null)
             {
                 if (currentEntry != null)
                 {
                     throw new InvalidOperationException(System.Data.Services.Client.Strings.AtomParser_SingleEntry_MultipleFound);
                 }
                 currentEntry = reader3.CurrentEntry;
             }
         }
         if (currentEntry == null)
         {
             if (flag)
             {
                 throw new InvalidOperationException(System.Data.Services.Client.Strings.AtomParser_SingleEntry_NoneFound);
             }
             throw new InvalidOperationException(System.Data.Services.Client.Strings.AtomParser_SingleEntry_ExpectedFeedOrEntry);
         }
         return MaterializerEntry.GetEntry(currentEntry);
     }
 }
Ejemplo n.º 3
0
 internal MaterializeAtom(ResponseInfo responseInfo, QueryComponents queryComponents, ProjectionPlan plan, IODataResponseMessage responseMessage, ODataPayloadKind payloadKind)
 {
     Type type;
     this.responseInfo = responseInfo;
     this.elementType = queryComponents.LastSegmentType;
     this.MergeOptionValue = responseInfo.MergeOption;
     this.expectingPrimitiveValue = PrimitiveType.IsKnownNullableType(this.elementType);
     Type materializerType = GetTypeForMaterializer(this.expectingPrimitiveValue, this.elementType, responseInfo.MaxProtocolVersion, out type);
     this.materializer = ODataMaterializer.CreateMaterializerForMessage(responseMessage, responseInfo, materializerType, queryComponents, plan, payloadKind);
 }
Ejemplo n.º 4
0
 internal MaterializeAtom(ResponseInfo responseInfo, IEnumerable<ODataEntry> entries, Type elementType)
 {
     Type type;
     this.responseInfo = responseInfo;
     this.elementType = elementType;
     this.MergeOptionValue = responseInfo.MergeOption;
     this.expectingPrimitiveValue = PrimitiveType.IsKnownNullableType(elementType);
     Type expectedType = GetTypeForMaterializer(this.expectingPrimitiveValue, this.elementType, responseInfo.MaxProtocolVersion, out type);
     QueryComponents queryComponents = new QueryComponents(null, Util.DataServiceVersionEmpty, elementType, null, null);
     this.materializer = new ODataEntriesEntityMaterializer(entries, responseInfo, queryComponents, expectedType, null);
 }
Ejemplo n.º 5
0
        internal static MaterializeAtom Materialize(
            ResponseInfo responseInfo,
            QueryComponents queryComponents,
            ProjectionPlan plan,
            string contentType,
            IODataResponseMessage message,
            ODataPayloadKind expectedPayloadKind)
        {
            Debug.Assert(null != queryComponents, "querycomponents");
            Debug.Assert(null != message, "message");

            // If there is no content (For e.g. /Customers(1)/BestFriend is null), we need to return empty results.
            if (message.StatusCode == (int)HttpStatusCode.NoContent || String.IsNullOrEmpty(contentType))
            {
                return(MaterializeAtom.EmptyResults);
            }

            return(new MaterializeAtom(responseInfo, queryComponents, plan, message, expectedPayloadKind));
        }
Ejemplo n.º 6
0
 private void MaterializeResponse(EntityDescriptor entityDescriptor, ResponseInfo responseInfo, string etag)
 {
     using (MaterializeAtom atom = this.GetMaterializer(entityDescriptor, responseInfo))
     {
         atom.SetInsertingObject(entityDescriptor.Entity);
         object obj2 = null;
         foreach (object obj3 in atom)
         {
             if (obj2 != null)
             {
                 System.Data.Services.Client.Error.ThrowInternalError(InternalError.MaterializerReturningMoreThanOneEntity);
             }
             obj2 = obj3;
         }
         if (entityDescriptor.GetLatestETag() == null)
         {
             entityDescriptor.ETag = etag;
         }
     }
 }
Ejemplo n.º 7
0
        internal static ODataMessageReaderSettings CreateODataMessageReaderSettings(ResponseInfo responseInfo, Func <ODataEntry, XmlReader, Uri, XmlReader> entryXmlCustomizer, bool projectionQuery)
        {
            ODataMessageReaderSettings settings = new ODataMessageReaderSettings();

            responseInfo.TypeResolver = new TypeResolver(responseInfo, projectionQuery);
            settings.EnableWcfDataServicesClientBehavior(new Func <IEdmType, string, IEdmType>(responseInfo.TypeResolver.ResolveWireTypeName), responseInfo.DataNamespace, CommonUtil.UriToString(responseInfo.TypeScheme), entryXmlCustomizer);
            settings.BaseUri = (responseInfo.BaseUriResolver.GetRawBaseUriValue() != null) ? responseInfo.BaseUriResolver.GetBaseUriWithSlash() : null;
            settings.UndeclaredPropertyBehaviorKinds = ODataUndeclaredPropertyBehaviorKinds.ReportUndeclaredLinkProperty;
            settings.MaxProtocolVersion = CommonUtil.ConvertToODataVersion(responseInfo.MaxProtocolVersion);
            if (responseInfo.IgnoreMissingProperties)
            {
                settings.UndeclaredPropertyBehaviorKinds |= ODataUndeclaredPropertyBehaviorKinds.IgnoreUndeclaredValueProperty;
            }
            settings.MessageQuotas.MaxEntityPropertyMappingsPerType = 0x7fffffff;
            settings.MessageQuotas.MaxNestingDepth           = 0x7fffffff;
            settings.MessageQuotas.MaxOperationsPerChangeset = 0x7fffffff;
            settings.MessageQuotas.MaxPartsPerBatch          = 0x7fffffff;
            settings.MessageQuotas.MaxReceivedMessageSize    = 0x7fffffffffffffffL;
            return(settings);
        }
Ejemplo n.º 8
0
        private void HandleOperationResponseData(HttpWebResponse response, Stream responseStream)
        {
            Version       version;
            Func <Stream> getResponseStream     = null;
            Dictionary <string, string> headers = WebUtil.WrapResponseHeaders(response);
            Descriptor        descriptor        = base.ChangedEntries[base.entryIndex];
            MaterializerEntry entry             = null;
            Exception         exception         = BaseSaveResult.HandleResponse(base.RequestInfo, response.StatusCode, response.Headers["DataServiceVersion"], () => responseStream, false, out version);

            if (((responseStream != null) && (descriptor.DescriptorKind == DescriptorKind.Entity)) && (exception == null))
            {
                EntityDescriptor entityDescriptor = (EntityDescriptor)descriptor;
                if (((entityDescriptor.State == EntityStates.Added) || (entityDescriptor.StreamState == EntityStates.Added)) || ((entityDescriptor.State == EntityStates.Modified) || (entityDescriptor.StreamState == EntityStates.Modified)))
                {
                    try
                    {
                        ResponseInfo responseInfo = base.CreateResponseInfo(entityDescriptor);
                        if (getResponseStream == null)
                        {
                            getResponseStream = () => responseStream;
                        }
                        HttpWebResponseMessage message = new HttpWebResponseMessage(response, getResponseStream);
                        entry = ODataReaderEntityMaterializer.ParseSingleEntityPayload(message, responseInfo, entityDescriptor.Entity.GetType());
                        entityDescriptor.TransientEntityDescriptor = entry.EntityDescriptor;
                    }
                    catch (Exception exception2)
                    {
                        exception = exception2;
                        if (!CommonUtil.IsCatchableExceptionType(exception2))
                        {
                            throw;
                        }
                    }
                }
            }
            this.cachedResponses.Add(new CachedResponse(descriptor, headers, response.StatusCode, version, (entry != null) ? entry.Entry : null, exception));
            if (exception != null)
            {
                descriptor.SaveError = exception;
            }
        }
Ejemplo n.º 9
0
#pragma warning restore 649
#endif

        #endregion Private fields

        /// <summary>
        /// constructor
        /// </summary>
        /// <param name="responseInfo">originating context</param>
        /// <param name="queryComponents">Query components (projection, expected type)</param>
        /// <param name="plan">Projection plan (if compiled in an earlier query).</param>
        /// <param name="responseMessage">responseMessage</param>
        /// <param name="payloadKind">The kind of the payload to materialize.</param>
        internal MaterializeAtom(
            ResponseInfo responseInfo,
            QueryComponents queryComponents,
            ProjectionPlan plan,
            IODataResponseMessage responseMessage,
            ODataPayloadKind payloadKind)
        {
            Debug.Assert(queryComponents != null, "queryComponents != null");

            this.responseInfo            = responseInfo;
            this.elementType             = queryComponents.LastSegmentType;
            this.expectingPrimitiveValue = PrimitiveType.IsKnownNullableType(elementType);

            Debug.Assert(responseMessage != null, "Response message is null! Did you mean to use Materializer.ResultsWrapper/EmptyResults?");
            this.responseMessage = responseMessage;

            Type implementationType;
            Type materializerType = GetTypeForMaterializer(this.expectingPrimitiveValue, this.elementType, responseInfo.Model, out implementationType);

            this.materializer = ODataMaterializer.CreateMaterializerForMessage(responseMessage, responseInfo, materializerType, queryComponents, plan, payloadKind);
        }
Ejemplo n.º 10
0
 protected override MaterializeAtom GetMaterializer(EntityDescriptor entityDescriptor, ResponseInfo responseInfo)
 {
     return(new MaterializeAtom(responseInfo, new QueryComponents(null, Util.DataServiceVersionEmpty, entityDescriptor.Entity.GetType(), null, null), null, this.currentOperationResponse.CreateResponseMessage(), ODataPayloadKind.Entry));
 }
Ejemplo n.º 11
0
        protected static object CreateCollectionInstance(ODataProperty collectionProperty, Type userCollectionType, System.Data.Services.Client.ResponseInfo responseInfo)
        {
            object obj2;
            ODataCollectionValue value2     = collectionProperty.Value as ODataCollectionValue;
            ClientTypeAnnotation annotation = responseInfo.TypeResolver.ResolveEdmTypeName(userCollectionType, value2.TypeName);

            if (IsDataServiceCollection(annotation.ElementType))
            {
                throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.AtomMaterializer_DataServiceCollectionNotSupportedForNonEntities);
            }
            try
            {
                obj2 = annotation.CreateInstance();
            }
            catch (MissingMethodException exception)
            {
                throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.AtomMaterializer_NoParameterlessCtorForCollectionProperty(collectionProperty.Name, annotation.ElementTypeName), exception);
            }
            return(obj2);
        }
Ejemplo n.º 12
0
 protected override MaterializeAtom GetMaterializer(EntityDescriptor entityDescriptor, ResponseInfo responseInfo)
 {
     return(new MaterializeAtom(responseInfo, new ODataEntry[] { this.cachedResponse.Entry }, entityDescriptor.Entity.GetType()));
 }
Ejemplo n.º 13
0
 protected override MaterializeAtom GetMaterializer(EntityDescriptor entityDescriptor, ResponseInfo responseInfo)
 {
     return new MaterializeAtom(responseInfo, new QueryComponents(null, Util.DataServiceVersionEmpty, entityDescriptor.Entity.GetType(), null, null), null, this.currentOperationResponse.CreateResponseMessage(), ODataPayloadKind.Entry);
 }
Ejemplo n.º 14
0
 public ODataMessageReaderMaterializer(ODataMessageReader reader, ResponseInfo info, Type expectedType, bool? singleResult) : base(info, expectedType)
 {
     this.messageReader = reader;
     this.SingleResult = singleResult;
 }
Ejemplo n.º 15
0
 public ODataEntriesEntityMaterializer(IEnumerable<ODataEntry> entries, ResponseInfo responseInfo, QueryComponents queryComponents, Type expectedType, ProjectionPlan materializeEntryPlan) : base(responseInfo, queryComponents, expectedType, materializeEntryPlan)
 {
     this.feedEntries = entries.GetEnumerator();
 }
Ejemplo n.º 16
0
        protected static ODataMessageReader CreateODataMessageReader(IODataResponseMessage responseMessage, System.Data.Services.Client.ResponseInfo responseInfo, bool projectionQuery, ref ODataPayloadKind payloadKind)
        {
            Func <ODataEntry, XmlReader, Uri, XmlReader> entryXmlCustomizer = null;

            if (responseInfo.HasReadingEntityHandlers)
            {
                entryXmlCustomizer = new Func <ODataEntry, XmlReader, Uri, XmlReader>(ODataMaterializer.EntryXmlCustomizer);
            }
            ODataMessageReaderSettings settings = WebUtil.CreateODataMessageReaderSettings(responseInfo, entryXmlCustomizer, projectionQuery);
            ODataMessageReader         reader   = new ODataMessageReader(responseMessage, settings, ClientEdmModel.GetModel(responseInfo.MaxProtocolVersion));

            if (payloadKind == ODataPayloadKind.Unsupported)
            {
                List <ODataPayloadKindDetectionResult> source = reader.DetectPayloadKind().ToList <ODataPayloadKindDetectionResult>();
                if (source.Count == 0)
                {
                    throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.AtomMaterializer_InvalidResponsePayload(responseInfo.DataNamespace));
                }
                ODataPayloadKindDetectionResult result = source.FirstOrDefault <ODataPayloadKindDetectionResult>(delegate(ODataPayloadKindDetectionResult k) {
                    if (k.PayloadKind != ODataPayloadKind.EntityReferenceLink)
                    {
                        return(k.PayloadKind == ODataPayloadKind.EntityReferenceLinks);
                    }
                    return(true);
                });
                if (result == null)
                {
                    result = source.First <ODataPayloadKindDetectionResult>();
                }
                if ((result.Format != ODataFormat.Atom) && (result.Format != ODataFormat.RawValue))
                {
                    throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.AtomMaterializer_InvalidContentTypeEncountered(responseMessage.GetHeader("Content-Type")));
                }
                payloadKind = result.PayloadKind;
            }
            return(reader);
        }
Ejemplo n.º 17
0
 public ODataLinksMaterializer(ODataMessageReader reader, ResponseInfo info, Type expectedType, bool? singleResult) : base(reader, info, expectedType, singleResult)
 {
 }
Ejemplo n.º 18
0
 protected static void ApplyDataValues(ClientTypeAnnotation type, IEnumerable <ODataProperty> properties, bool ignoreMissingProperties, System.Data.Services.Client.ResponseInfo responseInfo, object instance)
 {
     foreach (ODataProperty property in properties)
     {
         ApplyDataValue(type, property, ignoreMissingProperties, responseInfo, instance);
     }
 }
Ejemplo n.º 19
0
 protected abstract MaterializeAtom GetMaterializer(EntityDescriptor entityDescriptor, ResponseInfo responseInfo);
Ejemplo n.º 20
0
 private void MaterializeResponse(EntityDescriptor entityDescriptor, ResponseInfo responseInfo, string etag)
 {
     using (MaterializeAtom atom = this.GetMaterializer(entityDescriptor, responseInfo))
     {
         atom.SetInsertingObject(entityDescriptor.Entity);
         object obj2 = null;
         foreach (object obj3 in atom)
         {
             if (obj2 != null)
             {
                 System.Data.Services.Client.Error.ThrowInternalError(InternalError.MaterializerReturningMoreThanOneEntity);
             }
             obj2 = obj3;
         }
         if (entityDescriptor.GetLatestETag() == null)
         {
             entityDescriptor.ETag = etag;
         }
     }
 }
Ejemplo n.º 21
0
 protected override MaterializeAtom GetMaterializer(EntityDescriptor entityDescriptor, ResponseInfo responseInfo)
 {
     return new MaterializeAtom(responseInfo, new ODataEntry[] { this.cachedResponse.Entry }, entityDescriptor.Entity.GetType());
 }
Ejemplo n.º 22
0
        protected static void ApplyDataValue(ClientTypeAnnotation type, ODataProperty property, bool ignoreMissingProperties, System.Data.Services.Client.ResponseInfo responseInfo, object instance)
        {
            ClientPropertyAnnotation annotation = type.GetProperty(property.Name, ignoreMissingProperties);

            if (annotation != null)
            {
                if (annotation.IsPrimitiveOrComplexCollection)
                {
                    if (property.Value == null)
                    {
                        throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.Collection_NullCollectionNotSupported(property.Name));
                    }
                    if (property.Value is string)
                    {
                        throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.Deserialize_MixedTextWithComment);
                    }
                    if (property.Value is ODataComplexValue)
                    {
                        throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.AtomMaterializer_InvalidCollectionItem(property.Name));
                    }
                    object obj2 = annotation.GetValue(instance);
                    if (obj2 == null)
                    {
                        obj2 = CreateCollectionInstance(property, annotation.PropertyType, responseInfo);
                        annotation.SetValue(instance, obj2, property.Name, false);
                    }
                    else
                    {
                        annotation.ClearBackingICollectionInstance(obj2);
                    }
                    ApplyCollectionDataValues(property, ignoreMissingProperties, responseInfo, obj2, annotation.PrimitiveOrComplexCollectionItemType, new Action <object, object>(annotation.AddValueToBackingICollectionInstance));
                }
                else
                {
                    object            obj3   = property.Value;
                    ODataComplexValue value2 = obj3 as ODataComplexValue;
                    if ((obj3 != null) && (value2 != null))
                    {
                        if (!annotation.EdmProperty.Type.IsComplex())
                        {
                            throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.Deserialize_ExpectingSimpleValue);
                        }
                        bool                 flag  = false;
                        ClientEdmModel       model = ClientEdmModel.GetModel(responseInfo.MaxProtocolVersion);
                        ClientTypeAnnotation clientTypeAnnotation = model.GetClientTypeAnnotation(model.GetOrCreateEdmType(annotation.PropertyType));
                        object               obj4 = annotation.GetValue(instance);
                        if (obj4 == null)
                        {
                            obj4 = clientTypeAnnotation.CreateInstance();
                            flag = true;
                        }
                        MaterializeDataValues(clientTypeAnnotation, value2.Properties, ignoreMissingProperties);
                        ApplyDataValues(clientTypeAnnotation, value2.Properties, ignoreMissingProperties, responseInfo, obj4);
                        if (flag)
                        {
                            annotation.SetValue(instance, obj4, property.Name, true);
                        }
                    }
                    else
                    {
                        MaterializePrimitiveDataValue(annotation.NullablePropertyType, property);
                        annotation.SetValue(instance, property.GetMaterializedValue(), property.Name, true);
                    }
                }
            }
        }
Ejemplo n.º 23
0
        protected static bool MaterializePrimitiveDataValue(Type type, string wireTypeName, object value, System.Data.Services.Client.ResponseInfo responseInfo, Func <string> throwOnNullMessage, out object materializedValue)
        {
            PrimitiveType type3;
            Type          clrType = Nullable.GetUnderlyingType(type) ?? type;
            bool          flag    = PrimitiveType.TryGetPrimitiveType(clrType, out type3);

            if (!flag)
            {
                flag = PrimitiveType.TryGetPrimitiveType(responseInfo.TypeResolver.ResolveEdmTypeName(type, wireTypeName).ElementType, out type3);
            }
            if (flag)
            {
                if (value == null)
                {
                    if (!ClientTypeUtil.CanAssignNull(type))
                    {
                        throw new InvalidOperationException(throwOnNullMessage());
                    }
                    materializedValue = null;
                }
                else
                {
                    materializedValue = ConvertPrimitiveValue(value, clrType);
                }
                return(true);
            }
            materializedValue = null;
            return(false);
        }
Ejemplo n.º 24
0
        protected static void MaterializeComplexTypeProperty(Type propertyType, ODataComplexValue complexValue, bool ignoreMissingProperties, System.Data.Services.Client.ResponseInfo responseInfo)
        {
            object instance = null;

            if ((complexValue != null) && !complexValue.HasMaterializedValue())
            {
                ClientTypeAnnotation actualType = null;
                if (WebUtil.IsWireTypeCollection(complexValue.TypeName))
                {
                    actualType = responseInfo.TypeResolver.ResolveEdmTypeName(propertyType, complexValue.TypeName);
                }
                else
                {
                    ClientEdmModel model = ClientEdmModel.GetModel(responseInfo.MaxProtocolVersion);
                    actualType = model.GetClientTypeAnnotation(model.GetOrCreateEdmType(propertyType));
                }
                instance = Util.ActivatorCreateInstance(propertyType, new object[0]);
                MaterializeDataValues(actualType, complexValue.Properties, ignoreMissingProperties);
                ApplyDataValues(actualType, complexValue.Properties, ignoreMissingProperties, responseInfo, instance);
                complexValue.SetMaterializedValue(instance);
            }
        }
Ejemplo n.º 25
0
        protected static void ApplyCollectionDataValues(ODataProperty collectionProperty, bool ignoreMissingProperties, System.Data.Services.Client.ResponseInfo responseInfo, object collectionInstance, Type collectionItemType, Action <object, object> AddValueToBackingICollectionInstance)
        {
            ODataCollectionValue value2 = collectionProperty.Value as ODataCollectionValue;

            if (value2.Items != null)
            {
                bool           flag  = PrimitiveType.IsKnownNullableType(collectionItemType);
                ClientEdmModel model = ClientEdmModel.GetModel(responseInfo.MaxProtocolVersion);
                foreach (object obj2 in value2.Items)
                {
                    if (obj2 == null)
                    {
                        throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.Collection_NullCollectionItemsNotSupported);
                    }
                    if (flag)
                    {
                        object obj3;
                        if ((obj2 is ODataComplexValue) || (obj2 is ODataCollectionValue))
                        {
                            throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.Collection_ComplexTypesInCollectionOfPrimitiveTypesNotAllowed);
                        }
                        MaterializePrimitiveDataValue(collectionItemType, value2.TypeName, obj2, responseInfo, () => System.Data.Services.Client.Strings.Collection_NullCollectionItemsNotSupported, out obj3);
                        AddValueToBackingICollectionInstance(collectionInstance, ConvertPrimitiveValue(obj2, collectionItemType));
                    }
                    else
                    {
                        ODataComplexValue value3 = obj2 as ODataComplexValue;
                        if (value3 == null)
                        {
                            throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.Collection_PrimitiveTypesInCollectionOfComplexTypesNotAllowed);
                        }
                        ClientTypeAnnotation clientTypeAnnotation = model.GetClientTypeAnnotation(model.GetOrCreateEdmType(collectionItemType));
                        object instance = clientTypeAnnotation.CreateInstance();
                        ApplyDataValues(clientTypeAnnotation, value3.Properties, ignoreMissingProperties, responseInfo, instance);
                        AddValueToBackingICollectionInstance(collectionInstance, instance);
                    }
                }
            }
            collectionProperty.SetMaterializedValue(collectionInstance);
        }
Ejemplo n.º 26
0
 public ODataFeedOrEntryReader(ODataReader reader, ResponseInfo responseInfo)
 {
     this.reader = reader;
     this.responseInfo = responseInfo;
     this.currentEntry = null;
     this.currentFeed = null;
     this.feedEntries = null;
 }
Ejemplo n.º 27
0
 public ODataReaderEntityMaterializer(ODataMessageReader odataMessageReader, ODataReader reader, ResponseInfo responseInfo, QueryComponents queryComponents, Type expectedType, ProjectionPlan materializeEntryPlan) : base(responseInfo, queryComponents, expectedType, materializeEntryPlan)
 {
     this.messageReader = odataMessageReader;
     this.itemReader = new ODataFeedOrEntryReader(reader, responseInfo);
 }
Ejemplo n.º 28
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ODataMessageReadingHelper"/> class.
 /// </summary>
 /// <param name="responseInfo">The response info.</param>
 internal ODataMessageReadingHelper(ResponseInfo responseInfo)
 {
     Debug.Assert(responseInfo != null, "responseInfo != null");
     this.responseInfo = responseInfo;
 }
Ejemplo n.º 29
0
        public static ODataMaterializer CreateMaterializerForMessage(IODataResponseMessage responseMessage, System.Data.Services.Client.ResponseInfo responseInfo, Type materializerType, QueryComponents queryComponents, ProjectionPlan plan, ODataPayloadKind payloadKind)
        {
            ODataMaterializer materializer2;
            bool projectionQuery             = (plan != null) || (queryComponents.Projection != null);
            ODataMessageReader messageReader = CreateODataMessageReader(responseMessage, responseInfo, projectionQuery, ref payloadKind);
            IEdmType           expectedType  = null;

            try
            {
                ODataMaterializer materializer;
                if (materializerType != typeof(object))
                {
                    expectedType = ClientEdmModel.GetModel(responseInfo.MaxProtocolVersion).GetOrCreateEdmType(materializerType);
                }
                if ((payloadKind == ODataPayloadKind.Entry) || (payloadKind == ODataPayloadKind.Feed))
                {
                    if ((expectedType != null) && (expectedType.TypeKind != EdmTypeKind.Entity))
                    {
                        throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.AtomMaterializer_InvalidNonEntityType(materializerType.FullName));
                    }
                    ODataReader reader = CreateODataReader(messageReader, payloadKind, expectedType, responseInfo.MaxProtocolVersion);
                    materializer = new ODataReaderEntityMaterializer(messageReader, reader, responseInfo, queryComponents, materializerType, plan);
                }
                else
                {
                    switch (payloadKind)
                    {
                    case ODataPayloadKind.Property:
                        if ((expectedType != null) && (expectedType.TypeKind == EdmTypeKind.Entity))
                        {
                            throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.AtomMaterializer_InvalidEntityType(materializerType.FullName));
                        }
                        break;

                    case ODataPayloadKind.EntityReferenceLink:
                    case ODataPayloadKind.EntityReferenceLinks:
                        materializer = new ODataLinksMaterializer(messageReader, responseInfo, materializerType, queryComponents.SingleResult);
                        goto Label_013A;

                    case ODataPayloadKind.Value:
                        materializer = new ODataValueMaterializer(messageReader, responseInfo, materializerType, queryComponents.SingleResult);
                        goto Label_013A;

                    case ODataPayloadKind.BinaryValue:
                    case ODataPayloadKind.Collection:
                    case ODataPayloadKind.ServiceDocument:
                    case ODataPayloadKind.MetadataDocument:
                        goto Label_0129;

                    case ODataPayloadKind.Error:
                    {
                        ODataError error = messageReader.ReadError();
                        throw new ODataErrorException(error.Message, error);
                    }

                    default:
                        goto Label_0129;
                    }
                    materializer = new ODataPropertyMaterializer(messageReader, responseInfo, materializerType, queryComponents.SingleResult);
                }
                goto Label_013A;
Label_0129:
                throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.AtomMaterializer_InvalidResponsePayload(responseInfo.DataNamespace));
Label_013A:
                materializer2 = materializer;
            }
            catch (Exception exception)
            {
                if (CommonUtil.IsCatchableExceptionType(exception))
                {
                    messageReader.Dispose();
                }
                throw;
            }
            return(materializer2);
        }
Ejemplo n.º 30
0
 protected abstract MaterializeAtom GetMaterializer(EntityDescriptor entityDescriptor, ResponseInfo responseInfo);
Ejemplo n.º 31
0
 protected ODataMaterializer(System.Data.Services.Client.ResponseInfo responseInfo, Type expectedType)
 {
     this.ResponseInfo  = responseInfo;
     this.ExpectedType  = expectedType;
     this.nextLinkTable = new Dictionary <IEnumerable, DataServiceQueryContinuation>(System.Data.Services.Client.ReferenceEqualityComparer <IEnumerable> .Instance);
 }