示例#1
0
        internal override PropagationMacroCommand PrePropagation()
        {
            PIMClass        pimClass = Project.TranslateComponent <PIMClass>(classGuid);
            List <PSMClass> list     = pimClass.GetInterpretedComponents().Cast <PSMClass>().ToList <PSMClass>();

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

            PropagationMacroCommand command = new PropagationMacroCommand(Controller);

            command.Report = new CommandReport("Pre-propagation (update PIM class abstract property)");

            foreach (PSMClass psmClass in list)
            {
                acmdUpdatePSMClassAbstract cmd = new acmdUpdatePSMClassAbstract(Controller, psmClass, newAbstract)
                {
                    Propagate = false
                };
                command.Commands.Add(cmd);
            }

            return(command);
        }
        internal override PropagationMacroCommand PrePropagation()
        {
            PIMGeneralization pimGeneralization  = Project.TranslateComponent <PIMGeneralization>(generalizationGuid);
            PIMClass          newPIMGeneral      = Project.TranslateComponent <PIMClass>(specialClassGuid);
            PIMClass          pimSpecificClass   = pimGeneralization.Specific;
            PIMClass          oldPIMGeneral      = pimGeneralization.General;
            List <PSMClass>   psmSpecificClasses = pimSpecificClass.GetInterpretedComponents().Cast <PSMClass>().ToList();

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

            PropagationMacroCommand command = new PropagationMacroCommand(Controller)
            {
                CheckFirstOnlyInCanExecute = true
            };

            command.Report = new CommandReport("Pre-propagation (specialize PIM generalization)");

            foreach (PSMClass c in psmSpecificClasses)
            {
                if (c.GeneralizationAsSpecific != null)
                {
                    PSMClass oldPSMGeneral = c.GeneralizationAsSpecific.General;
                    if (oldPSMGeneral.Interpretation == oldPIMGeneral)
                    {
                        IEnumerable <PSMClass> rightDescendants = oldPSMGeneral.GeneralizationsAsGeneral.Where(g => g.Specific.Interpretation == newPIMGeneral).Select(g => g.Specific);
                        if (rightDescendants.Count() == 1)
                        //0 - there is no suitable class.. nothing has to happen,
                        //>1 there are more... nothing will happen and it is up to the user (instead of duplicating or SR). Coherence not violated.
                        {
                            PSMClass newPSMGeneral = rightDescendants.Single();
                            command.Commands.Add(new acmdSpecializePSMGeneralization(Controller, c.GeneralizationAsSpecific, newPSMGeneral)
                            {
                                Propagate = false
                            });
                        }
                    }
                }
            }

            return(command);
        }
示例#3
0
        internal override PropagationMacroCommand PrePropagation()
        {
            PIMClass        pimClass = Project.TranslateComponent <PIMClass>(classGuid);
            List <PSMClass> list     = pimClass.GetInterpretedComponents().Cast <PSMClass>().ToList <PSMClass>();

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

            PropagationMacroCommand command = new PropagationMacroCommand(Controller)
            {
                CheckFirstOnlyInCanExecute = true
            };

            command.Report = new CommandReport("Pre-propagation (update PIM class final property)");

            foreach (PSMClass c in list)
            {
                if (c.GeneralizationsAsGeneral.Count > 0)
                {
                    foreach (PSMGeneralization g in c.GeneralizationsAsGeneral)
                    {
                        //This should be only in case of:
                        Debug.Assert(g.General.Interpretation == g.Specific.Interpretation);
                        //If not, the PSM class was still involved in a generalization and
                        acmdDeletePSMGeneralization d1 = new acmdDeletePSMGeneralization(Controller, g)
                        {
                            Propagate = false
                        };
                        command.Commands.Add(d1);
                    }
                }

                acmdUpdatePSMClassFinal d = new acmdUpdatePSMClassFinal(Controller, c, newFinal)
                {
                    Propagate = false
                };
                command.Commands.Add(d);
            }

            return(command);
        }
示例#4
0
        internal override PropagationMacroCommand PrePropagation()
        {
            IEnumerable <PIMAssociation> aX1 = Project.TranslateComponentCollection <PIMAssociation>(X1);
            IEnumerable <PIMAssociation> aX2 = Project.TranslateComponentCollection <PIMAssociation>(X2);

            if (aX1.Count() == 0 || aX2.Count() == 0 || aX1.Union(aX2).Count() == 1)
            {
                return(null);
            }

            PropagationMacroCommand command = new PropagationMacroCommand(Controller)
            {
                CheckFirstOnlyInCanExecute = true
            };

            command.Report = new CommandReport("Pre-propagation (synchronize PIM association sets)");
            PIMClass pimClass1 = aX2.First().PIMClasses.First();
            PIMClass pimClass2 = aX2.First().PIMClasses.Last();

            //Twice... X1 => X2, X2 => X1
            for (int i = 0; i < 2; i++)
            {
                IEnumerable <PSMClass> allPSMClasses = pimClass1.GetInterpretedComponents().Union(pimClass2.GetInterpretedComponents()).Cast <PSMClass>();
                //Selects psmClasses affected by the synchronization (those which have aX1 counterpart present)
                List <PSMClass> psmClasses = new List <PSMClass>();
                foreach (PSMClass c in allPSMClasses)
                {
                    IEnumerable <PSMAssociation> assocs = c.GetContextPSMAssociations();
                    if (assocs.Union(c.ParentAssociation == null
                                ? Enumerable.Empty <PSMAssociation>()
                                : Enumerable.Repeat(c.ParentAssociation, 1))
                        .Where(a => a.Interpretation != null)
                        .Select(psma => psma.Interpretation as PIMAssociation)
                        .Intersect(aX1)
                        .OrderBy(k => k.ID)
                        .SequenceEqual(aX1.OrderBy(j => j.ID)))
                    {
                        psmClasses.Add(c);
                    }
                }

                //Elimination of SRs where C is affected and SR is a SR of C
                bool found = true;
                while (found)
                {
                    found = false;
                    List <PSMClass> list = new List <PSMClass>();
                    foreach (PSMClass psmClass in psmClasses)
                    {
                        if (psmClass.RepresentedClass != null &&
                            psmClasses.Contains(psmClass.RepresentedClass) &&
                            !psmClass.GetContextPSMAssociations(true)
                            .Union(psmClass.ParentAssociation == null
                                        ? Enumerable.Empty <PSMAssociation>()
                                        : Enumerable.Repeat(psmClass.ParentAssociation, 1))
                            .Where(a => a.Interpretation != null)
                            .Select(psma => psma.Interpretation as PIMAssociation)
                            .Intersect(aX1)
                            .OrderBy(k => k.ID)
                            .SequenceEqual(aX1.OrderBy(j => j.ID)))
                        {
                            found = true;
                        }
                        else
                        {
                            list.Add(psmClass);
                        }
                    }
                    psmClasses = list;
                }

                foreach (PSMClass psmClass in psmClasses)
                {
                    IEnumerable <PSMAssociation> parentEnum =
                        psmClass.ParentAssociation == null
                        ? Enumerable.Empty <PSMAssociation>()
                        : Enumerable.Repeat(psmClass.ParentAssociation, 1);

                    IEnumerable <Tuple <PSMAssociation, IEnumerable <ModelIterator.MoveStep> > > associationsAndPaths = psmClass.GetContextPSMAssociationsWithPaths();
                    IEnumerable <PSMAssociation> associations            = associationsAndPaths.Select(t => t.Item1).Union(parentEnum);
                    IEnumerable <PSMAssociation> interpretedAssociations = associations.Where(a => a.Interpretation != null);
                    IEnumerable <PSMAssociation> responsibleAssociations = interpretedAssociations.Where(a => aX1.Contains(a.Interpretation as PIMAssociation));
                    IEnumerable <PIMAssociation> interpretations         = interpretedAssociations.Select(a => a.Interpretation as PIMAssociation);
                    IEnumerable <PIMAssociation> associationsToPropagate = aX2.Where(a => !interpretations.Contains(a));

                    IEnumerable <PSMAssociation> psmAssociationsToMoveList = interpretedAssociations.Where(a => a.Parent != psmClass && a.Child != psmClass && aX1.Contains((PIMAssociation)a.Interpretation) || aX2.Contains((PIMAssociation)a.Interpretation));
                    Dictionary <PSMAssociation, IEnumerable <ModelIterator.MoveStep> > psmAssociationsToMove = new Dictionary <PSMAssociation, IEnumerable <ModelIterator.MoveStep> >();
                    foreach (PSMAssociation t in psmAssociationsToMoveList)
                    {
                        Tuple <PSMAssociation, IEnumerable <ModelIterator.MoveStep> > tuple = associationsAndPaths.Single(tup => tup.Item1 == t);
                        psmAssociationsToMove.Add(tuple.Item1, tuple.Item2);
                    }

                    List <Guid> newAssociationsGuid = new List <Guid>();
                    foreach (PIMAssociation a in associationsToPropagate)
                    {
                        Guid classGuid = Guid.NewGuid();
                        command.Commands.Add(new acmdNewPSMClass(Controller, psmClass.PSMSchema)
                        {
                            ClassGuid = classGuid
                        });
                        command.Commands.Add(new acmdRenameComponent(Controller, classGuid, psmClass.Interpretation == pimClass1 ? pimClass2.Name : pimClass1.Name));
                        command.Commands.Add(new acmdSetPSMClassInterpretation(Controller, classGuid, psmClass.Interpretation == pimClass1 ? pimClass2 : pimClass1));

                        Guid assocGuid = Guid.NewGuid();
                        command.Commands.Add(new acmdNewPSMAssociation(Controller, psmClass, classGuid, psmClass.PSMSchema)
                        {
                            AssociationGuid = assocGuid
                        });
                        command.Commands.Add(new acmdRenameComponent(Controller, assocGuid, a.Name));
                        PIMAssociationEnd e = a.PIMAssociationEnds.First(ae => ae.PIMClass != psmClass.Interpretation);
                        command.Commands.Add(new acmdUpdatePSMAssociationCardinality(Controller, assocGuid, e.Lower, e.Upper));
                        command.Commands.Add(new acmdSetPSMAssociationInterpretation(Controller, assocGuid, e, a));
                        newAssociationsGuid.Add(assocGuid);
                    }

                    foreach (KeyValuePair <PSMAssociation, IEnumerable <ModelIterator.MoveStep> > kvp in psmAssociationsToMove)
                    {
                        foreach (ModelIterator.MoveStep s in kvp.Value)
                        {
                            if (s.StepType == ModelIterator.MoveStep.MoveStepType.None)
                            {
                                continue;
                            }
                            command.Commands.Add(new acmdReconnectPSMAssociation(Controller, kvp.Key, s.StepTarget)
                            {
                                Propagate = false
                            });
                        }
                    }

                    IEnumerable <Guid> synchroGroup1 = responsibleAssociations.Select <PSMAssociation, Guid>(a => a);
                    IEnumerable <Guid> synchroGroup2 = associations.Where(a => aX2.Contains((PIMAssociation)a.Interpretation)).Select <PSMAssociation, Guid>(a => a).Union(newAssociationsGuid);

                    command.Commands.Add(new acmdSynchroPSMAssociations(Controller)
                    {
                        X1 = synchroGroup1.ToList(), X2 = synchroGroup2.ToList(), Propagate = false
                    });

                    foreach (KeyValuePair <PSMAssociation, IEnumerable <ModelIterator.MoveStep> > kvp in psmAssociationsToMove)
                    {
                        bool first = true;
                        foreach (ModelIterator.MoveStep s in kvp.Value.Reverse <ModelIterator.MoveStep>())
                        {
                            if (first)
                            {
                                first = false;
                            }
                            else
                            {
                                command.Commands.Add(new acmdReconnectPSMAssociation(Controller, kvp.Key, s.StepTarget)
                                {
                                    Propagate = false
                                });
                            }
                        }
                    }
                }

                //Swap the two lists and do it again
                IEnumerable <PIMAssociation> temp = aX1;
                aX1 = aX2;
                aX2 = temp;
            }

            return(command);
        }
示例#5
0
        internal override PropagationMacroCommand PrePropagation()
        {
            PIMGeneralization pimGeneralization  = Project.TranslateComponent <PIMGeneralization>(generalizationGuid);
            PIMClass          pimSpecificClass   = pimGeneralization.Specific;
            PIMClass          oldPIMGeneral      = pimGeneralization.General;
            PIMClass          newPIMGeneral      = oldPIMGeneral.GeneralizationAsSpecific.General;
            List <PSMClass>   classesToCheck     = pimSpecificClass.GetSpecificClasses(true).SelectMany(c => c.GetInterpretedComponents().Cast <PSMClass>()).ToList();
            List <PSMClass>   psmSpecificClasses = pimSpecificClass.GetInterpretedComponents().Cast <PSMClass>().ToList();

            /* ALTERNATIVE SOLUTION - TO BE THOUGHT THROUGH - MOVE AS MANY ATTS AND ASSOCS AS POSSIBLE - DOES IT MAKE SENSE?
             * What about those in inheritance subtree??? Must go through every PSM class that has interpretation in the inheritance hierarchy subtree
             *
             *
             * 1) Is there a need to move atts and assocs? No - OK
             *  1a) Yes - where? Is there the "old general class"?
             *   1aa) Yes - There
             *   1ab) No - Is there superparent?
             *    1aba) Yes - Create old parent and there and specialize the subtree under it
             *    1abb) No - create parent, move "bad" atts and assocs, delete generalization.
             * 2) Now assocs and attrs are OK. Has inh. parent same interpretation or is there no generalization? Yes - nothing
             *  2a) No - is it old parent? Yes - generalize
             *   2aa) No - Nothing - the generalization does not affect the current PSM class.
             */

            PropagationMacroCommand command = new PropagationMacroCommand(Controller)
            {
                CheckFirstOnlyInCanExecute = true
            };

            command.Report = new CommandReport("Pre-propagation (generalize PIM generalization)");

            //DELETE ATTS AND ASSOCS THAT VIOLATE INTERPRETATION AFTER GEN PIM GEN
            foreach (PSMClass c in classesToCheck)
            {
                //parent association (just check it...), it should not be involved...
                Debug.Assert(c.ParentAssociation == null || c.ParentAssociation.Interpretation == null || c.Interpretation == (c.ParentAssociation.Interpretation as PIMAssociation)
                             .PIMAssociationEnds
                             .Single(e => e != c.ParentAssociation.InterpretedAssociationEnd));

                List <PSMAttribute> attributesLost = c.GetContextPSMAttributes(true).Where
                                                         (a => a.Interpretation != null && (a.Interpretation as PIMAttribute).PIMClass == pimGeneralization.General).ToList();

                List <PSMAssociation> associationsLost = c.GetContextPSMAssociations(true).Where
                                                             (a => a.Interpretation != null && a.InterpretedAssociationEnd.PIMClass == pimGeneralization.General).ToList();

                foreach (PSMAttribute att in attributesLost)
                {
                    if (att.PSMClass != c)
                    {
                        command.Commands.Add(new cmdMovePSMAttribute(Controller)
                        {
                            AttributeGuid = att, ClassGuid = c
                        });
                    }
                    command.Commands.Add(new cmdDeletePSMAttribute(Controller)
                    {
                        AttributeGuid = att
                    });
                }

                foreach (PSMAssociation assoc in associationsLost)
                {
                    if (assoc.Parent != c)
                    {
                        command.Commands.Add(new cmdReconnectPSMAssociation(Controller)
                        {
                            AssociationGuid = assoc, NewParentGuid = c
                        });
                    }
                    command.Commands.Add(new cmdDeletePSMAssociation(Controller)
                    {
                        AssociationGuid = assoc
                    });
                }
            }

            foreach (PSMClass c in psmSpecificClasses)
            {
                if (c.GeneralizationAsSpecific != null && c.GeneralizationAsSpecific.General.Interpretation != c.Interpretation)
                {
                    if (c.GeneralizationAsSpecific.General.Interpretation == oldPIMGeneral)
                    {
                        command.Commands.Add(new acmdGeneralizePSMGeneralization(Controller, c.GeneralizationAsSpecific)
                        {
                            Propagate = false
                        });
                    }
                }
            }

            return(command);
        }
示例#6
0
        internal override PropagationMacroCommand PrePropagation()
        {
            IEnumerable <PIMAttribute> aX1 = Project.TranslateComponentCollection <PIMAttribute>(X1);
            IEnumerable <PIMAttribute> aX2 = Project.TranslateComponentCollection <PIMAttribute>(X2);

            if (aX1.Count() == 0 || aX2.Count() == 0)
            {
                return(null);
            }

            PropagationMacroCommand command = new PropagationMacroCommand(Controller)
            {
                CheckFirstOnlyInCanExecute = true
            };

            command.Report = new CommandReport("Pre-propagation (synchronize PIM attribute sets)");
            PIMClass pimClass = aX2.First().PIMClass;

            //Twice... X1 => X2, X2 => X1
            for (int i = 0; i < 2; i++)
            {
                IEnumerable <PSMClass> allPSMClasses = pimClass.GetInterpretedComponents().Cast <PSMClass>();
                List <PSMClass>        psmClasses    = new List <PSMClass>();
                foreach (PSMClass c in allPSMClasses)
                {
                    IEnumerable <PSMAttribute> atts = c.GetContextPSMAttributes();
                    if (atts.Where(a => a.Interpretation != null)
                        .Select(psma => psma.Interpretation as PIMAttribute)
                        .Intersect(aX1)
                        .OrderBy(k => k.ID)
                        .SequenceEqual(aX1.OrderBy(j => j.ID)))
                    {
                        psmClasses.Add(c);
                    }
                }

                //Elimination of SRs where C is affected and SR is a SR of C
                bool found = true;
                while (found)
                {
                    found = false;
                    List <PSMClass> list = new List <PSMClass>();
                    foreach (PSMClass psmClass in psmClasses)
                    {
                        if (psmClass.RepresentedClass != null &&
                            psmClasses.Contains(psmClass.RepresentedClass) &&
                            !psmClass.GetContextPSMAttributes(true)
                            .Where(a => a.Interpretation != null)
                            .Select(psma => psma.Interpretation as PIMAttribute)
                            .Intersect(aX1)
                            .OrderBy(k => k.ID)
                            .SequenceEqual(aX1.OrderBy(j => j.ID)))
                        {
                            found = true;
                        }
                        else
                        {
                            list.Add(psmClass);
                        }
                    }
                    psmClasses = list;
                }

                foreach (PSMClass psmClass in psmClasses)
                {
                    IEnumerable <Tuple <PSMAttribute, IEnumerable <ModelIterator.MoveStep> > > attributesAndPaths = psmClass.GetContextPSMAttributesWithPaths();
                    IEnumerable <PSMAttribute> attributes            = attributesAndPaths.Select(t => t.Item1);
                    IEnumerable <PSMAttribute> interpretedAttributes = attributes.Where(a => a.Interpretation != null);
                    IEnumerable <PSMAttribute> responsibleAttributes = interpretedAttributes.Where(a => aX1.Contains(a.Interpretation as PIMAttribute));
                    IEnumerable <PIMAttribute> interpretations       = interpretedAttributes.Select(a => a.Interpretation as PIMAttribute);
                    IEnumerable <PIMAttribute> attributesToPropagate = aX2.Where(a => !interpretations.Contains(a));

                    IEnumerable <PSMAttribute> attributesToMoveList = interpretedAttributes.Where(a => a.PSMClass != psmClass && (aX1.Contains((PIMAttribute)a.Interpretation) || aX2.Contains((PIMAttribute)a.Interpretation)));
                    Dictionary <PSMAttribute, IEnumerable <ModelIterator.MoveStep> > psmAttributesToMove = new Dictionary <PSMAttribute, IEnumerable <ModelIterator.MoveStep> >();
                    foreach (PSMAttribute t in attributesToMoveList)
                    {
                        Tuple <PSMAttribute, IEnumerable <ModelIterator.MoveStep> > tuple = attributesAndPaths.Single(tup => tup.Item1 == t);
                        psmAttributesToMove.Add(tuple.Item1, tuple.Item2);
                    }

                    List <Guid> newAttributesGuid = new List <Guid>();
                    foreach (PIMAttribute a in attributesToPropagate)
                    {
                        cmdCreateNewPSMAttribute c = new cmdCreateNewPSMAttribute(Controller);
                        Guid attrGuid = Guid.NewGuid();
                        c.AttributeGuid = attrGuid;
                        c.Set(psmClass, a.AttributeType, a.Name, a.Lower, a.Upper, responsibleAttributes.First().Element);
                        command.Commands.Add(c);
                        newAttributesGuid.Add(attrGuid);

                        acmdSetInterpretation cmdi = new acmdSetPSMAttributeInterpretation(Controller, attrGuid, a);
                        command.Commands.Add(cmdi);
                    }

                    foreach (KeyValuePair <PSMAttribute, IEnumerable <ModelIterator.MoveStep> > kvp in psmAttributesToMove)
                    {
                        foreach (ModelIterator.MoveStep s in kvp.Value)
                        {
                            if (s.StepType == ModelIterator.MoveStep.MoveStepType.None)
                            {
                                continue;
                            }
                            command.Commands.Add(new acmdMovePSMAttribute(Controller, kvp.Key, s.StepTarget)
                            {
                                Propagate = false
                            });
                        }
                    }

                    IEnumerable <Guid> synchroGroup1 = responsibleAttributes.Select <PSMAttribute, Guid>(a => a);
                    IEnumerable <Guid> synchroGroup2 = attributes.Where(a => aX2.Contains((PIMAttribute)a.Interpretation)).Select <PSMAttribute, Guid>(a => a).Union(newAttributesGuid);

                    command.Commands.Add(new acmdSynchroPSMAttributes(Controller)
                    {
                        X1 = synchroGroup1.ToList(), X2 = synchroGroup2.ToList(), Propagate = false
                    });

                    foreach (KeyValuePair <PSMAttribute, IEnumerable <ModelIterator.MoveStep> > kvp in psmAttributesToMove)
                    {
                        bool first = true;
                        foreach (ModelIterator.MoveStep s in kvp.Value.Reverse <ModelIterator.MoveStep>())
                        {
                            if (first)
                            {
                                first = false;
                            }
                            else
                            {
                                command.Commands.Add(new acmdMovePSMAttribute(Controller, kvp.Key, s.StepTarget)
                                {
                                    Propagate = false
                                });
                            }
                        }
                    }
                }

                //Swap the two lists and do it again
                IEnumerable <PIMAttribute> temp = aX1;
                aX1 = aX2;
                aX2 = temp;
            }

            return(command);
        }