private static IAbstractElementInfo FindInfo(AbstractElement element) { if (element.Parent != null) { var info = element.Parent.Info as IElementInfoContainer; if (info != null) { return(info.Elements.FirstOrDefault(v => v.Id == element.DefinitionId)); } } return(null); }
private static IAbstractElementInfo FindInfo(AbstractElement element) { if (element.Parent != null) { var info = element.Parent.Info as IElementInfoContainer; if (info != null) { return info.Elements.FirstOrDefault(v => v.Id == element.DefinitionId); } } return null; }
/// <summary> /// Sync the extension points of the given element/collection. /// </summary> internal static void SyncExtensionPointsFrom( this AbstractElement element, IEnumerable <IExtensionPointInfo> extensionPoints, IPatternManager patternManager) { element.ExtensionProducts .Where(p => !IsValidExtensionPoint(p, extensionPoints, patternManager)) .ToArray() .ForEach(p => p.Delete()); element.ExtensionProducts .GroupBy(x => x.DefinitionId) .Where(x => x.Count() > 1 && HasSingletonExtensionPointsInElement(x, extensionPoints, patternManager)) .SelectMany(x => x.Skip(1)) .ForEach(x => x.Delete()); }
/// <summary> /// Sync the elements/collections of the given element. /// </summary> internal static void SyncElementsFrom(this AbstractElement element, IEnumerable <IAbstractElementInfo> elements) { element.Elements .Where(e => !elements.Any(i => i.Id == e.DefinitionId)) .ToArray() .ForEach(e => e.Delete()); element.Elements .GroupBy(x => x.DefinitionId) .Where(x => elements.Any( i => x.Key == i.Id && (i.Cardinality == Cardinality.OneToOne || i.Cardinality == Cardinality.ZeroToOne) && x.Count() > 1)) .SelectMany(x => x.Skip(1)) .ForEach(x => x.Delete()); var singletonElements = elements .Where(i => i.AutoCreate && !element.Elements.Any(e => e.DefinitionId == i.Id)) .ToArray(); singletonElements.OfType <IElementInfo>().ForEach(x => element.CreateElement(e => e.DefinitionId = x.Id)); singletonElements.OfType <ICollectionInfo>().ForEach(x => element.CreateCollection(e => e.DefinitionId = x.Id)); }
/// <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 AbstractElement instance that will get the deserialized data.</param> private static void ReadChildElements(DslModeling::SerializationContext serializationContext, AbstractElement 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 "ElementHasChildElements" 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> ReadElementHasChildElementsInstances(serializationContext, element, reader); DslModeling::SerializationUtilities.Skip(reader); // Skip the close tag of </elements> } break; case "extensionProducts": // Relationship "ElementHasExtensions" 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> ReadElementHasExtensionsInstances(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(AbstractElement element) { return GetRoleCollection<DslModeling::LinkedElementCollection<AbstractElement>, AbstractElement>(element, ParentElementDomainRoleId); }
internal static void SetOwner(AbstractElement element, AbstractElement newParentElement) { DslModeling::DomainRoleInfo.SetLinkedElement(element, ChildElementDomainRoleId, newParentElement); }
internal static AbstractElement GetOwner(AbstractElement element) { return DslModeling::DomainRoleInfo.GetLinkedElement(element, ChildElementDomainRoleId) as AbstractElement; }
/// <summary> /// Constructor /// Creates a ElementHasChildElements link in the same Partition as the given AbstractElement /// </summary> /// <param name="source">AbstractElement to use as the source of the relationship.</param> /// <param name="target">AbstractElement to use as the target of the relationship.</param> internal ElementHasChildElements(AbstractElement source, AbstractElement target) : base((source != null ? source.Partition : null), new DslModeling::RoleAssignment[]{new DslModeling::RoleAssignment(ElementHasChildElements.ParentElementDomainRoleId, source), new DslModeling::RoleAssignment(ElementHasChildElements.ChildElementDomainRoleId, target)}, null) { }
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 DslModeling::LinkedElementCollection<Product> GetExtensionProducts(AbstractElement element) { return GetRoleCollection<DslModeling::LinkedElementCollection<Product>, Product>(element, AbstractElementDomainRoleId); }
internal static void SetOwner(Product element, AbstractElement newAbstractElement) { DslModeling::DomainRoleInfo.SetLinkedElement(element, ExtensionDomainRoleId, newAbstractElement); }
/// <summary> /// Constructor /// Creates a ElementHasExtensions link in the same Partition as the given AbstractElement /// </summary> /// <param name="source">AbstractElement to use as the source of the relationship.</param> /// <param name="target">Product to use as the target of the relationship.</param> internal ElementHasExtensions(AbstractElement source, Product target) : base((source != null ? source.Partition : null), new DslModeling::RoleAssignment[]{new DslModeling::RoleAssignment(ElementHasExtensions.AbstractElementDomainRoleId, source), new DslModeling::RoleAssignment(ElementHasExtensions.ExtensionDomainRoleId, target)}, null) { }
/// <summary> /// Reads all instances of relationship ElementHasExtensions. /// </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 AbstractElement instance that will get the deserialized data.</param> /// <param name="reader">XmlReader to read serialized data from.</param> private static void ReadElementHasExtensionsInstances(DslModeling::SerializationContext serializationContext, AbstractElement element, global::System.Xml.XmlReader reader) { while (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element) { DslModeling::DomainClassXmlSerializer newProductOfElementHasExtensionsSerializer = serializationContext.Directory.GetSerializer(Product.DomainClassId); global::System.Diagnostics.Debug.Assert(newProductOfElementHasExtensionsSerializer != null, "Cannot find serializer for Product!"); Product newProductOfElementHasExtensions = newProductOfElementHasExtensionsSerializer.TryCreateInstance(serializationContext, reader, element.Partition) as Product; if (newProductOfElementHasExtensions != null) { element.ExtensionProducts.Add(newProductOfElementHasExtensions); DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer (newProductOfElementHasExtensions.GetDomainClass().Id); global::System.Diagnostics.Debug.Assert (targetSerializer != null, "Cannot find serializer for " + newProductOfElementHasExtensions.GetDomainClass().Name + "!"); targetSerializer.Read(serializationContext, newProductOfElementHasExtensions, reader); } else { global::System.Type typeofElementHasExtensions = typeof(ElementHasExtensions); DslModeling::DomainRelationshipXmlSerializer newElementHasExtensionsSerializer = serializationContext.Directory.GetSerializer(ElementHasExtensions.DomainClassId) as DslModeling::DomainRelationshipXmlSerializer; global::System.Diagnostics.Debug.Assert(newElementHasExtensionsSerializer != null, "Cannot find serializer for ElementHasExtensions!"); ElementHasExtensions newElementHasExtensions = newElementHasExtensionsSerializer.TryCreateInstance (serializationContext, reader, element.Partition) as ElementHasExtensions; if (newElementHasExtensions != null) { if (newElementHasExtensions.GetType() == typeofElementHasExtensions) { // The relationship should be serialized in short-form. ProductStateStoreSerializationBehaviorSerializationMessages.ExpectingShortFormRelationship(serializationContext, reader, typeof(ElementHasExtensions)); } DslModeling::DomainRoleInfo.SetRolePlayer (newElementHasExtensions, ElementHasExtensions.AbstractElementDomainRoleId, element); DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer (newElementHasExtensions.GetDomainClass().Id); global::System.Diagnostics.Debug.Assert (targetSerializer != null, "Cannot find serializer for " + newElementHasExtensions.GetDomainClass().Name + "!"); targetSerializer.Read(serializationContext, newElementHasExtensions, reader); } else { // Unknown element, skip DslModeling::SerializationUtilities.Skip(reader); } } } }
private static void WriteChildElements(DslModeling::SerializationContext serializationContext, AbstractElement element, global::System.Xml.XmlWriter writer) { // ElementHasChildElements global::System.Collections.ObjectModel.ReadOnlyCollection<ElementHasChildElements> allElementHasChildElementsInstances = ElementHasChildElements.GetLinksToElements(element); if (!serializationContext.Result.Failed && allElementHasChildElementsInstances.Count > 0) { writer.WriteStartElement("elements"); global::System.Type typeofElementHasChildElements = typeof(ElementHasChildElements); foreach (ElementHasChildElements eachElementHasChildElementsInstance in allElementHasChildElementsInstances) { if (serializationContext.Result.Failed) break; if (eachElementHasChildElementsInstance.GetType() != typeofElementHasChildElements) { // Derived relationships will be serialized in full-form. DslModeling::DomainClassXmlSerializer derivedRelSerializer = serializationContext.Directory.GetSerializer(eachElementHasChildElementsInstance.GetDomainClass().Id); global::System.Diagnostics.Debug.Assert(derivedRelSerializer != null, "Cannot find serializer for " + eachElementHasChildElementsInstance.GetDomainClass().Name + "!"); derivedRelSerializer.Write(serializationContext, eachElementHasChildElementsInstance, writer); } else { // No need to serialize the relationship itself, just serialize the role-player directly. DslModeling::ModelElement targetElement = eachElementHasChildElementsInstance.ChildElement; 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(); } // ElementHasExtensions global::System.Collections.ObjectModel.ReadOnlyCollection<ElementHasExtensions> allElementHasExtensionsInstances = ElementHasExtensions.GetLinksToExtensionProducts(element); if (!serializationContext.Result.Failed && allElementHasExtensionsInstances.Count > 0) { writer.WriteStartElement("extensionProducts"); global::System.Type typeofElementHasExtensions = typeof(ElementHasExtensions); foreach (ElementHasExtensions eachElementHasExtensionsInstance in allElementHasExtensionsInstances) { if (serializationContext.Result.Failed) break; if (eachElementHasExtensionsInstance.GetType() != typeofElementHasExtensions) { // Derived relationships will be serialized in full-form. DslModeling::DomainClassXmlSerializer derivedRelSerializer = serializationContext.Directory.GetSerializer(eachElementHasExtensionsInstance.GetDomainClass().Id); global::System.Diagnostics.Debug.Assert(derivedRelSerializer != null, "Cannot find serializer for " + eachElementHasExtensionsInstance.GetDomainClass().Name + "!"); derivedRelSerializer.Write(serializationContext, eachElementHasExtensionsInstance, writer); } else { // No need to serialize the relationship itself, just serialize the role-player directly. DslModeling::ModelElement targetElement = eachElementHasExtensionsInstance.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(); } }
internal static View GetView(AbstractElement element) { return DslModeling::DomainRoleInfo.GetLinkedElement(element, AbstractElementDomainRoleId) as View; }