Ejemplo n.º 1
0
 private StackedCommand GetNormalizationCommand(PSMSchema schema)
 {
     // (d) Content model association normalization
     if (!modelVerifier.TestSchemaClassChildrenAreClasses(schema))
     {
         PSMContentModel         cm      = (PSMContentModel)modelVerifier.LastViolatingComponent;
         cmdDeletePSMAssociation command = new cmdDeletePSMAssociation(Controller);
         command.Set(cm.ParentAssociation.ID);
         return(command);
     } // (c) Empty name association
     else if (!modelVerifier.TestSchemaClassChildrenNames(schema))
     {
         PSMAssociation          a       = (PSMAssociation)modelVerifier.LastViolatingComponent;
         cmdDeletePSMAssociation command = new cmdDeletePSMAssociation(Controller);
         command.Set(a.ID);
         return(command);
     } // (e) Root content model normalization
     else if (!modelVerifier.TestRootsAreNotContentModels(schema))
     {
         PSMContentModel cm = (PSMContentModel)modelVerifier.LastViolatingComponent;
         MacroCommand    m  = new MacroCommand(Controller);
         foreach (PSMAssociation childPsmAssociation in cm.ChildPSMAssociations)
         {
             cmdDeletePSMAssociation delA = new cmdDeletePSMAssociation(Controller);
             delA.Set(childPsmAssociation.ID);
             m.Commands.Add(delA);
         }
         cmdDeletePSMContentModel delCM = new cmdDeletePSMContentModel(Controller);
         delCM.Set(cm.ID);
         m.Commands.Add(delCM);
         return(m);
     } // (f) Root class normalization
     else if (!modelVerifier.TestRootsAreReferenced(schema))
     {
         PSMClass c = (PSMClass)modelVerifier.LastViolatingComponent;
         cmdDeleteRootPSMClass command = new cmdDeleteRootPSMClass(Controller);
         command.Set(c.ID);
         return(command);
     } // (a) Cardinality normalization
     else if (!modelVerifier.TestSchemaClassChildrenCardinality(schema))
     {
         PSMAssociation a = (PSMAssociation)modelVerifier.LastViolatingComponent;
         cmdUpdatePSMAssociationCardinality command = new cmdUpdatePSMAssociationCardinality(Controller);
         command.Set(a.ID, 1, 1);
         return(command);
     } // (b) Name normalization
     else if (!modelVerifier.TestContentModelsAssociationNames(schema))
     {
         PSMAssociation     a       = (PSMAssociation)modelVerifier.LastViolatingComponent;
         cmdRenameComponent command = new cmdRenameComponent(Controller)
         {
             ComponentGuid = a.ID, NewName = String.Empty
         };
         return(command);
     }
     else
     {
         throw new InvalidOperationException("Schema is already normalized. ");
     }
 }
Ejemplo n.º 2
0
 public override void Execute(object parameter = null)
 {
     if (Current.ActiveOCLScript != null)
     {
         string newName;
         if (ExolutioInputBox.Show("Enter new name of the script", Current.ActiveOCLScript.Name, out newName) == true)
         {
             cmdRenameComponent c = new cmdRenameComponent(Current.Controller);
             c.ComponentGuid = Current.ActiveOCLScript;
             c.NewName       = newName;
             c.Execute();
         }
     }
 }
Ejemplo n.º 3
0
        private void bApply_Click(object sender, RoutedEventArgs e)
        {
            bApply.Focus();
            applyButtonPressed = true;
            error = false;

            controller.BeginMacro();
            //controller.CreatedMacro.Description = string.Format("PIM Classs '{0}' was updated. ", PIMClass);
            if (tbName.ValueChanged)
            {
                cmdRenameComponent renameCommand = new cmdRenameComponent(controller)
                {
                    ComponentGuid = PIMClass, NewName = tbName.Text
                };
                controller.CreatedMacro.Commands.Add(renameCommand);
                tbName.ForgetOldValue();
            }

            //if (PIMClass.IsAbstract != cbAbstract.IsChecked)
            //{
            //    PIMClassController.ChangeAbstract(cbAbstract.IsChecked == true);
            //}

            //if (PIMClass.AllowAnyAttribute != cbAnyAttribute.IsChecked)
            //{
            //    PIMClassController.ChangeAllowAnyAttributeDefinition(cbAnyAttribute.IsChecked == true);
            //}

            #region check for deleted attributes

            List <PIMAttribute>     removedAttributes = new List <PIMAttribute>();
            List <FakePIMAttribute> addedAttributes   = new List <FakePIMAttribute>();
            foreach (PIMAttribute PIMAttribute in PIMClass.PIMAttributes)
            {
                bool found = false;
                foreach (FakePIMAttribute fakeAttribute in fakeAttributes)
                {
                    if (fakeAttribute.SourceAttribute == PIMAttribute && fakeAttribute.Checked)
                    {
                        found = true;
                        break;
                    }
                    else if (fakeAttribute.SourceAttribute == PIMAttribute && !fakeAttribute.Checked)
                    {
                        fakeAttribute.SourceAttribute = null;
                    }
                }
                if (!found)
                {
                    removedAttributes.Add(PIMAttribute);
                    cmdDeletePIMAttribute deleteCommand = new cmdDeletePIMAttribute(controller);
                    deleteCommand.Set(PIMAttribute);
                    controller.CreatedMacro.Commands.Add(deleteCommand);
                }
            }

            #endregion

            #region remove dummy entries in fake collection

            List <FakePIMAttribute> toRemove = new List <FakePIMAttribute>();
            foreach (FakePIMAttribute fakeAttribute in fakeAttributes)
            {
                if (String.IsNullOrEmpty(fakeAttribute.Name))
                {
                    if (fakeAttribute.SourceAttribute != null)
                    {
                        removedAttributes.Add(fakeAttribute.SourceAttribute);
                        cmdDeletePIMAttribute deleteCommand = new cmdDeletePIMAttribute(controller);
                        deleteCommand.Set(fakeAttribute.SourceAttribute);
                        controller.CreatedMacro.Commands.Add(deleteCommand);
                    }
                    toRemove.Add(fakeAttribute);
                }
            }

            foreach (FakePIMAttribute attribute in toRemove)
            {
                fakeAttributes.Remove(attribute);
            }

            #endregion

            Dictionary <PIMAttribute, string> namesDict = new Dictionary <PIMAttribute, string>();
            foreach (PIMAttribute a in PIMClass.PIMAttributes)
            {
                if (!removedAttributes.Contains(a))
                {
                    namesDict.Add(a, a.Name);
                }
            }

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

            // editing exisiting attribute
            foreach (FakePIMAttribute modifiedAttribute in modified)
            {
                PIMAttribute sourceAttribute = modifiedAttribute.SourceAttribute;
                uint         lower;
                UnlimitedInt upper;
                if (
                    !IHasCardinalityExt.ParseMultiplicityString(modifiedAttribute.Multiplicity, out lower,
                                                                out upper))
                {
                    error = true;
                }
                cmdUpdatePIMAttribute updateCommand = new cmdUpdatePIMAttribute(controller);
                updateCommand.Set(sourceAttribute, modifiedAttribute.Type, modifiedAttribute.Name, lower, upper, modifiedAttribute.DefaultValue);
                controller.CreatedMacro.Commands.Add(updateCommand);
                namesDict[sourceAttribute] = modifiedAttribute.Name;
            }

            List <string> names = namesDict.Values.ToList();
            // new attribute
            foreach (FakePIMAttribute 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;
                        }
                    }
                    cmdCreateNewPIMAttribute createNewPIMAttribute = new cmdCreateNewPIMAttribute(controller);
                    createNewPIMAttribute.Set(PIMClass, addedAttribute.Type, addedAttribute.Name, lower, upper, addedAttribute.DefaultValue);
                    controller.CreatedMacro.Commands.Add(createNewPIMAttribute);
                    addedAttributes.Add(addedAttribute);
                    names.Add(addedAttribute.Name);
                }
            }

            if (error)
            {
                controller.CancelMacro();
            }
            else
            {
                CommandBase tmp = (CommandBase)controller.CreatedMacro;
                controller.CommitMacro();
                if (string.IsNullOrEmpty(tmp.ErrorDescription))
                {
                    foreach (FakePIMAttribute attribute in addedAttributes)
                    {
                        attribute.SourceAttribute = PIMClass.PIMAttributes.Where
                                                        (property => property.Name == attribute.Name).SingleOrDefault();
                    }
                    addedAttributes.RemoveAll(attribute => attribute.SourceAttribute == null);
                    bApply.IsEnabled = false;
                    dialogReady      = true;
                    error            = false;
                }
                else
                {
                    error = true;
                }
            }
            Initialize(controller, PIMClass);
            applyButtonPressed = false;
        }