/// <summary>
        /// If a user selects any of the outputs listed by the Add-in, this function will be invoked.
        /// The function receives the Schema Composer automation interface, which can be used to traverse the schema.
        /// </summary>
        /// <param name="Repository"></param>
        /// <param name="composer"></param>
        public override void EA_GenerateFromSchema(EA.Repository Repository, EA.SchemaComposer composer, string exports)
        {
            try
            {
                Schema schema = this.schemaFactory.createSchema(composer, this.settings);
                UML.Classes.Kernel.Package targetPackage = null;
                if (this.settings.generateToArtifactPackage)
                {
                    targetPackage = schema.containerElement?.owningPackage;
                }
                if (targetPackage == null)
                {
                    targetPackage = this.model.getUserSelectedPackage() as UML.Classes.Kernel.Package;
                }
                if (targetPackage != null)
                {
                    Cursor.Current = Cursors.WaitCursor;
                    bool writable = true;
                    //check if package is writable
                    if (this.settings.checkSecurity)
                    {
                        writable = targetPackage.isCompletelyWritable;
                        if (!writable)
                        {
                            DialogResult lockPackageResponse = MessageBox.Show("Package is read-only" + Environment.NewLine + "Would you like to lock the package?"
                                                                               , "Lock target Package?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                            //lock the elements immediately
                            if (lockPackageResponse == DialogResult.Yes)
                            {
                                writable = makeCompletelyWritable(targetPackage);
                                if (!writable)
                                {
                                    //if not writable then inform user and stop further processing;
                                    MessageBox.Show("Target package could not be locked", "Target Read-Only", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                }
                            }
                        }
                    }
                    //only proceed if target package is writable
                    if (writable)
                    {
                        //check if the already contains classes
                        DialogResult response = DialogResult.No;
                        response = MessageBox.Show($"Are you sure you want to generate the subset to package '{targetPackage.name}'?"
                                                   , "Generate Subset?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                        if (response == DialogResult.Yes)
                        {
                            this.updateMessageSubset(schema, targetPackage);
                        }
                    }
                    Cursor.Current = Cursors.Default;
                }
            }
            catch (Exception e)
            {
                processException(e);
            }
        }
        /// <summary>
        /// If a user selects any of the outputs listed by the Add-in, this function will be invoked.
        /// The function receives the Schema Composer automation interface, which can be used to traverse the schema.
        /// </summary>
        /// <param name="Repository"></param>
        /// <param name="composer"></param>
        public override void EA_GenerateFromSchema(EA.Repository Repository, EA.SchemaComposer composer, string exports)
        {
            Schema schema = this.schemaFactory.createSchema(composer, this.settings);

            UML.Classes.Kernel.Element selectedElement = this.model.getUserSelectedElement(new List <string> {
                "Package"
            });
            if (selectedElement != null)
            {
                var targetPackage = selectedElement as UML.Classes.Kernel.Package;
                if (targetPackage != null)
                {
                    Cursor.Current = Cursors.WaitCursor;
                    bool writable = true;
                    //check if package is writable
                    if (this.settings.checkSecurity)
                    {
                        writable = checkCompletelyWritable(targetPackage);
                        if (!writable)
                        {
                            DialogResult lockPackageResponse = MessageBox.Show("Package is read-only" + Environment.NewLine + "Would you like to lock the package?"
                                                                               , "Lock target Package?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                            //lock the elements immediately
                            if (lockPackageResponse == DialogResult.Yes)
                            {
                                writable = makeCompletelyWritable(targetPackage);
                                if (!writable)
                                {
                                    //if not writable then inform user and stop further processing;
                                    MessageBox.Show("Target package could not be locked", "Target Read-Only", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                }
                            }
                        }
                    }
                    //only proceed if target package is writable
                    if (writable)
                    {
                        //check if the already contains classes
                        DialogResult response = DialogResult.No;
                        if (!targetPackage.isEmpty)
                        {
                            response = MessageBox.Show("The target package is not empty." + Environment.NewLine + "Would you like to update an existing subset model?"
                                                       , "Update existing subset model?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                        }
                        if (response == DialogResult.No)
                        {
                            this.createNewMessageSubset(schema, targetPackage);
                        }
                        else if (response == DialogResult.Yes)
                        {
                            this.updateMessageSubset(schema, targetPackage);
                        }
                        //if the user chose cancel we don't do anything
                    }
                }
                Cursor.Current = Cursors.Default;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// If a user selects any of the outputs listed by the Add-in, this function will be invoked.
        /// The function receives the Schema Composer automation interface, which can be used to traverse the schema.
        /// </summary>
        /// <param name="Repository"></param>
        /// <param name="composer"></param>
        public override void EA_GenerateFromSchema(EA.Repository Repository, EA.SchemaComposer composer, string exports)
        {
            Schema schema = this.schemaFactory.createSchema(composer, this.settings);

            UML.Classes.Kernel.Element selectedElement = this.model.getUserSelectedElement(new List <string> {
                "Package"
            });
            if (selectedElement != null)
            {
                var targetPackage = selectedElement as UML.Classes.Kernel.Package;
                if (targetPackage != null)
                {
                    Cursor.Current = Cursors.WaitCursor;
                    //check if the already contains classes
                    var          classElement = targetPackage.ownedElements.FirstOrDefault(x => (x is UML.Classes.Kernel.Class || x is UML.Classes.Kernel.Enumeration)) as UML.Classes.Kernel.Classifier;
                    DialogResult response     = DialogResult.No;
                    if (classElement != null)
                    {
                        response = MessageBox.Show("Package already contains one or more classes" + Environment.NewLine + "Would you like to update an existing subset model?"
                                                   , "Update existing subset model?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
                    }
                    if (response == DialogResult.No)
                    {
                        this.createNewMessageSubset(schema, targetPackage);
                    }
                    else if (response == DialogResult.Yes)
                    {
                        this.updateMessageSubset(schema, classElement);
                    }
                    //if the user chose cancel we don't do anything
                }
                else
                {
                    this.updateMessageSubset(schema, selectedElement as UML.Classes.Kernel.Class);
                    //refresh all open diagram to show the changes
                    this.model.reloadDiagrams();
                }
                Cursor.Current = Cursors.Default;
            }
        }
 /// <summary>
 /// Constructor of the EASchema. Only to be used by the EASchemaBuilderFactory
 /// </summary>
 /// <param name="model">The model containing this Scheam</param>
 /// <param name="composer">The EA.SchemaComposer object to be wrapped</param>
 internal EASchema(UTF_EA.Model model, EA.SchemaComposer composer, SBF.SchemaSettings settings)
 {
     this.model           = model;
     this.wrappedComposer = composer;
     this.settings        = settings;
 }
		/// <summary>
		/// Constructor of the EASchema. Only to be used by the EASchemaBuilderFactory
		/// </summary>
		/// <param name="model">The model containing this Scheam</param>
		/// <param name="composer">The EA.SchemaComposer object to be wrapped</param>
		internal EASchema(UTF_EA.Model model, EA.SchemaComposer composer)
		{
			this.model = model;
			this.wrappedComposer = composer;
		}
        /// <summary>
        /// If a user selects any of the outputs listed by the Add-in, this function will be invoked.
        /// The function receives the Schema Composer automation interface, which can be used to traverse the schema.
        /// </summary>
        /// <param name="Repository"></param>
        /// <param name="composer"></param>
        public override void EA_GenerateFromSchema(EA.Repository Repository, EA.SchemaComposer composer, string exports)
        {
            try
            {
                Schema schema = this.schemaFactory.createSchema(composer, this.settings);
                UML.Classes.Kernel.Package targetPackage = null;
                if (this.settings.generateToArtifactPackage)
                {
                    targetPackage = schema.containerElement?.owningPackage;
                }
                else
                {
                    var targetPackageTag = schema.containerElement?.taggedValues.FirstOrDefault(x => x.name == targetPackageTagName);
                    if (targetPackageTag != null)
                    {
                        targetPackage = targetPackageTag?.tagValue as UML.Classes.Kernel.Package;
                    }
                }
                if (targetPackage == null)
                {
                    targetPackage = this.model.getUserSelectedPackage() as UML.Classes.Kernel.Package;
                }
                if (targetPackage != null)
                {
                    //save target package as tagged value on schema artifact
                    if (!this.settings.generateToArtifactPackage)
                    {
                        this.saveTargetPackageTag(schema, targetPackage);
                    }
                    Cursor.Current = Cursors.WaitCursor;
                    bool writable = true;
                    //check if package is writable
                    if (this.settings.checkSecurity)
                    {
                        writable = targetPackage.isCompletelyWritable;
                        if (!writable)
                        {
                            var lockPackageResponse = MessageBox.Show("Package is read-only" + Environment.NewLine + "Would you like to lock the package?"
                                                                      , "Lock target Package?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                            //lock the elements immediately
                            if (lockPackageResponse == DialogResult.Yes)
                            {
                                writable = this.makeCompletelyWritable(targetPackage);
                                if (!writable)
                                {
                                    //if not writable then inform user and stop further processing;
                                    MessageBox.Show("Target package could not be locked", "Target Read-Only", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                }
                            }
                        }
                    }
                    //only proceed if target package is writable
                    if (writable)
                    {
                        //check if the already contains classes
                        var response = DialogResult.No;
                        response = MessageBox.Show($"Are you sure you want to generate the subset to package '{targetPackage.name}'?"
                                                   , "Generate Subset?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                        if (response == DialogResult.Yes)
                        {
                            if (this.EAModel.EAVersion >= 1308)
                            {
                                //disable ui updates to speed up process. Only for v13 or higher
                                this.EAModel.wrappedModel.EnableUIUpdates = false;
                            }
                            //update the subset
                            this.updateMessageSubset(schema, targetPackage);
                            //refresh package to make changes visible Only for v13 or higher
                            if (this.EAModel.EAVersion >= 1308)
                            {
                                targetPackage.refresh();
                            }
                            //check for any errors or warnings
                            var errorCount   = EAOutputLogger.getErrors(this.EAModel, this.settings.outputName).Count();
                            var warningCount = EAOutputLogger.getWarnings(this.EAModel, this.settings.outputName).Count();
                            if (errorCount > 0 || warningCount > 0)
                            {
                                MessageBox.Show(this.EAModel.mainEAWindow, $"Generation resulted in {errorCount} errors and {warningCount} warnings.\nPlease check the output log"
                                                , "Errors or Warnings!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            }
                        }
                    }
                    Cursor.Current = Cursors.Default;
                }
            }
            catch (Exception e)
            {
                processException(e);
            }
            finally
            {
                if (this.EAModel.EAVersion >= 1308)
                {
                    //re-enable gui updates. Only for V13 or higher
                    this.EAModel.wrappedModel.EnableUIUpdates = true;
                }
            }
        }
 /// <summary>
 /// Constructor of the EASchema. Only to be used by the EASchemaBuilderFactory
 /// </summary>
 /// <param name="model">The model containing this Scheam</param>
 /// <param name="composer">The EA.SchemaComposer object to be wrapped</param>
 internal EASchema(UTF_EA.Model model, EA.SchemaComposer composer, SBF.SchemaSettings settings)
 {
     this.model = model;
     this.wrappedComposer = composer;
     this.settings = settings;
 }