/// <summary> /// Reads all instances of relationship PolicyHasSettings. /// </summary> /// <remarks> /// The caller will position the reader at the open tag of the first XML element inside the relationship tag, so it can be /// either the first instance, or a bogus tag. This method will deserialize all instances and ignore all bogus tags. When the /// method returns, the reader will be positioned at the end tag of the relationship (or EOF if somehow that happens). /// </remarks> /// <param name="serializationContext">Serialization context.</param> /// <param name="element">In-memory CustomizationPolicySchema instance that will get the deserialized data.</param> /// <param name="reader">XmlReader to read serialized data from.</param> private static void ReadPolicyHasSettingsInstances(DslModeling::SerializationContext serializationContext, CustomizationPolicySchema element, global::System.Xml.XmlReader reader) { while (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element) { DslModeling::DomainClassXmlSerializer newCustomizableSettingSchemaOfPolicyHasSettingsSerializer = serializationContext.Directory.GetSerializer(CustomizableSettingSchema.DomainClassId); global::System.Diagnostics.Debug.Assert(newCustomizableSettingSchemaOfPolicyHasSettingsSerializer != null, "Cannot find serializer for CustomizableSettingSchema!"); CustomizableSettingSchema newCustomizableSettingSchemaOfPolicyHasSettings = newCustomizableSettingSchemaOfPolicyHasSettingsSerializer.TryCreateInstance(serializationContext, reader, element.Partition) as CustomizableSettingSchema; if (newCustomizableSettingSchemaOfPolicyHasSettings != null) { element.Settings.Add(newCustomizableSettingSchemaOfPolicyHasSettings); DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer (newCustomizableSettingSchemaOfPolicyHasSettings.GetDomainClass().Id); global::System.Diagnostics.Debug.Assert (targetSerializer != null, "Cannot find serializer for " + newCustomizableSettingSchemaOfPolicyHasSettings.GetDomainClass().Name + "!"); targetSerializer.Read(serializationContext, newCustomizableSettingSchemaOfPolicyHasSettings, reader); } else { global::System.Type typeofPolicyHasSettings = typeof(PolicyHasSettings); DslModeling::DomainRelationshipXmlSerializer newPolicyHasSettingsSerializer = serializationContext.Directory.GetSerializer(PolicyHasSettings.DomainClassId) as DslModeling::DomainRelationshipXmlSerializer; global::System.Diagnostics.Debug.Assert(newPolicyHasSettingsSerializer != null, "Cannot find serializer for PolicyHasSettings!"); PolicyHasSettings newPolicyHasSettings = newPolicyHasSettingsSerializer.TryCreateInstance (serializationContext, reader, element.Partition) as PolicyHasSettings; if (newPolicyHasSettings != null) { if (newPolicyHasSettings.GetType() == typeofPolicyHasSettings) { // The relationship should be serialized in short-form. PatternModelSerializationBehaviorSerializationMessages.ExpectingShortFormRelationship(serializationContext, reader, typeof(PolicyHasSettings)); } DslModeling::DomainRoleInfo.SetRolePlayer (newPolicyHasSettings, PolicyHasSettings.CustomizationPolicySchemaDomainRoleId, element); DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer (newPolicyHasSettings.GetDomainClass().Id); global::System.Diagnostics.Debug.Assert (targetSerializer != null, "Cannot find serializer for " + newPolicyHasSettings.GetDomainClass().Name + "!"); targetSerializer.Read(serializationContext, newPolicyHasSettings, reader); } else { // Unknown element, skip DslModeling::SerializationUtilities.Skip(reader); } } } }
private static void WriteChildElements(DslModeling::SerializationContext serializationContext, CustomizationPolicySchema element, global::System.Xml.XmlWriter writer) { // PolicyHasSettings global::System.Collections.ObjectModel.ReadOnlyCollection<PolicyHasSettings> allPolicyHasSettingsInstances = PolicyHasSettings.GetLinksToSettings(element); if (!serializationContext.Result.Failed && allPolicyHasSettingsInstances.Count > 0) { writer.WriteStartElement("settings"); global::System.Type typeofPolicyHasSettings = typeof(PolicyHasSettings); foreach (PolicyHasSettings eachPolicyHasSettingsInstance in allPolicyHasSettingsInstances) { if (serializationContext.Result.Failed) break; if (eachPolicyHasSettingsInstance.GetType() != typeofPolicyHasSettings) { // Derived relationships will be serialized in full-form. DslModeling::DomainClassXmlSerializer derivedRelSerializer = serializationContext.Directory.GetSerializer(eachPolicyHasSettingsInstance.GetDomainClass().Id); global::System.Diagnostics.Debug.Assert(derivedRelSerializer != null, "Cannot find serializer for " + eachPolicyHasSettingsInstance.GetDomainClass().Name + "!"); derivedRelSerializer.Write(serializationContext, eachPolicyHasSettingsInstance, writer); } else { // No need to serialize the relationship itself, just serialize the role-player directly. DslModeling::ModelElement targetElement = eachPolicyHasSettingsInstance.CustomizableSettingSchema; DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer(targetElement.GetDomainClass().Id); global::System.Diagnostics.Debug.Assert(targetSerializer != null, "Cannot find serializer for " + targetElement.GetDomainClass().Name + "!"); targetSerializer.Write(serializationContext, targetElement, writer); } } writer.WriteEndElement(); } }
/// <summary> /// This method deserializes all child model elements. /// </summary> /// <remarks> /// The caller will position the reader at the open tag of the first child XML element to deserialized. /// This method will read as many child elements as it can. It returns under three circumstances: /// 1) When an unknown child XML element is encountered. In this case, this method will position the reader at the /// open tag of the unknown element. This implies that if the first child XML element is unknown, this method /// should return immediately and do nothing. /// 2) When all child XML elemnets are read. In this case, the reader will be positioned at the end tag of the parent element. /// 3) EOF. /// </remarks> /// <param name="serializationContext">Serialization context.</param> /// <param name="reader">XmlReader to read serialized data from.</param> /// <param name="element">In-memory CustomizationPolicySchema instance that will get the deserialized data.</param> private static void ReadChildElements(DslModeling::SerializationContext serializationContext, CustomizationPolicySchema element, global::System.Xml.XmlReader reader) { if (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element) { if (string.Compare(reader.LocalName, "settings", global::System.StringComparison.CurrentCulture) == 0) { if (reader.IsEmptyElement) { // No instance of this relationship, just skip DslModeling::SerializationUtilities.Skip(reader); } else { DslModeling::SerializationUtilities.SkipToFirstChild(reader); // Skip the open tag of <settings> ReadPolicyHasSettingsInstances(serializationContext, element, reader); DslModeling::SerializationUtilities.Skip(reader); // Skip the close tag of </settings> } } } }