/// <summary>Initializes a new <see cref="PlainXmlDeserializer"/> based on the settings for another one.</summary> /// <param name="reader">Reader for content.</param> /// <param name="deserializer">Parent deserializer.</param> /// <param name="propertiesApplied">Properties already applied based on content</param> internal PlainXmlDeserializer(XmlReader reader, Deserializer deserializer, EpmContentDeSerializer.EpmAppliedPropertyInfo propertiesApplied) : base(deserializer) { Debug.Assert(reader != null, "reader != null"); this.xmlReader = reader; Debug.Assert(propertiesApplied != null, "Requires valid collection for applied properties"); this.propertiesApplied = propertiesApplied; this.currentPathPrefix = String.Empty; // this.xmlReaderOwned = false; }
/// <summary> /// Matches the targetSegment with properties already applied and if finds something already applied considers it a match /// </summary> /// <param name="targetSegment">Target segment for which existing property application is checked for</param> /// <param name="propertiesApplied">Properties already applied based on content</param> /// <returns>true if already the property for the current segment has been applied</returns> internal static bool Match(EpmTargetPathSegment targetSegment, EpmContentDeSerializer.EpmAppliedPropertyInfo propertiesApplied) { if (!targetSegment.EpmInfo.Attribute.KeepInContent) { return propertiesApplied.Lookup(targetSegment.EpmInfo.Attribute.SourcePath); } else { return true; } }
/// <summary>Constructor</summary> /// <param name="item"><see cref="SyndicationItem"/> from which to read EPM content</param> /// <param name="state">State of the deserializer</param> internal EpmContentDeSerializerBase(SyndicationItem item, EpmContentDeSerializer.EpmContentDeserializerState state) { this.item = item; this.state = state; }
/// <summary>Applies the properties in the plain XML content to the specified resource.</summary> /// <param name="item">item to read from.</param> /// <param name='resourceType'>Type of resource whose values are being set.</param> /// <param name="propertiesApplied">Properties that have been applied to the <paramref name="resource"/></param> /// <param name='resource'>Target resource.</param> private void ApplyProperties(SyndicationItem item, ResourceType resourceType, EpmContentDeSerializer.EpmAppliedPropertyInfo propertiesApplied, object resource) { Debug.Assert(item != null, "item != null"); Debug.Assert(resourceType != null, "resourceType != null"); Debug.Assert(propertiesApplied != null, "propertiesApplied != null"); Debug.Assert(resource != null, "resource != null"); using (XmlReader propertiesFromEntry = GetPropertiesReaderFromEntry(item)) using (XmlReader propertiesFromContent = GetPropertiesReaderFromContent(item)) { XmlReader reader = null; if (resourceType.IsMediaLinkEntry) { if (propertiesFromContent != null) { // The server is expecting a MLE payload, however we found a <m:properties> element under the <atom:content> element. // The client must assumed the resource type is a non-MLE type and serialized as such. // // We must throw here otherwise the client would falsely assume all the properties are correctly deserialized on // the server where as in fact the properties element is under the wrong node. throw DataServiceException.CreateBadRequestError(Strings.DataServiceException_GeneralError); } reader = propertiesFromEntry; } else { if (propertiesFromEntry != null) { // The server is expecting a non-MLE payload, however we found a <m:properties> element under the <entry> element. // The client must assumed the resource type is a MLE type and serialized as such. // // We must throw here otherwise the client would falsely assume all the properties are correctly deserialized on // the server where as in fact the properties element is under the wrong node. throw DataServiceException.CreateBadRequestError(Strings.DataServiceException_GeneralError); } reader = propertiesFromContent; } if (reader != null) { reader.ReadStartElement(XmlConstants.AtomPropertiesElementName, XmlConstants.DataWebMetadataNamespace); PlainXmlDeserializer.ApplyContent(this, reader, resourceType, resource, propertiesApplied, this.MaxObjectCount); } } }
/// <summary>Constructor</summary> /// <param name="item"><see cref="SyndicationItem"/> to read content from</param> /// <param name="state">State of the deserializer</param> internal EpmCustomContentDeSerializer(SyndicationItem item, EpmContentDeSerializer.EpmContentDeserializerState state) : base(item, state) { }
/// <summary>Applies properties from the reader to the specified resource.</summary> /// <param name="deserializer">Deserializer which is driving the <paramref name="reader"/>.</param> /// <param name='reader'>XmlReader to read from.</param> /// <param name='resourceType'>Type of resource.</param> /// <param name='resource'>Resource to set value on.</param> /// <param name="propertiesApplied">Properties already applied based on content</param> /// <param name="currentObjectCount">current object count for this operation.</param> /// <remarks> /// This method will end as soon as it find something that is not an /// XML element to process. /// </remarks> internal static void ApplyContent(Deserializer deserializer, XmlReader reader, ResourceType resourceType, object resource, EpmContentDeSerializer.EpmAppliedPropertyInfo propertiesApplied, int currentObjectCount) { Debug.Assert(deserializer != null, "deserializer != null"); Debug.Assert(reader != null, "reader != null"); using (PlainXmlDeserializer xml = new PlainXmlDeserializer(reader, deserializer, propertiesApplied)) { // Initialize the new deserializer instance with the current object count xml.UpdateObjectCount(currentObjectCount); // load all the properties xml.ApplyContent(xml.xmlReader, resourceType, resource); // After all the properties have been loaded, initialize the current deserializer value with the object count deserializer.UpdateObjectCount(xml.MaxObjectCount); } }