Пример #1
0
        internal override PropagationMacroCommand PrePropagation()
        {
            List <PSMAssociation> list = Project.TranslateComponent <PIMAssociationEnd>(ComponentGuid).PIMAssociation.GetInterpretedComponents().Cast <PSMAssociation>().ToList <PSMAssociation>();

            if (list.Count == 0)
            {
                return(null);
            }

            PropagationMacroCommand command = new PropagationMacroCommand(Controller);

            command.Report = new CommandReport("Pre-propagation (update PIM association end cardinality)");

            foreach (PSMAssociation a in list)
            {
                acmdUpdatePSMAssociationCardinality d = new acmdUpdatePSMAssociationCardinality(Controller, a, newLower, newUpper)
                {
                    Propagate = false
                };
                command.Commands.Add(d);
            }

            return(command);
        }
Пример #2
0
        internal override PropagationMacroCommand PrePropagation()
        {
            PropagationMacroCommand command = new PropagationMacroCommand(Controller);

            command.Report = new CommandReport("Pre-propagation (move PIM attribute)");

            PIMAttribute attribute   = Project.TranslateComponent <PIMAttribute>(attributeGuid);
            PIMClass     targetClass = Project.TranslateComponent <PIMClass>(newClassGuid);
            PIMClass     sourceClass = attribute.PIMClass;

            IEnumerable <PIMAssociation> pimAssociations       = targetClass.GetAssociationsWith(sourceClass);
            IEnumerable <PSMAttribute>   interpretedAttributes = attribute.GetInterpretedComponents().Cast <PSMAttribute>().Where(a => a.ID != PropagateSource);

            foreach (PSMAttribute psmAttribute in interpretedAttributes)
            {
                PSMClass intclass = psmAttribute.PSMClass.NearestInterpretedClass();
                Debug.Assert(intclass.Interpretation == sourceClass, "Intclass != sourceclass");

                bool           found             = false;
                PSMAssociation parentAssociation = intclass.ParentAssociation;

                foreach (PIMAssociation association in pimAssociations)
                {
                    if (parentAssociation != null && parentAssociation.Interpretation == association)
                    {
                        //moving the attribute up in PSM
                        found = true;

                        cmdCreateNewPSMAttribute c2 = new cmdCreateNewPSMAttribute(Controller);
                        Guid attrGuid2 = Guid.NewGuid();
                        c2.AttributeGuid = attrGuid2;
                        c2.Set(intclass, psmAttribute.AttributeType, psmAttribute.Name, psmAttribute.Lower, psmAttribute.Upper, psmAttribute.Element);
                        command.Commands.Add(c2);

                        if (psmAttribute.PSMClass != intclass)
                        {
                            command.Commands.Add(new cmdMovePSMAttribute(Controller)
                            {
                                AttributeGuid = psmAttribute, ClassGuid = intclass, Propagate = false
                            });
                        }

                        acmdSynchroPSMAttributes s2 = new acmdSynchroPSMAttributes(Controller)
                        {
                            Propagate = false
                        };
                        s2.X1.Add(psmAttribute);
                        s2.X2.Add(attrGuid2);
                        command.Commands.Add(s2);

                        if (psmAttribute.PSMClass != intclass)
                        {
                            command.Commands.Add(new cmdMovePSMAttribute(Controller)
                            {
                                AttributeGuid = psmAttribute, ClassGuid = psmAttribute.PSMClass, Propagate = false
                            });
                        }

                        acmdSetInterpretation i2 = new acmdSetPSMAttributeInterpretation(Controller, attrGuid2, attribute);
                        command.Commands.Add(i2);

                        cmdMovePSMAttribute m2 = new cmdMovePSMAttribute(Controller)
                        {
                            Propagate = false
                        };
                        m2.Set(attrGuid2, intclass.NearestInterpretedParentClass());
                        command.Commands.Add(m2);
                    }

                    //select nearest interpreted child PSM classes, whose parent association's interpretation is the PIM association through which we are moving the attribute
                    IEnumerable <PSMClass> children = intclass.InterpretedSubClasses().Where <PSMClass>(pc => pc.Interpretation == targetClass && pc.ParentAssociation.Interpretation == association);
                    foreach (PSMClass child in children)
                    {
                        found = true;
                        cmdCreateNewPSMAttribute c = new cmdCreateNewPSMAttribute(Controller);
                        Guid attrGuid = Guid.NewGuid();
                        c.AttributeGuid = attrGuid;
                        c.Set(intclass, psmAttribute.AttributeType, psmAttribute.Name, psmAttribute.Lower, psmAttribute.Upper, psmAttribute.Element);
                        command.Commands.Add(c);

                        if (psmAttribute.PSMClass != intclass)
                        {
                            command.Commands.Add(new cmdMovePSMAttribute(Controller)
                            {
                                AttributeGuid = psmAttribute, ClassGuid = intclass, Propagate = false
                            });
                        }

                        acmdSynchroPSMAttributes s2 = new acmdSynchroPSMAttributes(Controller)
                        {
                            Propagate = false
                        };
                        s2.X1.Add(psmAttribute);
                        s2.X2.Add(attrGuid);
                        command.Commands.Add(s2);

                        if (psmAttribute.PSMClass != intclass)
                        {
                            command.Commands.Add(new cmdMovePSMAttribute(Controller)
                            {
                                AttributeGuid = psmAttribute, ClassGuid = psmAttribute.PSMClass, Propagate = false
                            });
                        }

                        acmdSetInterpretation i = new acmdSetPSMAttributeInterpretation(Controller, attrGuid, attribute);
                        command.Commands.Add(i);

                        cmdMovePSMAttribute m = new cmdMovePSMAttribute(Controller)
                        {
                            Propagate = false
                        };
                        m.Set(attrGuid, child);
                        command.Commands.Add(m);
                    }

                    if (!found)
                    {
                        cmdCreateNewPSMAttribute c = new cmdCreateNewPSMAttribute(Controller);
                        Guid attrGuid = Guid.NewGuid();
                        c.AttributeGuid = attrGuid;
                        c.Set(/*intclass*/ psmAttribute.PSMClass, psmAttribute.AttributeType, psmAttribute.Name, psmAttribute.Lower, psmAttribute.Upper, psmAttribute.Element);
                        command.Commands.Add(c);

                        /*if (psmAttribute.PSMClass != intclass)
                         * {
                         *  cmdMovePSMAttribute m1 = new cmdMovePSMAttribute(Controller) { Propagate = false };
                         *  m1.Set(psmAttribute, intclass);
                         *  command.Commands.Add(m1);
                         * }*/

                        acmdSynchroPSMAttributes s = new acmdSynchroPSMAttributes(Controller)
                        {
                            Propagate = false
                        };
                        s.X1.Add(psmAttribute);
                        s.X2.Add(attrGuid);
                        command.Commands.Add(s);

                        /*if (psmAttribute.PSMClass != intclass)
                         * {
                         *  cmdMovePSMAttribute m2 = new cmdMovePSMAttribute(Controller) { Propagate = false };
                         *  m2.Set(psmAttribute, psmAttribute.PSMClass);
                         *  command.Commands.Add(m2);
                         * }*/

                        acmdSetInterpretation i = new acmdSetPSMAttributeInterpretation(Controller, attrGuid, attribute);
                        command.Commands.Add(i);

                        //create psmassoc, class
                        Guid            ncGuid = Guid.NewGuid();
                        acmdNewPSMClass nc     = new acmdNewPSMClass(Controller, psmAttribute.PSMSchema)
                        {
                            ClassGuid = ncGuid
                        };
                        command.Commands.Add(nc);

                        acmdRenameComponent rc = new acmdRenameComponent(Controller, ncGuid, targetClass.Name);
                        command.Commands.Add(rc);

                        acmdSetInterpretation ic = new acmdSetPSMClassInterpretation(Controller, ncGuid, targetClass);
                        command.Commands.Add(ic);

                        Guid naGuid = Guid.NewGuid();

                        acmdNewPSMAssociation na = new acmdNewPSMAssociation(Controller, /*intclass*/ psmAttribute.PSMClass, ncGuid, psmAttribute.PSMSchema)
                        {
                            AssociationGuid = naGuid
                        };
                        command.Commands.Add(na);

                        acmdRenameComponent ra = new acmdRenameComponent(Controller, naGuid, association.Name);
                        command.Commands.Add(ra);

                        PIMAssociationEnd e = targetClass.PIMAssociationEnds.Single <PIMAssociationEnd>(aend => aend.PIMAssociation == association);
                        acmdUpdatePSMAssociationCardinality carda = new acmdUpdatePSMAssociationCardinality(Controller, naGuid, e.Lower, e.Upper)
                        {
                            Propagate = false
                        };
                        command.Commands.Add(carda);

                        acmdSetInterpretation ia = new acmdSetPSMAssociationInterpretation(Controller, naGuid, e, association);
                        command.Commands.Add(ia);

                        acmdMovePSMAttribute m = new acmdMovePSMAttribute(Controller, attrGuid, ncGuid)
                        {
                            Propagate = false
                        };
                        command.Commands.Add(m);
                    }
                }
                //delete attribute
                cmdDeletePSMAttribute d = new cmdDeletePSMAttribute(Controller)
                {
                    Propagate = false
                };
                d.Set(psmAttribute);
                command.Commands.Add(d);
            }

            command.CheckFirstOnlyInCanExecute = true;
            return(command);
        }