Ejemplo n.º 1
0
        internal override PropagationMacroCommand PostPropagation()
        {
            PSMAssociation       psmAssociation = Project.TranslateComponent <PSMAssociation>(associationGuid);
            PSMAssociationMember source         = Project.TranslateComponent <PSMAssociationMember>(oldParentGuid);
            PSMAssociationMember target         = Project.TranslateComponent <PSMAssociationMember>(newParentGuid);

            PSMClass oldIntContext = (source is PSMClass && (source as PSMClass).Interpretation != null)? (source as PSMClass) : source.NearestInterpretedParentClass();
            PSMClass newIntContext = (target is PSMClass && (target as PSMClass).Interpretation != null) ? (target as PSMClass) : target.NearestInterpretedParentClass();

            if (oldIntContext == null)
            {
                return(null);
            }
            if (newIntContext != null && oldIntContext.Interpretation == newIntContext.Interpretation)
            {
                return(null);
            }

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

            command.Report = new CommandReport("Post-propagation (reconnect parent PSM association end)");

            if (newIntContext == null)
            {
                foreach (PSMAttribute a in psmAssociation.Child.UnInterpretedSubClasses(true)
                         .SelectMany <PSMClass, PSMAttribute>(c => c.PSMAttributes)
                         .Where(a => a.Interpretation != null))
                {
                    command.Commands.Add(new acmdSetPSMAttributeInterpretation(Controller, a, Guid.Empty));
                }
                foreach (PSMAssociation a in psmAssociation.Child.UnInterpretedSubClasses(true)
                         .SelectMany <PSMClass, PSMAssociation>(c => c.ChildPSMAssociations)
                         .Where(a => a.Interpretation != null))
                {
                    command.Commands.Add(new acmdSetPSMAssociationInterpretation(Controller, a, Guid.Empty, Guid.Empty));
                }
            }
            if (psmAssociation.Interpretation == null)
            {
                foreach (PSMAttribute a in psmAssociation.Child.UnInterpretedSubClasses(true)
                         .SelectMany <PSMClass, PSMAttribute>(c => c.PSMAttributes)
                         .Where(a => a.Interpretation != null))
                {
                    command.Commands.Add(new acmdMovePIMAttribute(Controller, a.Interpretation, newIntContext.Interpretation)
                    {
                        PropagateSource = a
                    });
                }
                foreach (PSMAssociation a in psmAssociation.Child.UnInterpretedSubClasses(true)
                         .SelectMany <PSMClass, PSMAssociation>(c => c.ChildPSMAssociations)
                         .Where(a => a.Interpretation != null))
                {
                    PIMAssociationEnd e = (a.Interpretation as PIMAssociation).PIMAssociationEnds.First(ae => ae.PIMClass == oldIntContext.Interpretation);
                    command.Commands.Add(new acmdMoveAssociationEnd(Controller, e, newIntContext.Interpretation)
                    {
                        PropagateSource = a
                    });
                }
            }
            else
            {
                if (newIntContext == null)
                {
                    command.Commands.Add(new acmdSetPSMAssociationInterpretation(Controller, psmAssociation, Guid.Empty, Guid.Empty));
                }
                else
                {
                    PIMAssociationEnd e = (psmAssociation.Interpretation as PIMAssociation).PIMAssociationEnds.First(ae => ae.PIMClass == oldIntContext.Interpretation);
                    command.Commands.Add(new acmdMoveAssociationEnd(Controller, e, newIntContext.Interpretation)
                    {
                        PropagateSource = psmAssociation
                    });
                }
            }

            return(command);
        }