public void Initialize() { this.store = new DslTestStore<ProductStateStoreDomainModel>(); var viewInfo = new Mock<IViewInfo>(); using (var tx = this.store.TransactionManager.BeginTransaction()) { this.view = this.store.ElementFactory.CreateElement<View>(); this.view.Info = viewInfo.Object; tx.Commit(); } this.collectionInfo = new Mock<ICollectionInfo>(); this.collectionInfo.Setup(c => c.Id).Returns(Guid.NewGuid()); this.collectionInfo.Setup(c => c.Parent).Returns(this.view.Info); viewInfo.Setup(p => p.Elements).Returns(new[] { this.collectionInfo.Object }); }
private static void WriteChildElements(DslModeling::SerializationContext serializationContext, View element, global::System.Xml.XmlWriter writer) { // ViewHasElements global::System.Collections.ObjectModel.ReadOnlyCollection<ViewHasElements> allViewHasElementsInstances = ViewHasElements.GetLinksToElements(element); if (!serializationContext.Result.Failed && allViewHasElementsInstances.Count > 0) { writer.WriteStartElement("elements"); global::System.Type typeofViewHasElements = typeof(ViewHasElements); foreach (ViewHasElements eachViewHasElementsInstance in allViewHasElementsInstances) { if (serializationContext.Result.Failed) break; if (eachViewHasElementsInstance.GetType() != typeofViewHasElements) { // Derived relationships will be serialized in full-form. DslModeling::DomainClassXmlSerializer derivedRelSerializer = serializationContext.Directory.GetSerializer(eachViewHasElementsInstance.GetDomainClass().Id); global::System.Diagnostics.Debug.Assert(derivedRelSerializer != null, "Cannot find serializer for " + eachViewHasElementsInstance.GetDomainClass().Name + "!"); derivedRelSerializer.Write(serializationContext, eachViewHasElementsInstance, writer); } else { // No need to serialize the relationship itself, just serialize the role-player directly. DslModeling::ModelElement targetElement = eachViewHasElementsInstance.AbstractElement; 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(); } // ViewHasExtensionProducts global::System.Collections.ObjectModel.ReadOnlyCollection<ViewHasExtensionProducts> allViewHasExtensionProductsInstances = ViewHasExtensionProducts.GetLinksToExtensionProducts(element); if (!serializationContext.Result.Failed && allViewHasExtensionProductsInstances.Count > 0) { writer.WriteStartElement("extensionProducts"); global::System.Type typeofViewHasExtensionProducts = typeof(ViewHasExtensionProducts); foreach (ViewHasExtensionProducts eachViewHasExtensionProductsInstance in allViewHasExtensionProductsInstances) { if (serializationContext.Result.Failed) break; if (eachViewHasExtensionProductsInstance.GetType() != typeofViewHasExtensionProducts) { // Derived relationships will be serialized in full-form. DslModeling::DomainClassXmlSerializer derivedRelSerializer = serializationContext.Directory.GetSerializer(eachViewHasExtensionProductsInstance.GetDomainClass().Id); global::System.Diagnostics.Debug.Assert(derivedRelSerializer != null, "Cannot find serializer for " + eachViewHasExtensionProductsInstance.GetDomainClass().Name + "!"); derivedRelSerializer.Write(serializationContext, eachViewHasExtensionProductsInstance, writer); } else { // No need to serialize the relationship itself, just serialize the role-player directly. DslModeling::ModelElement targetElement = eachViewHasExtensionProductsInstance.Extension; 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> /// Reads all instances of relationship ViewHasExtensionProducts. /// </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 View instance that will get the deserialized data.</param> /// <param name="reader">XmlReader to read serialized data from.</param> private static void ReadViewHasExtensionProductsInstances(DslModeling::SerializationContext serializationContext, View element, global::System.Xml.XmlReader reader) { while (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element) { DslModeling::DomainClassXmlSerializer newProductOfViewHasExtensionProductsSerializer = serializationContext.Directory.GetSerializer(Product.DomainClassId); global::System.Diagnostics.Debug.Assert(newProductOfViewHasExtensionProductsSerializer != null, "Cannot find serializer for Product!"); Product newProductOfViewHasExtensionProducts = newProductOfViewHasExtensionProductsSerializer.TryCreateInstance(serializationContext, reader, element.Partition) as Product; if (newProductOfViewHasExtensionProducts != null) { element.ExtensionProducts.Add(newProductOfViewHasExtensionProducts); DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer (newProductOfViewHasExtensionProducts.GetDomainClass().Id); global::System.Diagnostics.Debug.Assert (targetSerializer != null, "Cannot find serializer for " + newProductOfViewHasExtensionProducts.GetDomainClass().Name + "!"); targetSerializer.Read(serializationContext, newProductOfViewHasExtensionProducts, reader); } else { global::System.Type typeofViewHasExtensionProducts = typeof(ViewHasExtensionProducts); DslModeling::DomainRelationshipXmlSerializer newViewHasExtensionProductsSerializer = serializationContext.Directory.GetSerializer(ViewHasExtensionProducts.DomainClassId) as DslModeling::DomainRelationshipXmlSerializer; global::System.Diagnostics.Debug.Assert(newViewHasExtensionProductsSerializer != null, "Cannot find serializer for ViewHasExtensionProducts!"); ViewHasExtensionProducts newViewHasExtensionProducts = newViewHasExtensionProductsSerializer.TryCreateInstance (serializationContext, reader, element.Partition) as ViewHasExtensionProducts; if (newViewHasExtensionProducts != null) { if (newViewHasExtensionProducts.GetType() == typeofViewHasExtensionProducts) { // The relationship should be serialized in short-form. ProductStateStoreSerializationBehaviorSerializationMessages.ExpectingShortFormRelationship(serializationContext, reader, typeof(ViewHasExtensionProducts)); } DslModeling::DomainRoleInfo.SetRolePlayer (newViewHasExtensionProducts, ViewHasExtensionProducts.ViewDomainRoleId, element); DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer (newViewHasExtensionProducts.GetDomainClass().Id); global::System.Diagnostics.Debug.Assert (targetSerializer != null, "Cannot find serializer for " + newViewHasExtensionProducts.GetDomainClass().Name + "!"); targetSerializer.Read(serializationContext, newViewHasExtensionProducts, reader); } else { // Unknown element, skip DslModeling::SerializationUtilities.Skip(reader); } } } }
/// <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 View instance that will get the deserialized data.</param> private static void ReadChildElements(DslModeling::SerializationContext serializationContext, View element, global::System.Xml.XmlReader reader) { while (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element) { switch (reader.LocalName) { case "elements": // Relationship "ViewHasElements" if (reader.IsEmptyElement) { // No instance of this relationship, just skip DslModeling::SerializationUtilities.Skip(reader); } else { DslModeling::SerializationUtilities.SkipToFirstChild(reader); // Skip the open tag of <elements> ReadViewHasElementsInstances(serializationContext, element, reader); DslModeling::SerializationUtilities.Skip(reader); // Skip the close tag of </elements> } break; case "extensionProducts": // Relationship "ViewHasExtensionProducts" if (reader.IsEmptyElement) { // No instance of this relationship, just skip DslModeling::SerializationUtilities.Skip(reader); } else { DslModeling::SerializationUtilities.SkipToFirstChild(reader); // Skip the open tag of <extensionProducts> ReadViewHasExtensionProductsInstances(serializationContext, element, reader); DslModeling::SerializationUtilities.Skip(reader); // Skip the close tag of </extensionProducts> } break; default: return; // Don't know this element. } } }
internal static DslModeling::LinkedElementCollection<AbstractElement> GetElements(View element) { return GetRoleCollection<DslModeling::LinkedElementCollection<AbstractElement>, AbstractElement>(element, ViewDomainRoleId); }
internal static void SetView(AbstractElement element, View newView) { DslModeling::DomainRoleInfo.SetLinkedElement(element, AbstractElementDomainRoleId, newView); }
/// <summary> /// Constructor /// Creates a ViewHasElements link in the same Partition as the given View /// </summary> /// <param name="source">View to use as the source of the relationship.</param> /// <param name="target">AbstractElement to use as the target of the relationship.</param> internal ViewHasElements(View source, AbstractElement target) : base((source != null ? source.Partition : null), new DslModeling::RoleAssignment[]{new DslModeling::RoleAssignment(ViewHasElements.ViewDomainRoleId, source), new DslModeling::RoleAssignment(ViewHasElements.AbstractElementDomainRoleId, target)}, null) { }
internal static void SetProduct(View element, Product newProduct) { DslModeling::DomainRoleInfo.SetLinkedElement(element, ViewDomainRoleId, newProduct); }
internal static Product GetProduct(View element) { return DslModeling::DomainRoleInfo.GetLinkedElement(element, ViewDomainRoleId) as Product; }
/// <summary> /// Constructor /// Creates a ProductHasViews link in the same Partition as the given Product /// </summary> /// <param name="source">Product to use as the source of the relationship.</param> /// <param name="target">View to use as the target of the relationship.</param> internal ProductHasViews(Product source, View target) : base((source != null ? source.Partition : null), new DslModeling::RoleAssignment[]{new DslModeling::RoleAssignment(ProductHasViews.ProductDomainRoleId, source), new DslModeling::RoleAssignment(ProductHasViews.ViewDomainRoleId, target)}, null) { }
internal static DslModeling::LinkedElementCollection<Product> GetExtensionProducts(View element) { return GetRoleCollection<DslModeling::LinkedElementCollection<Product>, Product>(element, ViewDomainRoleId); }
internal static void SetView(Product element, View newView) { DslModeling::DomainRoleInfo.SetLinkedElement(element, ExtensionDomainRoleId, newView); }
/// <summary> /// Constructor /// Creates a ViewHasExtensionProducts link in the same Partition as the given View /// </summary> /// <param name="source">View to use as the source of the relationship.</param> /// <param name="target">Product to use as the target of the relationship.</param> internal ViewHasExtensionProducts(View source, Product target) : base((source != null ? source.Partition : null), new DslModeling::RoleAssignment[]{new DslModeling::RoleAssignment(ViewHasExtensionProducts.ViewDomainRoleId, source), new DslModeling::RoleAssignment(ViewHasExtensionProducts.ExtensionDomainRoleId, target)}, null) { }
public override void Initialize() { base.Initialize(); CreateProperty(this.Product, this.Product.DefinitionName + "Property1", this.Product.DefinitionName + "Value1"); // Build the Tree this.View = CreateView(this.Product, "AView", v => { CreateElement(v, "O"); CreateElement(v, "N"); CreateElement(v, "Q", Cardinality.OneToOne, q => { CreateElement(q, "T", Cardinality.OneToOne, t => { CreateElement(t, "U"); CreateElement(t, "V"); CreateElement(t, "M", Cardinality.OneToOne); }); CreateElement(q, "S"); CreateElement(q, "R", Cardinality.OneToOne, r => { CreateElement(r, "L"); CreateElement(r, "E", Cardinality.OneToOne, e => { CreateElement(e, "F"); CreateElement(e, "G"); }); }); }); }); }