示例#1
0
        private bool ApplyAttributeChanges()
        {
            #region check for deleted attributes

            foreach (PSMAttribute psmAttribute in psmClass.PSMAttributes)
            {
                bool found = false;
                foreach (FakePSMAttribute fakeAttribute in fakeAttributes)
                {
                    if (fakeAttribute.SourceAttribute == psmAttribute && fakeAttribute.Checked)
                    {
                        found = true;
                        break;
                    }
                    else if (fakeAttribute.SourceAttribute == psmAttribute && !fakeAttribute.Checked)
                    {
                        fakeAttribute.SourceAttribute = null;
                    }
                }
                if (!found)
                {
                    Controller.Commands.Complex.PSM.cmdDeletePSMAttribute deleteCommand = new Controller.Commands.Complex.PSM.cmdDeletePSMAttribute(controller);
                    deleteCommand.Set(psmAttribute);
                    controller.CreatedMacro.Commands.Add(deleteCommand);
                }
            }

            #endregion

            // check for changes and new attributes
            var modified = from FakePSMAttribute a in fakeAttributes
                           where a.SourceAttribute != null && a.SomethingChanged()
                           select a;
            var added = from FakePSMAttribute a in fakeAttributes where a.SourceAttribute == null select a;

            #region editing exisiting attribute
            foreach (FakePSMAttribute modifiedAttribute in modified)
            {
                PSMAttribute sourceAttribute = modifiedAttribute.SourceAttribute;
                uint         lower;
                UnlimitedInt upper;
                if (
                    !IHasCardinalityExt.ParseMultiplicityString(modifiedAttribute.Multiplicity, out lower,
                                                                out upper))
                {
                    error = true;
                }
                cmdUpdatePSMAttribute updateCommand = new cmdUpdatePSMAttribute(controller);
                updateCommand.Set(sourceAttribute, modifiedAttribute.Type, modifiedAttribute.Name, lower, upper, modifiedAttribute.XFormElement, modifiedAttribute.DefaultValue);
                updateCommand.InterpretedAttribute = modifiedAttribute.RepresentedAttribute;
                controller.CreatedMacro.Commands.Add(updateCommand);
            }
            #endregion

            #region new attribute
            foreach (FakePSMAttribute addedAttribute in added)
            {
                if (!string.IsNullOrEmpty(addedAttribute.Name) && addedAttribute.Checked)
                {
                    uint         lower = 1;
                    UnlimitedInt upper = 1;
                    if (!String.IsNullOrEmpty(addedAttribute.Multiplicity))
                    {
                        if (!IHasCardinalityExt.ParseMultiplicityString(addedAttribute.Multiplicity, out lower, out upper))
                        {
                            error = true;
                        }
                    }
                    Exolutio.Controller.Commands.Complex.PSM.cmdCreateNewPSMAttribute createNewPsmAttribute = new Exolutio.Controller.Commands.Complex.PSM.cmdCreateNewPSMAttribute(controller);
                    createNewPsmAttribute.Set(psmClass, addedAttribute.Type, addedAttribute.Name, lower, upper, addedAttribute.XFormElement);
                    createNewPsmAttribute.AttributeGuid = Guid.NewGuid();
                    addedAttribute.AddedAttributeID     = createNewPsmAttribute.AttributeGuid;
                    if (addedAttribute.RepresentedAttribute != null)
                    {
                        createNewPsmAttribute.InterpretedAttribute = addedAttribute.RepresentedAttribute;
                    }
                    controller.CreatedMacro.Commands.Add(createNewPsmAttribute);
                }
            }
            #endregion

            #region ordering

            {
                List <Guid> ordering = new List <Guid>();
                foreach (FakePSMAttribute attribute in fakeAttributes)
                {
                    if (attribute.SourceAttribute != null)
                    {
                        ordering.Add(attribute.SourceAttribute.ID);
                    }
                    else if (attribute.AddedAttributeID != Guid.Empty)
                    {
                        ordering.Add(attribute.AddedAttributeID);
                    }
                }

                cmdReorderComponents <PSMAttribute> reorderCommand = new cmdReorderComponents <PSMAttribute>(controller)
                {
                    ComponentGuids = ordering, OwnerCollection = psmClass.PSMAttributes
                };
                controller.CreatedMacro.Commands.Add(reorderCommand);
            }

            #endregion

            return(!error);
        }
示例#2
0
        private bool ApplyAssociationChanges()
        {
            #region check for deleted associations

            foreach (PSMAssociation psmAssociation in psmClass.ChildPSMAssociations)
            {
                bool found = false;
                foreach (FakePSMAssociation fakeAssociation in fakeAssociations)
                {
                    if (fakeAssociation.SourceAssociation == psmAssociation && fakeAssociation.Checked)
                    {
                        found = true;
                        break;
                    }
                    else if (fakeAssociation.SourceAssociation == psmAssociation && !fakeAssociation.Checked)
                    {
                        fakeAssociation.SourceAssociation = null;
                    }
                }
                if (!found)
                {
                    MessageBoxResult result = ExolutioYesNoBox.Show("Cut or delete", string.Format("Click 'Yes' if you want to delete the association '{0}' with the whole subtree.\nClick 'No' if you want to delete the association and make the subtree a new tree. ", psmAssociation));
                    if (result == MessageBoxResult.No)
                    {
                        Exolutio.Controller.Commands.Complex.PSM.cmdDeletePSMAssociation deleteCommand = new Exolutio.Controller.Commands.Complex.PSM.cmdDeletePSMAssociation(controller);
                        deleteCommand.Set(psmAssociation);
                        controller.CreatedMacro.Commands.Add(deleteCommand);
                    }
                    else if (result == MessageBoxResult.Yes)
                    {
                        cmdDeletePSMAssociationRecursive deleteCommand = new cmdDeletePSMAssociationRecursive(controller);
                        deleteCommand.Set(psmAssociation);
                        controller.CreatedMacro.Commands.Add(deleteCommand);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }

            #endregion

            // check for changes and new associations
            var modified = from FakePSMAssociation a in fakeAssociations
                           where a.SourceAssociation != null && a.SomethingChanged()
                           select a;
            var added = from FakePSMAssociation a in fakeAssociations where a.SourceAssociation == null && a.Checked select a;

            #region editing exisiting association
            foreach (FakePSMAssociation modifiedAssociation in modified)
            {
                PSMAssociation sourceAssociation = modifiedAssociation.SourceAssociation;
                uint           lower;
                UnlimitedInt   upper;
                if (
                    !IHasCardinalityExt.ParseMultiplicityString(modifiedAssociation.Multiplicity, out lower,
                                                                out upper))
                {
                    error = true;
                    return(!error);
                }

                cmdUpdatePSMAssociation updateCommand = new cmdUpdatePSMAssociation(controller);
                updateCommand.Set(sourceAssociation, modifiedAssociation.Name, lower, upper);
                updateCommand.InterpretedAssociation = modifiedAssociation.RepresentedPIMAssociation;
                controller.CreatedMacro.Commands.Add(updateCommand);
            }
            #endregion

            #region new association
            foreach (FakePSMAssociation addedAssociation in added)
            {
                uint         lower = 1;
                UnlimitedInt upper = 1;
                if (!String.IsNullOrEmpty(addedAssociation.Multiplicity))
                {
                    if (!IHasCardinalityExt.ParseMultiplicityString(addedAssociation.Multiplicity, out lower, out upper))
                    {
                        error = true;
                        return(!error);
                    }
                }

                if (addedAssociation.RepresentedPIMAssociation == null)
                {
                    cmdNewPSMClass createNewPSMClass = new cmdNewPSMClass(controller);
                    createNewPSMClass.SchemaGuid = psmClass.Schema;
                    createNewPSMClass.ClassGuid  = Guid.NewGuid();
                    controller.CreatedMacro.Commands.Add(createNewPSMClass);

                    cmdNewPSMAssociation createNewPSMAssociation = new cmdNewPSMAssociation(controller);
                    addedAssociation.AddedAssociationID     = Guid.NewGuid();
                    createNewPSMAssociation.AssociationGuid = addedAssociation.AddedAssociationID;
                    createNewPSMAssociation.Set(psmClass, createNewPSMClass.ClassGuid, psmClass.Schema);
                    controller.CreatedMacro.Commands.Add(createNewPSMAssociation);

                    cmdUpdatePSMAssociation updateCommand = new cmdUpdatePSMAssociation(controller);
                    updateCommand.Set(createNewPSMAssociation.AssociationGuid, addedAssociation.Name, lower, upper);
                    controller.CreatedMacro.Commands.Add(updateCommand);
                }
                else
                {
                    //ExolutioMessageBox.Show("Creating new association", addedAssociation.Name, "");
                    cmdCreateNewPSMClassAsIntChild createNewPSMAssociation = new cmdCreateNewPSMClassAsIntChild(controller);
                    addedAssociation.AddedAssociationID = Guid.NewGuid();

                    if (addedAssociation.SourcePIMAssociationEnd == null)
                    {
                        foreach (PIMAssociationEnd otherEnd in addedAssociation.RepresentedPIMAssociation.PIMAssociationEnds)
                        {
                            if (otherEnd.PIMClass == psmClass.Interpretation)
                            {
                                continue;
                            }
                            addedAssociation.SourcePIMAssociationEnd = otherEnd;
                        }
                    }

                    createNewPSMAssociation.Set(psmClass, addedAssociation.SourcePIMAssociationEnd, Guid.Empty, addedAssociation.AddedAssociationID);
                    controller.CreatedMacro.Commands.Add(createNewPSMAssociation);

                    cmdUpdatePSMAssociation updateCommand = new cmdUpdatePSMAssociation(controller);
                    updateCommand.Set(addedAssociation.AddedAssociationID, addedAssociation.Name, lower, upper);
                    controller.CreatedMacro.Commands.Add(updateCommand);
                }
            }
            #endregion

            #region ordering

            {
                List <Guid> ordering = new List <Guid>();
                foreach (FakePSMAssociation association in fakeAssociations)
                {
                    if (association.SourceAssociation != null)
                    {
                        ordering.Add(association.SourceAssociation.ID);
                    }
                    else if (association.AddedAssociationID != Guid.Empty)
                    {
                        ordering.Add(association.AddedAssociationID);
                    }
                }

                cmdReorderComponents <PSMAssociation> reorderCommand = new cmdReorderComponents <PSMAssociation>(controller)
                {
                    ComponentGuids = ordering, OwnerCollection = psmClass.ChildPSMAssociations
                };
                controller.CreatedMacro.Commands.Add(reorderCommand);
            }

            #endregion

            return(!error);
        }