コード例 #1
0
        private static void FixUpDomainClassInTreeView(DomainClass domainClass)
        {
            // add embedding relationships
            foreach (DomainRole role in domainClass.RolesPlayed)
            {
                if (role.Relationship.Source == role && role.Relationship is EmbeddingRelationship)
                {
                    EmbeddingRelationship emb = role.Relationship as EmbeddingRelationship;

                    if (emb.Target.RolePlayer.DomainModelTreeNodes.Count > 0)
                    {
                        ModelTreeHelper.AddNewEmbeddingRS(emb, emb.Source.RolePlayer as DomainClass, emb.Target.RolePlayer, false);
                    }
                    else
                    {
                        ModelTreeHelper.AddNewEmbeddingRS(emb, emb.Source.RolePlayer as DomainClass, emb.Target.RolePlayer, true);
                        FixUpDomainClassInTreeView(emb.Target.RolePlayer as DomainClass);

                        emb.Target.RolePlayer.DomainModelTreeNodes[0].IsEmbeddingTreeExpanded    = true;
                        emb.Target.RolePlayer.DomainModelTreeNodes[0].IsReferenceTreeExpanded    = true;
                        emb.Target.RolePlayer.DomainModelTreeNodes[0].IsInheritanceTreeExpanded  = true;
                        emb.Target.RolePlayer.DomainModelTreeNodes[0].IsShapeMappingTreeExpanded = true;
                    }
                }
            }
        }
コード例 #2
0
        public static void OnEmbeddingRelationshipAdded(EmbeddingRelationship embeddingRelationship)
        {
            #region Check Paramaters
            if (embeddingRelationship.Source == null)
            {
                throw new ArgumentNullException("embeddingRelationship.Source");
            }

            if (embeddingRelationship.Target == null)
            {
                throw new ArgumentNullException("embeddingRelationship.Target");
            }

            if (!(embeddingRelationship.Source.RolePlayer is DomainClass))
            {
                throw new ArgumentNullException("embeddingRelationship.Source.RolePlayer needs to be DomainClass");
            }

            if (!(embeddingRelationship.Target.RolePlayer is DomainClass))
            {
                throw new ArgumentNullException("embeddingRelationship.Target.RolePlayer needs to be DomainClass");
            }
            #endregion

            // add serialization info
            SerializedDomainClass child;
            if ((embeddingRelationship.Target.RolePlayer as DomainClass).SerializedDomainClass == null)
            {
                child             = new SerializedDomainClass(embeddingRelationship.Store);
                child.DomainClass = embeddingRelationship.Target.RolePlayer as DomainClass;
                (embeddingRelationship.Target.RolePlayer as DomainClass).ModelContext.SerializationModel.Children.Add(child);

                SerializationHelper.AddSerializationDomainProperties(embeddingRelationship.Store, embeddingRelationship.Target.RolePlayer);
            }
            else
            {
                child = (embeddingRelationship.Target.RolePlayer as DomainClass).SerializedDomainClass;
            }

            // Add properties and id attribute and set serialization form for embedding relationship.
            SerializedEmbeddingRelationship embChild = new SerializedEmbeddingRelationship(embeddingRelationship.Store);
            embChild.EmbeddingRelationship = embeddingRelationship;
            embChild.IsInFullSerialization = false;
            embChild.SerializationName     = embeddingRelationship.SerializationName;
            SerializationHelper.AddSerializationDomainProperties(embeddingRelationship.Store, embeddingRelationship);

            embeddingRelationship.ModelContext.SerializationModel.Children.Add(embChild);
            embChild.Children.Add(child);

            // Add connection between roleplayers, to reflect it onto the serialization model.
            SerializationClass sourceSerializationClass = (embeddingRelationship.Source.RolePlayer as DomainClass).SerializedDomainClass;
            sourceSerializationClass.Children.Add(embChild);

            // update derived roles
            SerializationHelper.UpdateDerivedElementsSerializationDomainRoles(embeddingRelationship.Source.RolePlayer);
        }
コード例 #3
0
        /// <summary>
        /// Adds a new embedding relationship instance. Needs to be called within a modeling transaction.
        /// </summary>
        /// <param name="source">Domain class representing the parent.</param>
        /// <param name="target">Domain class representing the child.</param>
        public static EmbeddingRelationship AddNewEmbeddingRS(DomainClass source, AttributedDomainElement target, bool bTargetElementHolder)
        {
            // create rs
            EmbeddingRelationship emb = new EmbeddingRelationship(source.Store);

            source.ModelContext.Relationships.Add(emb);

            // create roles
            DomainRole sourceRole = new DomainRole(source.Store);

            sourceRole.PropagatesDelete = false;

            DomainRole targetRole = new DomainRole(source.Store);

            targetRole.Multiplicity     = Multiplicity.One;
            targetRole.PropagatesDelete = true;

            sourceRole.RolePlayer = source;
            targetRole.RolePlayer = target;

            sourceRole.Opposite = targetRole;
            targetRole.Opposite = sourceRole;

            // assign roles to rs
            emb.Roles.Add(sourceRole);
            emb.Roles.Add(targetRole);

            emb.Source = sourceRole;
            emb.Target = targetRole;

            // properties + names
            if (emb.Source.RolePlayer.Name == emb.Target.RolePlayer.Name)
            {
                sourceRole.Name = source.Name + "Source";
            }
            else
            {
                sourceRole.Name = source.Name;
            }
            sourceRole.IsNameTracking = TrackingEnum.IgnoreOnce;

            if (emb.Source.RolePlayer.Name == emb.Target.RolePlayer.Name)
            {
                targetRole.Name = target.Name + "Target";
            }
            else
            {
                targetRole.Name = target.Name;
            }
            targetRole.IsNameTracking = TrackingEnum.IgnoreOnce;

            AddNewEmbeddingRS(emb, source, target, bTargetElementHolder);

            return(emb);
        }
コード例 #4
0
        private void FinalizeEmbeddingRelationshipsMerge(ModelProtoElement protoElement, ModelProtoGroupMerger groupMerger, bool bCreateSInfo)
        {
            EmbeddingRelationship embRel = this.Store.ElementDirectory.FindElement(groupMerger.GetIdMapping(protoElement.ElementId)) as EmbeddingRelationship;

            if (bCreateSInfo)
            {
                SerializationDomainRelationshipAddRule.OnEmbeddingRelationshipAdded(embRel);
            }
            if (embRel == null)
            {
                return;
            }

            ModelTreeHelper.AddNewEmbeddingRS(embRel, embRel.Source.RolePlayer as DomainClass, embRel.Target.RolePlayer, false);
        }
コード例 #5
0
        public override void ElementPropertyChanged(ElementPropertyChangedEventArgs e)
        {
            if (e.ModelElement != null)
            {
                if (e.ModelElement.Store.TransactionManager.CurrentTransaction != null)
                {
                    if (e.ModelElement.Store.TransactionManager.CurrentTransaction.IsSerializing)
                    {
                        return;
                    }
                }
            }

            if (e.ModelElement == null)
            {
                return;
            }

            if (ImmutabilityExtensionMethods.GetLocks(e.ModelElement) != Locks.None)
            {
                return;
            }

            EmbeddingRelationship embeddingRelationship = e.ModelElement as EmbeddingRelationship;

            if (embeddingRelationship != null)
            {
                if (e.DomainProperty.Id == EmbeddingRelationship.SerializationNameDomainPropertyId)
                {
                    SerializedEmbeddingRelationship c = embeddingRelationship.SerializedEmbeddingRelationship;
                    if (c.SerializationName != embeddingRelationship.SerializationName)
                    {
                        c.SerializationName = embeddingRelationship.SerializationName;
                        if (embeddingRelationship.IsSerializationNameTracking != TrackingEnum.False)
                        {
                            c.IsSerializationNameTracking = TrackingEnum.IgnoreOnce;
                        }
                        else
                        {
                            c.IsSerializationNameTracking = TrackingEnum.False;
                        }
                    }
                }
            }
        }
コード例 #6
0
        /// <summary>
        /// Adds a new embedding relationship instance. Needs to be called within a modeling transaction.
        /// </summary>
        /// <param name="source">Domain class representing the parent.</param>
        /// <param name="target">Domain class representing the child.</param>
        public static void AddNewEmbeddingRS(EmbeddingRelationship emb, DomainClass source, AttributedDomainElement target, bool bTargetElementHolder)
        {
            // tree nodes
            // 1. find the element holder node for source
            // 2. add new EmbeddingRSNode, connect to rs
            // 3. add new EmbeddingNode for target
            TreeNode elementHolderNode = null;

            foreach (TreeNode node in source.DomainModelTreeNodes)
            {
                if (node.IsElementHolder)
                {
                    elementHolderNode = node;
                    break;
                }
            }

            if (elementHolderNode == null)
            {
                throw new ArgumentNullException("elementHolderNode");
            }

            EmbeddingRSNode rsNode = new EmbeddingRSNode(source.Store);

            rsNode.Relationship = emb;

            EmbeddingNode embNode = new EmbeddingNode(source.Store);

            embNode.DomainElement   = target;
            embNode.IsElementHolder = bTargetElementHolder;
            if (!bTargetElementHolder)
            {
                embNode.IsExpanded = false;
            }

            elementHolderNode.EmbeddingRSNodes.Add(rsNode);
            rsNode.EmbeddingNode = embNode;

            source.ModelContext.ViewContext.DomainModelTreeView.ModelTreeNodes.Add(rsNode);
            source.ModelContext.ViewContext.DomainModelTreeView.ModelTreeNodes.Add(embNode);
        }
コード例 #7
0
        private static void FixUpDerivedRelationships(DomainRelationship domainClass, MetaModel model)
        {
            if (domainClass.ModelContext.MetaModel == model)
            {
                if (domainClass is EmbeddingRelationship)
                {
                    EmbeddingRelationship con = domainClass as EmbeddingRelationship;
                    SerializationHelper.UpdateSerializationDomainProperties(domainClass.Store, con.SerializedEmbeddingRelationship, domainClass);
                }

                if (domainClass is ReferenceRelationship)
                {
                    ReferenceRelationship con = domainClass as ReferenceRelationship;
                    SerializationHelper.UpdateSerializationDomainProperties(domainClass.Store, con.SerializedReferenceRelationship, domainClass);
                }
            }

            foreach (DomainRelationship derivedClass in domainClass.DerivedRelationships)
            {
                FixUpDerivedRelationships(derivedClass, model);
            }
        }
コード例 #8
0
        public override void ElementAdded(ElementAddedEventArgs e)
        {
            if (e.ModelElement != null)
            {
                if (e.ModelElement.Store.TransactionManager.CurrentTransaction != null)
                {
                    if (e.ModelElement.Store.TransactionManager.CurrentTransaction.IsSerializing)
                    {
                        return;
                    }
                }
            }

            if (e.ModelElement == null)
            {
                return;
            }

            if (ImmutabilityExtensionMethods.GetLocks(e.ModelElement) != Locks.None)
            {
                return;
            }

            if (e.ModelElement.IsDeleting || e.ModelElement.IsDeleted)
            {
                return;
            }

            ReferenceRelationship referenceRelationship = e.ModelElement as ReferenceRelationship;

            if (referenceRelationship != null)
            {
                if (referenceRelationship.SerializedReferenceRelationship == null)
                {
                    OnReferenceRelationshipAdded(referenceRelationship);
                }
            }

            EmbeddingRelationship embeddingRelationship = e.ModelElement as EmbeddingRelationship;

            if (embeddingRelationship != null)
            {
                if (embeddingRelationship.SerializedEmbeddingRelationship == null)
                {
                    OnEmbeddingRelationshipAdded(embeddingRelationship);
                }
            }

            DomainClassReferencesBaseClass inhRelationship = e.ModelElement as DomainClassReferencesBaseClass;

            if (inhRelationship != null)
            {
                SerializationHelper.UpdateDerivedElementsSerializationProperties(inhRelationship.DerivedClass);
                SerializationHelper.UpdateDerivedElementsSerializationDomainRoles(inhRelationship.DerivedClass);
            }

            DomainRelationshipReferencesBaseRelationship inhRelationshipRel = e.ModelElement as DomainRelationshipReferencesBaseRelationship;

            if (inhRelationshipRel != null)
            {
                // update derived properties
                SerializationHelper.UpdateDerivedElementsSerializationProperties(inhRelationshipRel.DerivedRelationship);
            }
        }
コード例 #9
0
        public override void ElementDeleting(ElementDeletingEventArgs e)
        {
            if (e.ModelElement != null)
            {
                if (e.ModelElement.Store.TransactionManager.CurrentTransaction != null)
                {
                    if (e.ModelElement.Store.TransactionManager.CurrentTransaction.IsSerializing)
                    {
                        return;
                    }
                }
            }

            if (e.ModelElement == null)
            {
                return;
            }

            if (ImmutabilityExtensionMethods.GetLocks(e.ModelElement) != Locks.None)
            {
                return;
            }

            ReferenceRelationship referenceRelationship = e.ModelElement as ReferenceRelationship;

            if (referenceRelationship != null)
            {
                if (referenceRelationship.ReferenceRSNode != null)
                {
                    referenceRelationship.ReferenceRSNode.Delete();
                }
            }

            EmbeddingRelationship embeddingRelationship = e.ModelElement as EmbeddingRelationship;

            if (embeddingRelationship != null)
            {
                if (embeddingRelationship.EmbeddingRSNode != null)
                {
                    embeddingRelationship.EmbeddingRSNode.Delete();
                }
            }

            DomainClassReferencesBaseClass inhRelationship = e.ModelElement as DomainClassReferencesBaseClass;

            if (inhRelationship != null)
            {
                InheritanceNode node = inhRelationship.Store.ElementDirectory.FindElement(inhRelationship.InhNodeId) as InheritanceNode;
                if (node != null)
                {
                    if (node.IsElementHolder)
                    {
                        RootNode rootNode = new RootNode(node.Store);
                        rootNode.DomainElement = node.DomainElement;

                        rootNode.IsElementHolder         = true;
                        rootNode.IsEmbeddingTreeExpanded = node.IsEmbeddingTreeExpanded;
                        rootNode.IsExpanded = true;
                        rootNode.IsInheritanceTreeExpanded  = node.IsInheritanceTreeExpanded;
                        rootNode.IsReferenceTreeExpanded    = node.IsReferenceTreeExpanded;
                        rootNode.IsShapeMappingTreeExpanded = node.IsShapeMappingTreeExpanded;

                        // copy sub tree
                        for (int i = node.EmbeddingRSNodes.Count - 1; i >= 0; i--)
                        {
                            node.EmbeddingRSNodes[i].TreeNode = rootNode;
                        }

                        for (int i = node.ReferenceRSNodes.Count - 1; i >= 0; i--)
                        {
                            node.ReferenceRSNodes[i].TreeNode = rootNode;
                        }

                        for (int i = node.InheritanceNodes.Count - 1; i >= 0; i--)
                        {
                            node.InheritanceNodes[i].TreeNode = rootNode;
                        }

                        for (int i = node.ShapeClassNodes.Count - 1; i >= 0; i--)
                        {
                            node.ShapeClassNodes[i].TreeNode = rootNode;
                        }

                        node.DomainElement.ParentModelContext.ViewContext.DomainModelTreeView.RootNodes.Add(rootNode);
                        node.DomainElement.ParentModelContext.ViewContext.DomainModelTreeView.ModelTreeNodes.Add(rootNode);
                    }

                    // connection was deleted using the property window and not the menu item, so delete the rs and the
                    // node here
                    //if (inhNode.IsElementHolder)
                    //    TreeOperations.SplitTree(inhNode);

                    node.Delete();
                }
            }
        }
コード例 #10
0
        public override void  ElementDeleting(ElementDeletingEventArgs e)
        {
            if (e.ModelElement != null)
            {
                if (e.ModelElement.Store.TransactionManager.CurrentTransaction != null)
                {
                    if (e.ModelElement.Store.TransactionManager.CurrentTransaction.IsSerializing)
                    {
                        return;
                    }
                }
            }

            if (e.ModelElement == null)
            {
                return;
            }

            if (ImmutabilityExtensionMethods.GetLocks(e.ModelElement) != Locks.None)
            {
                return;
            }

            ReferenceRelationship referenceRelationship = e.ModelElement as ReferenceRelationship;

            if (referenceRelationship != null)
            {
                if (referenceRelationship.SerializedReferenceRelationship != null)
                {
                    referenceRelationship.SerializedReferenceRelationship.Delete();
                }

                if (referenceRelationship.Source != null)
                {
                    if (referenceRelationship.Source.RolePlayer != null)
                    {
                        SerializationHelper.UpdateDerivedElementsSerializationProperties(referenceRelationship.Source.RolePlayer);
                        SerializationHelper.UpdateDerivedElementsSerializationDomainRoles(referenceRelationship.Source.RolePlayer);
                    }
                }

                if (referenceRelationship.Target != null)
                {
                    if (referenceRelationship.Target.RolePlayer != null)
                    {
                        SerializationHelper.UpdateDerivedElementsSerializationProperties(referenceRelationship.Target.RolePlayer);
                        SerializationHelper.UpdateDerivedElementsSerializationDomainRoles(referenceRelationship.Target.RolePlayer);
                    }
                }
            }

            EmbeddingRelationship embeddingRelationship = e.ModelElement as EmbeddingRelationship;

            if (embeddingRelationship != null)
            {
                if (embeddingRelationship.SerializedEmbeddingRelationship != null)
                {
                    embeddingRelationship.SerializedEmbeddingRelationship.Delete();
                }

                if (embeddingRelationship.Source != null)
                {
                    if (embeddingRelationship.Source.RolePlayer != null)
                    {
                        SerializationHelper.UpdateDerivedElementsSerializationProperties(embeddingRelationship.Source.RolePlayer);
                        SerializationHelper.UpdateDerivedElementsSerializationDomainRoles(embeddingRelationship.Source.RolePlayer);
                    }
                }

                if (embeddingRelationship.Target != null)
                {
                    if (embeddingRelationship.Target.RolePlayer != null)
                    {
                        SerializationHelper.UpdateDerivedElementsSerializationProperties(embeddingRelationship.Target.RolePlayer);
                        SerializationHelper.UpdateDerivedElementsSerializationDomainRoles(embeddingRelationship.Target.RolePlayer);
                    }
                }
            }

            DomainClassReferencesBaseClass inhRelationship = e.ModelElement as DomainClassReferencesBaseClass;

            if (inhRelationship != null)
            {
                inhRelationship.DerivedClass.BaseClass = null;

                SerializationHelper.UpdateDerivedElementsSerializationProperties(inhRelationship.DerivedClass);
                SerializationHelper.UpdateDerivedElementsSerializationDomainRoles(inhRelationship.DerivedClass);
            }

            DomainRelationshipReferencesBaseRelationship inhRelationshipRel = e.ModelElement as DomainRelationshipReferencesBaseRelationship;

            if (inhRelationshipRel != null)
            {
                inhRelationshipRel.DerivedRelationship.BaseRelationship = null;

                SerializationHelper.UpdateDerivedElementsSerializationProperties(inhRelationshipRel.DerivedRelationship);
            }
        }
コード例 #11
0
        public override void ElementAdded(ElementAddedEventArgs e)
        {
            if (e.ModelElement != null)
            {
                if (e.ModelElement.Store.TransactionManager.CurrentTransaction != null)
                {
                    if (e.ModelElement.Store.TransactionManager.CurrentTransaction.IsSerializing)
                    {
                        return;
                    }
                }
            }

            if (e.ModelElement == null)
            {
                return;
            }

            if (ImmutabilityExtensionMethods.GetLocks(e.ModelElement) != Locks.None)
            {
                return;
            }

            AttributedDomainElement attributedDomainElement = e.ModelElement as AttributedDomainElement;

            if (attributedDomainElement != null)
            {
                if (attributedDomainElement.IsDeleted || attributedDomainElement.IsDeleting)
                {
                    return;
                }

                if (attributedDomainElement is DomainRelationship)
                {
                    string name;
                    if (attributedDomainElement is EmbeddingRelationship)
                    {
                        name = EmbeddingRelationship.GenerateDomainRelationshipName((attributedDomainElement as DomainRelationship));
                    }
                    else
                    {
                        name = ReferenceRelationship.GenerateDomainRelationshipName((attributedDomainElement as DomainRelationship));
                    }


                    if (attributedDomainElement.Name == "")
                    {
                        attributedDomainElement.Name = name;
                        (attributedDomainElement as DomainRelationship).IsNameTracking = TrackingEnum.IgnoreOnce;
                    }
                }

                //if (attributedDomainElement.SerializationName != attributedDomainElement.Name)
                if (attributedDomainElement.SerializationName == "" || attributedDomainElement.SerializationName == null)
                {
                    attributedDomainElement.SerializationName           = attributedDomainElement.Name;
                    attributedDomainElement.IsSerializationNameTracking = TrackingEnum.IgnoreOnce;
                }

                attributedDomainElement.Namespace = attributedDomainElement.ParentModelContext.MetaModel.Namespace;
            }
        }
コード例 #12
0
        public override void ElementAdded(ElementAddedEventArgs e)
        {
            if (e.ModelElement != null)
            {
                if (e.ModelElement.Store.TransactionManager.CurrentTransaction != null)
                {
                    if (e.ModelElement.Store.TransactionManager.CurrentTransaction.IsSerializing)
                    {
                        return;
                    }
                }
            }

            if (e.ModelElement == null)
            {
                return;
            }

            if (ImmutabilityExtensionMethods.GetLocks(e.ModelElement) != Locks.None)
            {
                return;
            }

            DomainClassReferencesBaseClass con = e.ModelElement as DomainClassReferencesBaseClass;

            if (con != null)
            {
                if (con.BaseClass != null)
                {
                    InheritanceNode inhNode = con.Store.ElementDirectory.FindElement(con.InhNodeId) as InheritanceNode;
                    if (inhNode == null && ImmutabilityExtensionMethods.GetLocks(con.BaseClass) == Locks.None)
                    {
                        // connection was created using the property window and not the menu item, so create a new
                        // inheritance node to display the inheritance relationship
                        TreeNode elementHolderNode = null;
                        foreach (TreeNode node in con.BaseClass.DomainModelTreeNodes)
                        {
                            if (node.IsElementHolder)
                            {
                                elementHolderNode = node;
                                break;
                            }
                        }

                        if (elementHolderNode == null)
                        {
                            throw new ArgumentNullException("elementHolderNode");
                        }

                        // create new inheritance node
                        inhNode = new InheritanceNode(con.Store);
                        inhNode.DomainElement     = con.DerivedClass;
                        inhNode.IsElementHolder   = false;
                        inhNode.IsExpanded        = false;
                        inhNode.InhRelationshipId = con.Id;
                        con.InhNodeId             = inhNode.Id;

                        elementHolderNode.InheritanceNodes.Add(inhNode);
                        con.DerivedClass.ModelContext.ViewContext.DomainModelTreeView.ModelTreeNodes.Add(inhNode);
                    }
                }
            }

            DomainRelationshipReferencesBaseRelationship conRef = e.ModelElement as DomainRelationshipReferencesBaseRelationship;

            if (conRef != null)
            {
                if (conRef.BaseRelationship is ReferenceRelationship && conRef.DerivedRelationship is ReferenceRelationship)
                {
                    ReferenceRelationship rBase = conRef.BaseRelationship as ReferenceRelationship;
                    ReferenceRelationship rDer  = conRef.DerivedRelationship as ReferenceRelationship;
                    if (rBase.SerializedReferenceRelationship != null && rDer.SerializedReferenceRelationship != null)
                    {
                        if (rBase.SerializedReferenceRelationship.IsInFullSerialization)
                        {
                            if (!rDer.SerializedReferenceRelationship.IsInFullSerialization)
                            {
                                // we have to automatically change the serialization mode of the derived class to full serialization mode
                                rDer.SerializedReferenceRelationship.IsInFullSerialization = true;
                            }
                        }
                    }
                }
                else if (conRef.BaseRelationship is EmbeddingRelationship && conRef.DerivedRelationship is EmbeddingRelationship)
                {
                    EmbeddingRelationship rBase = conRef.BaseRelationship as EmbeddingRelationship;
                    EmbeddingRelationship rDer  = conRef.DerivedRelationship as EmbeddingRelationship;
                    if (rBase.SerializedEmbeddingRelationship != null && rDer.SerializedEmbeddingRelationship != null)
                    {
                        if (rBase.SerializedEmbeddingRelationship.IsInFullSerialization)
                        {
                            if (!rDer.SerializedEmbeddingRelationship.IsInFullSerialization)
                            {
                                // we have to automatically change the serialization mode of the derived class to full serialization mode
                                rDer.SerializedEmbeddingRelationship.IsInFullSerialization = true;
                            }
                        }
                    }
                }
            }
        }
コード例 #13
0
        private static void FixUpSerializedDomainModel(ModelContext model)
        {
            foreach (DomainClass domainClass in model.Classes)
            {
                if (domainClass.IsDomainModel)
                {
                    SerializedDomainModel child = new SerializedDomainModel(domainClass.Store);
                    child.DomainClass       = domainClass;
                    child.SerializationName = domainClass.SerializationName;

                    model.SerializationModel.SerializedDomainModel = child;
                    SerializationHelper.AddSerializationDomainProperties(domainClass.Store, domainClass);
                }
                else
                {
                    SerializationDomainClassAddRule.OnDomainClassAdded(domainClass);
                    domainClass.SerializedDomainClass.SerializationName = domainClass.SerializationName;
                }
            }

            foreach (DomainRelationship relationship in model.Relationships)
            {
                if (relationship is EmbeddingRelationship)
                {
                    SerializationDomainRelationshipAddRule.OnEmbeddingRelationshipAdded(relationship as EmbeddingRelationship);
                    (relationship as EmbeddingRelationship).SerializedEmbeddingRelationship.SerializationName = relationship.SerializationName;
                }
                else
                {
                    SerializationDomainRelationshipAddRule.OnReferenceRelationshipAdded(relationship as ReferenceRelationship);
                    (relationship as ReferenceRelationship).SerializedReferenceRelationship.SerializationName = relationship.SerializationName;
                }
            }

            foreach (DomainClass domainClass in model.Classes)
            {
                SerializationHelper.UpdateSerializationDomainProperties(domainClass.Store, domainClass.SerializedDomainClass, domainClass);
                SerializationHelper.UpdateSerializationDomainRoles(domainClass.Store, domainClass.SerializedDomainClass, domainClass);

                foreach (DomainProperty p in domainClass.Properties)
                {
                    p.SerializedDomainProperty.IsSerializationNameTracking = TrackingEnum.True;
                }
            }

            foreach (DomainRelationship relationship in model.Relationships)
            {
                if (relationship is EmbeddingRelationship)
                {
                    SerializationHelper.UpdateSerializationDomainProperties(relationship.Store, (relationship as EmbeddingRelationship).SerializedEmbeddingRelationship, relationship);
                }
                else
                {
                    SerializationHelper.UpdateSerializationDomainProperties(relationship.Store, (relationship as ReferenceRelationship).SerializedReferenceRelationship, relationship);
                }

                foreach (DomainProperty p in relationship.Properties)
                {
                    p.SerializedDomainProperty.IsSerializationNameTracking = TrackingEnum.True;
                }
            }

            // correct IsSerializationNameTracking values

            foreach (DomainClass domainClass in model.Classes)
            {
                if (domainClass.SerializationName != domainClass.Name)
                {
                    domainClass.IsSerializationNameTracking = TrackingEnum.False;
                }

                domainClass.SerializedDomainClass.IsSerializationNameTracking = domainClass.IsSerializationNameTracking;

                foreach (DomainProperty p in domainClass.Properties)
                {
                    if (p.Name != p.SerializationName)
                    {
                        p.IsSerializationNameTracking = TrackingEnum.False;
                    }

                    p.SerializedDomainProperty.IsSerializationNameTracking = p.IsSerializationNameTracking;

                    if (p.Name == "DomainFilePath")
                    {
                        p.SerializedDomainProperty.OmitProperty = true;
                    }
                }
            }

            foreach (DomainRelationship relationship in model.Relationships)
            {
                if (relationship is EmbeddingRelationship)
                {
                    EmbeddingRelationship emb = relationship as EmbeddingRelationship;
                    if (emb.SerializationName != emb.Name)
                    {
                        emb.IsSerializationNameTracking = TrackingEnum.False;
                    }

                    emb.SerializedEmbeddingRelationship.IsSerializationNameTracking = emb.IsSerializationNameTracking;
                }
                else
                {
                    ReferenceRelationship refRel = relationship as ReferenceRelationship;
                    if (refRel.SerializationName != refRel.Name)
                    {
                        refRel.IsSerializationNameTracking = TrackingEnum.False;
                    }

                    refRel.SerializedReferenceRelationship.IsSerializationNameTracking = refRel.IsSerializationNameTracking;
                }

                foreach (DomainProperty p in relationship.Properties)
                {
                    if (p.Name != p.SerializationName)
                    {
                        p.IsSerializationNameTracking = TrackingEnum.True;
                    }

                    p.SerializedDomainProperty.IsSerializationNameTracking = p.IsSerializationNameTracking;
                }
            }
        }
コード例 #14
0
        public static void PostProcessModelLoad(MetaModel model)
        {
            // package and custom editor GUIDs
            if (model.PackageGuid == null || model.PackageGuid == Guid.Empty)
            {
                model.PackageGuid = Guid.NewGuid();
            }
            if (model.CustomExtensionGuid == null || model.CustomExtensionGuid == Guid.Empty)
            {
                model.CustomExtensionGuid = Guid.NewGuid();
            }


            #region relationship targets fixup
            ReadOnlyCollection <DomainRelationship> rels = model.AllRelationships;
            foreach (DomainRelationship rel in rels)
            {
                if (rel.Target.RolePlayer == null)
                {
                    ReferenceRelationship referenceRelationship = rel as ReferenceRelationship;
                    if (referenceRelationship != null)
                    {
                        if (referenceRelationship.ReferenceRSNode != null)
                        {
                            referenceRelationship.ReferenceRSNode.Delete();
                        }

                        if (referenceRelationship.SerializedReferenceRelationship != null)
                        {
                            referenceRelationship.SerializedReferenceRelationship.Delete();
                        }
                    }

                    EmbeddingRelationship embeddingRelationship = rel as EmbeddingRelationship;
                    if (embeddingRelationship != null)
                    {
                        if (embeddingRelationship.EmbeddingRSNode != null)
                        {
                            embeddingRelationship.EmbeddingRSNode.Delete();
                        }

                        if (embeddingRelationship.SerializedEmbeddingRelationship != null)
                        {
                            embeddingRelationship.SerializedEmbeddingRelationship.Delete();
                        }
                    }

                    rel.Delete();
                }
            }
            #endregion

            #region inconsistent serialization elements
            foreach (BaseModelContext context in model.ModelContexts)
            {
                if (context is LibraryModelContext)
                {
                    LibraryModelContext lib = context as LibraryModelContext;
                    if (lib.SerializationModel != null)
                    {
                        for (int i = lib.SerializationModel.Children.Count - 1; i >= 0; i--)
                        {
                            SerializationClass c = lib.SerializationModel.Children[i];
                            if (c is SerializedDomainClass)
                            {
                                SerializedDomainClass s = c as SerializedDomainClass;
                                if (s.DomainClass == null)
                                {
                                    s.Delete();
                                }

                                continue;
                            }
                            else if (c is SerializedEmbeddingRelationship)
                            {
                                SerializedEmbeddingRelationship s = c as SerializedEmbeddingRelationship;
                                if (s.EmbeddingRelationship == null)
                                {
                                    s.Delete();
                                }

                                continue;
                            }
                            else if (c is SerializedReferenceRelationship)
                            {
                                SerializedReferenceRelationship s = c as SerializedReferenceRelationship;
                                if (s.ReferenceRelationship == null)
                                {
                                    s.Delete();
                                }

                                continue;
                            }

                            // element has not been deleted, see if its properties are ok
                            for (int y = c.Properties.Count - 1; y >= 0; y--)
                            {
                                if (c.Properties[y] == null)
                                {
                                    c.Properties[y].Delete();
                                }
                            }
                        }
                    }
                }
            }
            #endregion

            #region derived classes serialization items fixup
            if (model.MetaModelLibraries.Count > 0)
            {
                ReadOnlyCollection <ModelElement> elements = model.Store.ElementDirectory.FindElements(DomainClassReferencesBaseClass.DomainClassId);
                foreach (ModelElement m in elements)
                {
                    DomainClassReferencesBaseClass con = m as DomainClassReferencesBaseClass;
                    if (con != null)
                    {
                        if (con.BaseClass != null)
                        {
                            if (con.BaseClass.ModelContext.MetaModel != model)
                            {
                                foreach (DomainClass derivedClass in con.BaseClass.DerivedClasses)
                                {
                                    FixUpDerivedClasses(derivedClass, model);
                                }
                            }
                        }
                    }
                }

                ReadOnlyCollection <ModelElement> elementsCon = model.Store.ElementDirectory.FindElements(DomainRelationshipReferencesBaseRelationship.DomainClassId);
                foreach (ModelElement m in elementsCon)
                {
                    DomainRelationshipReferencesBaseRelationship con = m as DomainRelationshipReferencesBaseRelationship;
                    if (con != null)
                    {
                        if (con.BaseRelationship != null)
                        {
                            if (con.BaseRelationship.ModelContext.MetaModel != model)
                            {
                                foreach (DomainRelationship derivedClass in con.BaseRelationship.DerivedRelationships)
                                {
                                    FixUpDerivedRelationships(derivedClass, model);
                                }
                            }
                        }
                    }
                }
            }
            #endregion

            #region check if model contains all required elements
            // property grid editors
            if (model.PropertyGridEditors.Count == 0)
            {
                FixUpPropertyGridEditors(model);
            }

            // domain types
            if (model.DomainTypes.Count == 0)
            {
                FixUpDomainTypes(model);
            }

            // model context
            if (model.ModelContexts.Count == 0)
            {
                FixUpModelContext(model);
            }

            // validation
            if (model.Validation == null)
            {
                model.Validation = new Validation(model.Store);
            }

            if (model.View == null)
            {
                model.View = new View(model.Store);
            }

            if (model.View.ModelTree == null)
            {
                model.View.ModelTree = new ModelTree(model.Store);
            }

            foreach (BaseModelContext mContext in model.ModelContexts)
            {
                if (mContext is LibraryModelContext)
                {
                    LibraryModelContext m = mContext as LibraryModelContext;
                    if (m.DiagramClasses.Count == 0 && m is ModelContext)
                    {
                        DesignerDiagramClass ddC = new DesignerDiagramClass(model.Store);
                        ddC.Name  = "DesignerDiagram";
                        ddC.Title = "Designer";

                        m.DiagramClasses.Add(ddC);
                    }

                    if (m.ViewContext == null)
                    {
                        m.ViewContext = new ViewContext(model.Store);
                        m.ViewContext.DomainModelTreeView = new DomainModelTreeView(model.Store);
                        m.ViewContext.DiagramView         = new DiagramView(model.Store);

                        model.View.ViewContexts.Add(m.ViewContext);

                        FixUpDomainModelTreeView(m);
                        FixUpDiagramView(m);
                    }

                    if (m.ViewContext.DiagramView == null || m.ViewContext.DomainModelTreeView == null)
                    {
                        if (m.ViewContext.DomainModelTreeView == null)
                        {
                            m.ViewContext.DomainModelTreeView = new DomainModelTreeView(model.Store);
                            FixUpDomainModelTreeView(m);
                        }

                        if (m.ViewContext.DiagramView == null)
                        {
                            m.ViewContext.DiagramView = new DiagramView(model.Store);
                            FixUpDiagramView(m);
                        }
                    }

                    // diagram class view for designer diagram
                    if (m.ViewContext.DiagramView.DiagramClassViews.Count == 0 && m is ModelContext)
                    {
                        DiagramClassView vm = new DiagramClassView(model.Store);
                        vm.IsExpanded = true;
                        foreach (DiagramClass d in m.DiagramClasses)
                        {
                            if (d is DesignerDiagramClass)
                            {
                                vm.DiagramClass = d;
                                break;
                            }
                        }

                        m.ViewContext.DiagramView.DiagramClassViews.Add(vm);
                    }

                    // serialization
                    if (m.SerializationModel == null)
                    {
                        m.SerializationModel = new SerializationModel(model.Store);
                    }

                    // serialized domain model
                    if (m is ModelContext)
                    {
                        if (m.SerializationModel.SerializedDomainModel == null)
                        {
                            FixUpSerializedDomainModel(m as ModelContext);
                        }
                    }
                }
            }
            #endregion

            // view ids.
            if (model.View != null)
            {
                if (model.View.ModelTreeId == null || model.View.ModelTreeId == Guid.Empty)
                {
                    model.View.ModelTreeId = Guid.NewGuid();
                }

                if (model.View.DependenciesViewId == null || model.View.DependenciesViewId == Guid.Empty)
                {
                    model.View.DependenciesViewId = Guid.NewGuid();
                }

                if (model.View.ErrorListId == null || model.View.ErrorListId == Guid.Empty)
                {
                    model.View.ErrorListId = Guid.NewGuid();
                }

                if (model.View.PropertyGridId == null || model.View.PropertyGridId == Guid.Empty)
                {
                    model.View.PropertyGridId = Guid.NewGuid();
                }

                if (model.View.SearchId == null || model.View.SearchId == Guid.Empty)
                {
                    model.View.SearchId = Guid.NewGuid();
                }

                if (model.View.SearchResultId == null || model.View.SearchResultId == Guid.Empty)
                {
                    model.View.SearchResultId = Guid.NewGuid();
                }

                if (model.View.PluginWindowId == null || model.View.PluginWindowId == Guid.Empty)
                {
                    model.View.PluginWindowId = Guid.NewGuid();
                }
            }
        }
コード例 #15
0
        public override void ElementPropertyChanged(ElementPropertyChangedEventArgs e)
        {
            if (e.ModelElement != null)
            {
                if (e.ModelElement.Store.TransactionManager.CurrentTransaction != null)
                {
                    if (e.ModelElement.Store.TransactionManager.CurrentTransaction.IsSerializing)
                    {
                        return;
                    }
                }
            }

            if (e.ModelElement == null)
            {
                return;
            }

            if (ImmutabilityExtensionMethods.GetLocks(e.ModelElement) != Locks.None)
            {
                return;
            }

            DomainRole domainRole = e.ModelElement as DomainRole;


            if (domainRole != null)
            {
                if (domainRole.IsDeleted || domainRole.IsDeleting)
                {
                    return;
                }

                if (domainRole.Relationship.IsDeleted || domainRole.Relationship.IsDeleting)
                {
                    return;
                }

                if (e.DomainProperty.Id == DomainRole.NameDomainPropertyId)
                {
                    // display name tracking is already handled by NamedDomainElement
                    if (domainRole.IsNameTracking == TrackingEnum.True)
                    {
                        domainRole.IsNameTracking = TrackingEnum.False;
                    }
                    else if (domainRole.IsNameTracking == TrackingEnum.IgnoreOnce)
                    {
                        domainRole.IsNameTracking = TrackingEnum.True;
                    }

                    if (domainRole.Opposite != null)
                    {
                        if (domainRole.Opposite.IsPropertyNameTracking == TrackingEnum.True)
                        {
                            if (domainRole.Opposite.PropertyName != domainRole.Name)
                            {
                                domainRole.Opposite.PropertyName           = domainRole.Name;
                                domainRole.Opposite.IsPropertyNameTracking = TrackingEnum.IgnoreOnce;
                            }
                        }
                    }

                    if (domainRole.Relationship.IsNameTracking == TrackingEnum.True)
                    {
                        string name;
                        if (domainRole.Relationship is EmbeddingRelationship)
                        {
                            name = EmbeddingRelationship.GenerateDomainRelationshipName(domainRole.Relationship);
                        }
                        else
                        {
                            name = ReferenceRelationship.GenerateDomainRelationshipName(domainRole.Relationship);
                        }

                        if (domainRole.Relationship.Name != name)
                        {
                            domainRole.Relationship.Name           = name;
                            domainRole.Relationship.IsNameTracking = TrackingEnum.IgnoreOnce;
                        }
                    }

                    if (domainRole.Relationship is ReferenceRelationship)
                    {
                        ReferenceRelationship r = domainRole.Relationship as ReferenceRelationship;
                        if (domainRole == domainRole.Relationship.Source)
                        {
                            if (r.IsSerializationSourceNameTracking == TrackingEnum.True)
                            {
                                string name = domainRole.Name + "Ref";
                                if (domainRole.Name == domainRole.Opposite.Name)
                                {
                                    name = domainRole.Name + "Source" + "Ref";
                                }

                                if (name != r.SerializationSourceName)
                                {
                                    r.SerializationSourceName           = name;
                                    r.IsSerializationSourceNameTracking = TrackingEnum.IgnoreOnce;
                                }
                            }
                        }
                        else
                        {
                            if (r.IsSerializationTargetNameTracking == TrackingEnum.True)
                            {
                                string name = domainRole.Name + "Ref";
                                if (domainRole.Name == domainRole.Opposite.Name)
                                {
                                    name = domainRole.Name + "Target" + "Ref";
                                }

                                if (name != r.SerializationTargetName)
                                {
                                    r.SerializationTargetName           = name;
                                    r.IsSerializationTargetNameTracking = TrackingEnum.IgnoreOnce;
                                }
                            }
                        }
                    }
                }
                else if (e.DomainProperty.Id == DomainRole.PropertyNameDomainPropertyId)
                {
                    if (domainRole.IsPropertyNameTracking == TrackingEnum.True)
                    {
                        domainRole.IsPropertyNameTracking = TrackingEnum.False;
                    }
                    else if (domainRole.IsPropertyNameTracking == TrackingEnum.IgnoreOnce)
                    {
                        domainRole.IsPropertyNameTracking = TrackingEnum.True;
                    }

                    if (domainRole.IsPropertyDisplayNameTracking == TrackingEnum.True)
                    {
                        if (domainRole.PropertyDisplayName != StringHelper.BreakUpper(domainRole.PropertyName))
                        {
                            domainRole.PropertyDisplayName           = StringHelper.BreakUpper(domainRole.PropertyName);
                            domainRole.IsPropertyDisplayNameTracking = TrackingEnum.IgnoreOnce;
                        }
                    }
                }
                else if (e.DomainProperty.Id == DomainRole.PropertyDisplayNameDomainPropertyId)
                {
                    if (domainRole.IsPropertyDisplayNameTracking == TrackingEnum.True)
                    {
                        domainRole.IsPropertyDisplayNameTracking = TrackingEnum.False;
                    }
                    else if (domainRole.IsPropertyDisplayNameTracking == TrackingEnum.IgnoreOnce)
                    {
                        domainRole.IsPropertyDisplayNameTracking = TrackingEnum.True;
                    }
                }
            }
        }