Esempio n. 1
0
 /// <summary>
 /// Output to EA System Output, Tab 'Script'
 /// </summary>
 /// <param name="msg">The message to output in EA</param>
 public void Print(string msg)
 {
     // Displays the message in the 'Script' tab of Enterprise Architect System Output Window
     _repository.CreateOutputTab(EaOutputTabName);
     _repository.EnsureOutputVisible(EaOutputTabName);
     _repository.WriteOutput(EaOutputTabName, msg, 0);
 }
Esempio n. 2
0
        private void batch(EA.Repository Repository)
        {
            Dictionary <string, EA.Package> content = new Dictionary <string, EA.Package>();
            string   xml                 = Repository.SQLQuery("SELECT Name, ea_guid FROM t_object WHERE Object_Type = 'Package'"); // order by package_id
            XElement xEADATA             = XElement.Parse(xml, LoadOptions.None);
            IEnumerable <XElement> xRows = xEADATA.XPathSelectElements("//Data/Row");

            foreach (XElement xRow in xRows)
            {
                string ea_guid = xRow.Element("ea_guid").Value;
                string name    = xRow.Element("Name").Value;
                content[name] = Repository.GetPackageByGuid(ea_guid);
            }
            BatchForm form = new BatchForm();

            form.setContent(content);
            form.ShowDialog();

            if (form.isExportButtonPressed())
            {
                Repository.CreateOutputTab(MAX_TABNAME);
                Repository.ClearOutput(MAX_TABNAME);
                bool issues = false;
                foreach (string name in form.getSelectedItems())
                {
                    EA.Package package = content[name];
                    issues |= new Filters().exportPackage(Repository, package);
                }
                if (issues)
                {
                    // only popup when there were any issues
                    Repository.EnsureOutputVisible(MAX_TABNAME);
                }
            }
        }
Esempio n. 3
0
 public void enable(EA.Repository r)
 {
     this.toggle     = true;
     this.repository = r;
     if (this.toggle)
     {
         repository.CreateOutputTab("IAG");
         repository.EnsureOutputVisible("IAG");
         repository.ClearOutput("IAG");
         log("Logger is enabled");
         string version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
         log("APIAddIn version " + version);
     }
 }
        public static void SynchronizePackageWithJIRA(EA.Repository Repository, EA.Package Package, PackageConnectionSettingsViewModel PackageConnectionSettings, JiraConnection JiraConnection)
        {
            //Steps:
            //      1. User must be able to login to JIRA -- must ensure caller
            //      2. Creating Repository.Output -- well... am thinking about event, JTS so far
            //      3. Get the proper JQL -- i will get from parameter
            //      4. Do to job

            Repository.CreateOutputTab(EAGoatJira.JiraOutputWindowName);
            Repository.EnsureOutputVisible(EAGoatJira.JiraOutputWindowName);
            Repository.ClearOutput(EAGoatJira.JiraOutputWindowName);
            Repository.WriteOutput(EAGoatJira.JiraOutputWindowName, "Reading data...", 0);

            PackageConnectionSettings.Refresh();

            Dictionary <string, EA.Element> IssuesInEA = ReadIssuesFromEA(Repository, Package.Elements);

            var issues = JiraConnection.GetJiraIssues(PackageConnectionSettings.Jql);

            foreach (var issue in issues)
            {
                EA.Element EAElementForIssue = SynchronizeItem(issue, Repository, Package, null, IssuesInEA);

                if (PackageConnectionSettings.PackageConnectionSettings.Type == PackageConnectionSettingsType.EpicsAndStories)
                {
                    var epicissues = JiraConnection.GetJiraIssues($"\"Epic Link\" = {issue.Key}");
                    foreach (var epicissue in epicissues)
                    {
                        SynchronizeItem(epicissue, Repository, Package, EAElementForIssue, IssuesInEA);
                    }
                }
                EAElementForIssue.Update();
            }

            if (IssuesInEA.Count > 0)
            { //some issues that are in the Package are not in the issues (they were deleted or moved or the Jql has chaned)
                EA.Package PackageForRemovedIssues = EAUtils.CreatePackage(Package, "Removed Issues", ForceCreation: false);
                foreach (var removedItem in IssuesInEA)
                {
                    Repository.WriteOutput(EAGoatJira.JiraOutputWindowName, $"Removing issue {removedItem.Key}", removedItem.Value.ElementID);
                    removedItem.Value.PackageID = PackageForRemovedIssues.PackageID;
                    removedItem.Value.Update();
                    EAUtils.WriteTaggedValue(removedItem.Value, EAGoatJira.TagValueNameOperation, "Issue was " + IssueOperation.Removed.ToString() + ".", WriteValueToNotes: false);
                }
                PackageForRemovedIssues.Update();
            }

            Package.Update();
            Repository.WriteOutput(EAGoatJira.JiraOutputWindowName, $"Done.", 0);
        }
        public bool GetNewest()
        {
            // check nested packages
            foreach (EA.Package nestedPkg in _pkg.Packages)
            {
                var mks = new Mks(_rep, nestedPkg);
                mks.GetNewest();
            }
            if (_pkg.IsControlled)
            {
                //
                _rep.ShowInProjectView(_pkg);
                try
                {
                    // preference head revision
                    var mks = new Mks(_rep, _pkg);
                    mks.Checkout();

                    // load package
                    _rep.CreateOutputTab("Debug");
                    _rep.EnsureOutputVisible("Debug");
                    _rep.WriteOutput("Debug", _pkg.Name + " " + _pkg.Notes, 0);

                    //MessageBox.Show(_pkg.Name + " " + _pkg.Packages.Count.ToString() + " " + _pkg.PackageGUID, "CountBefore");
                    EA.Project prj = _rep.GetProjectInterface();
                    prj.LoadControlledPackage(_pkg.PackageGUID);


                    _rep.WriteOutput("Debug", _pkg.Name + " " + _pkg.Notes, 0);
                    //MessageBox.Show(_pkg.Name + " " + _pkg.Packages.Count.ToString() + " " + _pkg.PackageGUID, "CountAfter");
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.ToString(), @"Error");
                }
            }



            return(true);
        }
Esempio n. 6
0
        /**
         * Compile Profile will take a profile definition and create a profile based on that.
         * 1. Export profile definitions to MAX file (filename is in MAX::ExportFile) of ProfileDefinition Package
         * 2. Find Base Model MAX File (filename is in MAX::ImportFile) of <use> Dependency target from ProfileDefinition Package
         * 3. Compile profile to MAX File (filename is in MAX::ExportFile) of <create> Dependency target from ProfileDefinition Package
         * 4. (optionally) import the compiled profile
         */
        private void CompileProfile(EA.Repository repository, EA.Package package)
        {
            // Only on a "HL7-Profile-Definition" stereotypes package
            if (R2Const.ST_FM_PROFILEDEFINITION.Equals(package.StereotypeEx))
            {
                repository.CreateOutputTab(Properties.Resources.OUTPUT_TAB_HL7_FM);
                repository.ClearOutput(Properties.Resources.OUTPUT_TAB_HL7_FM);
                repository.EnsureOutputVisible(Properties.Resources.OUTPUT_TAB_HL7_FM);

                // !! Use tagged value "MAX:ExportFile" as fileNames!
                // Export it to MAX.
                EA.TaggedValue tvExportFile = (EA.TaggedValue)package.Element.TaggedValues.GetByName("MAX::ExportFile");
                if (tvExportFile == null)
                {
                    EAHelper.LogMessage(string.Format("[ERROR] MAX::ExportFile tag missing in Package \"{0}\"", package.Name), package.Element.ElementID);
                    MessageBox.Show(MESSAGE_PROFILE_DEFINITION, "Complete setup", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
                string profileDefinitionFileName = tvExportFile.Value;
                EAHelper.LogMessage(string.Format("[INFO] Profile Definition MAX file: {0}", profileDefinitionFileName));
                EAHelper.LogMessage("[BEGIN] Export Profile Definition to MAX file");
                new MAX_EA.MAXExporter3().exportPackage(repository, package, profileDefinitionFileName);
                EAHelper.LogMessage("[END] Export Profile Definition to MAX file");

                // Find associated Base
                EA.Package baseModelPackage = EAHelper.getAssociatedBaseModel(repository, package);
                if (baseModelPackage == null)
                {
                    MessageBox.Show(MESSAGE_PROFILE_DEFINITION, "Complete setup", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
                EAHelper.LogMessage(string.Format("[INFO] Base Model Package name: {0}", baseModelPackage.Name));
                EA.TaggedValue tvImportFile = (EA.TaggedValue)baseModelPackage.Element.TaggedValues.GetByName("MAX::ImportFile");
                if (tvImportFile == null)
                {
                    EAHelper.LogMessage(string.Format("[ERROR] MAX::ImportFile tag missing in Package \"{0}\"", baseModelPackage.Name));
                    MessageBox.Show(MESSAGE_PROFILE_DEFINITION, "Complete setup", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
                string baseModelFileName = tvImportFile.Value;
                EAHelper.LogMessage(string.Format("[INFO] Base Model MAX file: {0}", baseModelFileName));

                // Find associated Target Profile Package
                EA.Package compiledProfilePackage = EAHelper.getAssociatedOutputProfile(repository, package);
                if (compiledProfilePackage == null)
                {
                    MessageBox.Show(MESSAGE_PROFILE_DEFINITION, "Complete setup", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
                EAHelper.LogMessage(string.Format("[INFO] Compiled Profile Package name: {0}", compiledProfilePackage.Name));
                EA.TaggedValue tvExportFile2 = (EA.TaggedValue)compiledProfilePackage.Element.TaggedValues.GetByName("MAX::ExportFile");
                if (tvExportFile2 == null)
                {
                    EAHelper.LogMessage(string.Format("MAX::ExportFile tag missing in Package \"{0}\"", compiledProfilePackage.Name));
                    MessageBox.Show(MESSAGE_PROFILE_DEFINITION, "Complete setup", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
                string profileFileName = tvExportFile2.Value;

                // Call R2ProfileCompiler
                EAHelper.LogMessage(string.Format("[INFO] Compiled Profile MAX file: {0}", profileFileName));
                EAHelper.LogMessage("[BEGIN] Compile Profile");
                R2ProfileCompiler compiler = new R2ProfileCompiler();
                compiler._OutputListener = new EAOutputListener();
                compiler.Compile(baseModelFileName, profileDefinitionFileName, profileFileName);
                EAHelper.LogMessage("[END] Compile Profile");

                // Import compiled profile from MAX file
                //new MAX_EA.MAXImporter3().import(repository, profilePackage, profileFileName);
                MessageBox.Show("Manually import compiled profile now...", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("Select a Profile Definition Package to Compile.");
            }
        }
Esempio n. 7
0
        public void validate(EA.Repository repository, EA.Package rootPackage)
        {
            string sch_filepath = null;

            switch (rootPackage.StereotypeEx)
            {
            case R2Const.ST_FM:
                sch_filepath = Main.getAppDataFullPath(@"Schematron\EHRS_FM_R2-validation.sch");
                break;

            case R2Const.ST_FM_PROFILEDEFINITION:
                sch_filepath = Main.getAppDataFullPath(@"Schematron\EHRS_FM_R2_FPDEF-validation.sch");
                break;

            case R2Const.ST_FM_PROFILE:
                sch_filepath = Main.getAppDataFullPath(@"Schematron\EHRS_FM_R2_FP-validation.sch");
                break;

            default:
                MessageBox.Show(string.Format("Validation not available for {0}.\nChoose ", rootPackage.Name), "Choose other package", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            repository.CreateOutputTab(Properties.Resources.OUTPUT_TAB_HL7_FM);
            repository.ClearOutput(Properties.Resources.OUTPUT_TAB_HL7_FM);
            repository.EnsureOutputVisible(Properties.Resources.OUTPUT_TAB_HL7_FM);

            // TODO: Change to memorybased!!
            // TODO: Transform once to XSL, only if the xsl is older or not existing

            // Create and load the transform with script execution enabled.
            XslCompiledTransform transform = new XslCompiledTransform();
            XsltSettings         settings  = new XsltSettings {
                EnableScript = true
            };
            XmlUrlResolver resolver = new XmlUrlResolver();

            // transform the Schematron to a XSL
            string iso_sch_xsl_filepath = Main.getAppDataFullPath(@"Schematron\iso-schematron-xslt1\iso_svrl_for_xslt1.xsl");

            transform.Load(iso_sch_xsl_filepath, settings, resolver);
            string sch_xsl_filepath = Main.getAppDataFullPath(@"Schematron\EHRS_FM_R2-validation.sch.xsl");

            transform.Transform(sch_filepath, sch_xsl_filepath);

            // export to temp MAX file
            string temp_max_file = Main.getAppDataFullPath(@"Schematron\__temp__.max");

            new MAX_EA.MAXExporter3().exportPackage(repository, rootPackage, temp_max_file);

            // now execute the Schematron XSL
            transform.Load(sch_xsl_filepath, settings, resolver);
            string svrl_filepath = Main.getAppDataFullPath(@"Schematron\svrl_output.xml");

            transform.Transform(temp_max_file, svrl_filepath);

            // build element dictionary
            Dictionary <string, EA.Element> eaElementDict = new Dictionary <string, EA.Element>();

            recurseEaPackage(rootPackage, eaElementDict);

            XmlReader xReader = XmlReader.Create(svrl_filepath);

            // make sure file gets closed
            using (xReader)
            {
                XElement            svrl  = XElement.Load(xReader);
                XmlNamespaceManager nsmgr = new XmlNamespaceManager(xReader.NameTable);
                nsmgr.AddNamespace("svrl", "http://purl.oclc.org/dsdl/svrl");

                appendSvrlMessagesToOutputTab(repository, svrl.XPathSelectElements("//svrl:successful-report", nsmgr), eaElementDict, nsmgr);
                appendSvrlMessagesToOutputTab(repository, svrl.XPathSelectElements("//svrl:failed-assert", nsmgr), eaElementDict, nsmgr);
            }
            MessageBox.Show("Validation done.\nCheck output tab for message and issues.", "Done", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

            repository.EnsureOutputVisible(Properties.Resources.OUTPUT_TAB_HL7_FM);
        }
        /// <summary>
        /// Called when user makes a selection in the menu.
        /// This is your main exit point to the rest of your Add-in
        /// </summary>
        /// <param name="repository">the repository</param>
        /// <param name="location">the location of the menu</param>
        /// <param name="MenuName">the name of the menu</param>
        /// <param name="itemName">the name of the selected menu item</param>
        public override void EA_MenuClick(EA.Repository repository, string location, string MenuName, string itemName)
        {
            EA.Package    pkg        = null;
            EA.ObjectType oType      = repository.GetContextItemType();
            EA.Diagram    diaCurrent = repository.GetCurrentDiagram();
            EA.Connector  conCurrent = null;
            EA.Element    el         = null;


            if (diaCurrent != null)
            {
                conCurrent = diaCurrent.SelectedConnector;
            }
            switch (itemName)
            {
            case MenuAbout:
                About fAbout = new About();
                fAbout.setVersion(Release);     // set release / version
                fAbout.ShowDialog();

                break;


            case MenuMksGetNewest:
                if (oType.Equals(EA.ObjectType.otPackage))
                {
                    pkg = (EA.Package)repository.GetContextObject();
                    Mks mks = new Mks(repository, pkg);
                    mks.GetNewest();
                }

                break;

            case MenuMksGetHistory:
                // if controlled package
                if (oType.Equals(EA.ObjectType.otPackage))
                {
                    pkg = (EA.Package)repository.GetContextObject();
                    Mks mks = new Mks(repository, pkg);
                    MessageBox.Show(mks.ViewHistory(), "mks");
                }
                break;


            case MenuMksUndoCheckOut:
                // if controlled package
                if (oType.Equals(EA.ObjectType.otPackage))
                {
                    pkg = (EA.Package)repository.GetContextObject();
                    Mks    mks = new Mks(repository, pkg);
                    string msg = mks.UndoCheckout();
                    if (msg != "")
                    {
                        MessageBox.Show(mks.UndoCheckout(), "mks");
                    }
                }
                break;

            // Change name to synomym
            // - Package, recursive
            // - Class
            case MenuChangeClassNameToSynonym:
                // Class recursive
                if (oType.Equals(EA.ObjectType.otElement))
                {
                    el = (EA.Element)repository.GetContextObject();
                    Util.ChangeClassNameToSynonyms(repository, el);
                }
                // Package recursiv
                if (oType.Equals(EA.ObjectType.otPackage))
                {
                    pkg = (EA.Package)repository.GetContextObject();
                    Util.ChangePackageClassNameToSynonyms(repository, pkg);
                }

                break;



            //

            //   If package is controlled:
            //   - reset packageflags to "Recurse=0;VCCFG=unchanged";
            case MenuResetVcMode:
                if (oType.Equals(EA.ObjectType.otPackage))
                {
                    pkg = (EA.Package)repository.GetContextObject();
                    Util.ResetVc(repository, pkg);
                }
                break;

            //   For all nested packages:
            //   If package is controlled:
            //   - reset packageflags to "Recurse=0;VCCFG=unchanged";
            case MenuResetVcModeRecursive:
                if (oType.Equals(EA.ObjectType.otPackage))
                {
                    pkg = (EA.Package)repository.GetContextObject();
                    Util.ResetVcRecursive(repository, pkg);
                }
                break;



            case MenuGetVcLatest:
                if (oType.Equals(EA.ObjectType.otPackage))
                {
                    // start preparation
                    int      count      = 0;
                    int      errorCount = 0;
                    DateTime startTime  = DateTime.Now;

                    repository.CreateOutputTab("Debug");
                    repository.EnsureOutputVisible("Debug");
                    repository.WriteOutput("Debug", "Start GetLatest", 0);
                    pkg = (EA.Package)repository.GetContextObject();
                    Util.GetLatest(repository, pkg, false, ref count, 0, ref errorCount);
                    string s = "";
                    if (errorCount > 0)
                    {
                        s = " with " + errorCount.ToString() + " errors";
                    }

                    // finished
                    TimeSpan span = DateTime.Now - startTime;
                    repository.WriteOutput("Debug", "End GetLatest " + span.Minutes + " minutes. " + s, 0);
                }

                break;

            case MenuGetVcLatestRecursive:
                if (oType.Equals(EA.ObjectType.otPackage) || oType.Equals(EA.ObjectType.otNone))
                {
                    // start preparation
                    int      count      = 0;
                    int      errorCount = 0;
                    DateTime startTime  = DateTime.Now;

                    repository.CreateOutputTab("Debug");
                    repository.EnsureOutputVisible("Debug");
                    repository.WriteOutput("Debug", "Start GetLatestRecursive", 0);
                    pkg = (EA.Package)repository.GetContextObject();
                    Util.GetLatest(repository, pkg, true, ref count, 0, ref errorCount);
                    string s = "";
                    if (errorCount > 0)
                    {
                        s = " with " + errorCount.ToString() + " errors";
                    }

                    // finished
                    TimeSpan span = DateTime.Now - startTime;

                    repository.WriteOutput("Debug", "End GetLatestRecursive in " + span.Hours + ":" + span.Minutes + " hh:mm. " + s, 0);
                }

                break;

            case MenuGetVcModeAll:
                //Repository.VersionControlResynchPkgStatuses(false);
                // over all packages
                foreach (EA.Package pkg1 in repository.Models)
                {
                    Util.UpdateVc(repository, pkg1);
                }

                break;

            case MenuGetVcMode:
                if (oType.Equals(EA.ObjectType.otPackage))
                {
                    pkg = (EA.Package)repository.GetContextObject();
                    // Get the revision
                    Regex  pattern  = new Regex(@"Revision:[^\$]+");
                    Match  regMatch = pattern.Match(pkg.Notes);
                    string revision = "";
                    if (regMatch.Success)
                    {
                        // get Revision
                        revision = regMatch.Value;
                        // add new string
                    }
                    // Get date
                    pattern  = new Regex(@"Date:[^\$]+");
                    regMatch = pattern.Match(pkg.Notes);
                    string date = "";
                    if (regMatch.Success)
                    {
                        // get Revision
                        date = regMatch.Value;
                        // add new string
                    }
                    string msg = revision + "  " +
                                 date + "\r\n" +
                                 "Path: " + Util.GetFilePath(repository, pkg) +
                                 "\r\n\r\n" + pkg.Flags + "\r\n" +
                                 Util.GetVCstate(pkg, true);

                    MessageBox.Show(msg, "State");
                }
                break;



            case MenuCopyGuidToClipboard:
                string str  = "";
                string str1 = "";
                string str2 = "";

                if (conCurrent != null)
                {    // Connector
                    EA.Connector con = conCurrent;
                    str = con.ConnectorGUID + " " + con.Name + ' ' + con.Type + "\r\n" +

                          "\r\n Connector: Select ea_guid As CLASSGUID, connector_type As CLASSTYPE,* from t_connector con where ea_guid = '" + con.ConnectorGUID + "'" +

                          "\r\n\r\nSelect o.ea_guid As CLASSGUID, o.object_type As CLASSTYPE,o.name As Name, o.object_type AS ObjectType, o.PDATA1, o.Stereotype, " +
                          "\r\n                       con.Name, con.connector_type, con.Stereotype, con.ea_guid As ConnectorGUID, dia.Name As DiagrammName, dia.ea_GUID As DiagramGUID," +
                          "\r\n                       o.ea_guid, o.Classifier_GUID,o.Classifier " +
                          "\r\nfrom (((t_connector con INNER JOIN t_object o              on con.start_object_id   = o.object_id) " +
                          "\r\nINNER JOIN t_diagramlinks diaLink  on con.connector_id      = diaLink.connectorid ) " +
                          "\r\nINNER JOIN t_diagram dia           on diaLink.DiagramId     = dia.Diagram_ID) " +
                          "\r\nINNER JOIN t_diagramobjects diaObj on diaObj.diagram_ID     = dia.Diagram_ID and o.object_id = diaObj.object_id " +
                          "\r\nwhere         con.ea_guid = '" + con.ConnectorGUID + "' " +
                          "\r\nAND dialink.Hidden  = 0 ";
                    Clipboard.SetText(str);
                    break;
                }
                if (oType.Equals(EA.ObjectType.otElement))
                {    // Element
                    el = (EA.Element)repository.GetContextObject();
                    string pdata1       = el.get_MiscData(0);
                    string pdata1String = "";
                    if (pdata1.EndsWith("}"))
                    {
                        pdata1String = "/" + pdata1;
                    }
                    else
                    {
                        pdata1       = "";
                        pdata1String = "";
                    }
                    string classifier = Util.GetClassifierGuid(repository, el.ElementGUID);
                    str = el.ElementGUID + ":" + classifier + pdata1String + " " + el.Name + ' ' + el.Type + "\r\n" +
                          "\r\nSelect ea_guid As CLASSGUID, object_type As CLASSTYPE,* from t_object o where ea_guid = '" + el.ElementGUID + "'";
                    if (classifier != "")
                    {
                        if (el.Type.Equals("ActionPin"))
                        {
                            str = str + "\r\n Typ:\r\nSelect ea_guid As CLASSGUID, 'Parameter' As CLASSTYPE,* from t_operationparams op where ea_guid = '" + classifier + "'";
                        }
                        else
                        {
                            str = str + "\r\n Typ:\r\nSelect ea_guid As CLASSGUID, object_type As CLASSTYPE,* from t_object o where ea_guid = '" + classifier + "'";
                        }
                    }
                    if (pdata1 != "")
                    {
                        str = str + "\r\n PDATA1:  Select ea_guid As CLASSGUID, object_type As CLASSTYPE,* from t_object o where ea_guid = '" + pdata1 + "'";
                    }

                    // Look for diagram object
                    EA.Diagram curDia = repository.GetCurrentDiagram();
                    if (curDia != null)
                    {
                        foreach (EA.DiagramObject diaObj in curDia.DiagramObjects)
                        {
                            if (diaObj.ElementID == el.ElementID)
                            {
                                str = str + "\r\n\r\n" +
                                      "select * from t_diagramobjects where object_id = " + diaObj.ElementID.ToString();
                                break;
                            }
                        }
                    }
                }

                if (oType.Equals(EA.ObjectType.otDiagram))
                {    // Element
                    EA.Diagram dia = (EA.Diagram)repository.GetContextObject();
                    str = dia.DiagramGUID + " " + dia.Name + ' ' + dia.Type + "\r\n" +
                          "\r\nSelect ea_guid As CLASSGUID, diagram_type As CLASSTYPE,* from t_diagram dia where ea_guid = '" + dia.DiagramGUID + "'";
                }
                if (oType.Equals(EA.ObjectType.otPackage))
                {    // Element
                    pkg = (EA.Package)repository.GetContextObject();
                    str = pkg.PackageGUID + " " + pkg.Name + ' ' + " Package " + "\r\n" +
                          "\r\nSelect ea_guid As CLASSGUID, 'Package' As CLASSTYPE,* from t_package pkg where ea_guid = '" + pkg.PackageGUID + "'";
                }
                if (oType.Equals(EA.ObjectType.otAttribute))
                {    // Element
                    str1 = "LEFT JOIN  t_object typAttr on (attr.Classifier = typAttr.object_id)";
                    if (repository.ConnectionString.Contains(".eap"))
                    {
                        str1 = "LEFT JOIN  t_object typAttr on (attr.Classifier = Format(typAttr.object_id))";
                    }
                    EA.Attribute attr = (EA.Attribute)repository.GetContextObject();
                    str = attr.AttributeID + " " + attr.Name + ' ' + " Attribute " + "\r\n" +
                          "\r\n " +
                          "\r\nSelect ea_guid As CLASSGUID, 'Attribute' As CLASSTYPE,* from t_attribute attr where ea_guid = '" + attr.AttributeGUID + "'" +
                          "\r\n Class has Attributes:" +
                          "\r\nSelect attr.ea_guid As CLASSGUID, 'Attribute' As CLASSTYPE, " +
                          "\r\n       o.Name As Class, o.object_type, " +
                          "\r\n       attr.Name As AttrName, attr.Type As Type, " +
                          "\r\n       typAttr.Name " +
                          "\r\n   from (t_object o INNER JOIN t_attribute attr on (o.object_id = attr.object_id)) " +
                          "\r\n                   " + str1 +
                          "\r\n   where attr.ea_guid = '" + attr.AttributeGUID + "'";
                }
                if (oType.Equals(EA.ObjectType.otMethod))
                {    // Element
                    str1 = "LEFT JOIN t_object parTyp on (par.classifier = parTyp.object_id))";
                    str2 = "LEFT JOIN t_object opTyp on (op.classifier = opTyp.object_id)";
                    if (repository.ConnectionString.Contains(".eap"))
                    {
                        str1 = " LEFT JOIN t_object parTyp on (par.classifier = Format(parTyp.object_id))) ";
                        str2 = " LEFT JOIN t_object opTyp  on (op.classifier  = Format(opTyp.object_id))";
                    }

                    EA.Method op = (EA.Method)repository.GetContextObject();
                    str = op.MethodGUID + " " + op.Name + ' ' + " Operation " +
                          "\r\nOperation may have type " +
                          "\r\nSelect op.ea_guid As CLASSGUID, 'Operation' As CLASSTYPE,opTyp As OperationType, op.Name As OperationName, typ.Name As TypName,*" +
                          "\r\n   from t_operation op LEFT JOIN t_object typ on (op.classifier = typ.object_id)" +
                          "\r\n   where op.ea_guid = '" + op.MethodGUID + "';" +
                          "\r\n\r\nClass has Operation " +
                          "\r\nSelect op.ea_guid As CLASSGUID, 'Operation' As CLASSTYPE,* " +
                          "\r\n    from t_operation op INNER JOIN t_object o on (o.object_id = op.object_id)" +
                          "\r\n    where op.ea_guid = '" + op.MethodGUID + "';" +
                          "\r\n\r\nClass has Operation has Parameters/Typ and may have operationtype" +
                          "\r\nSelect op.ea_guid As CLASSGUID, 'Operation' As CLASSTYPE,op.Name As ClassName, op.Name As OperationName, opTyp.Name As OperationTyp, par.Name As ParName,parTyp.name As ParTypeName " +
                          "\r\n   from ((t_operation op INNER JOIN t_operationparams par on (op.OperationID = par.OperationID) )" +
                          "\r\n                        " + str1 +
                          "\r\n                        " + str2 +
                          "\r\n   where op.ea_guid = '" + op.MethodGUID + "' " +
                          "\r\n  Order by par.Pos ";
                }
                Clipboard.SetText(str);
                break;

            // delete undefined referencee
            case MenuDeleteExternalReference:
                if (diaCurrent != null)
                {
                    foreach (EA.DiagramObject diaObj in diaCurrent.SelectedObjects)
                    {
                        EA.Element el1 = repository.GetElementByID(diaObj.ElementID);
                        string     s   = String.Format("External Reference of diagram '{0}', name:'{1}' ID={2} GUID='{3}' deleted", diaCurrent.Name, el1.Name, el1.ElementID, el1.ElementGUID);
                        repository.WriteOutput("System", s, 0);
                        DeleteUndefinedReference(repository, el1);
                    }
                }
                else
                {
                    foreach (EA.Element el1 in repository.GetTreeSelectedElements())
                    {
                        string s = String.Format("External Reference of tree, name:'{0}' ID={1} GUID='{2}' deleted", el1.Name, el1.ElementID, el1.ElementGUID);
                        repository.WriteOutput("System", s, 0);
                        DeleteUndefinedReference(repository, el1);
                    }
                }
                break;

            // Recursive delete undefined referencee
            case MenuDeleteExternalReferenceRecursive:
                pkg = null;
                if (oType.Equals(EA.ObjectType.otNone))
                {
                    oType = repository.GetTreeSelectedItemType();
                    if (oType.Equals(EA.ObjectType.otPackage))
                    {
                        pkg = (EA.Package)repository.GetTreeSelectedObject();
                    }
                    if (oType.Equals(EA.ObjectType.otElement))
                    {
                        el = (EA.Element)repository.GetTreeSelectedObject();
                    }
                }
                else
                {
                    if (oType.Equals(EA.ObjectType.otPackage))
                    {
                        pkg = (EA.Package)repository.GetContextObject();
                    }
                    if (oType.Equals(EA.ObjectType.otElement))
                    {
                        el = (EA.Element)repository.GetContextObject();
                    }
                }
                if (pkg != null)
                {
                    RecursivePackages.doRecursivePkg(repository,
                                                     pkg,
                                                     null,                        // Packages
                                                     SetDeleteUndefinedReference, // Elements
                                                     null,                        // Diagrams
                                                     null);
                }
                if (el != null)
                {
                    RecursivePackages.doRecursiveEl(repository,
                                                    el,
                                                    SetDeleteUndefinedReference, // Elements
                                                    null,                        // Diagrams
                                                    null);
                }

                break;
            }
        }
Esempio n. 9
0
        public void import(EA.Repository Repository, EA.Package rootPackage)
        {
            Repository.EnableUIUpdates = false;
            Repository.BatchAppend     = true;

            Repository.CreateOutputTab(Properties.Resources.OUTPUT_TAB_HL7_FM);
            Repository.ClearOutput(Properties.Resources.OUTPUT_TAB_HL7_FM);
            Repository.EnsureOutputVisible(Properties.Resources.OUTPUT_TAB_HL7_FM);

            chapterColors["DC"] = 0x00ffff;
            chapterColors["S"]  = 0x00d7ff;
            chapterColors["IN"] = 0xffcc00;

            functions.Clear();
            functionCompSource.Clear();
            functionCompTarget.Clear();
            functionLinkSource.Clear();
            functionLinkTarget.Clear();
            functionSeeAlsoSource.Clear();
            functionSeeAlsoTarget.Clear();

            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(@"D:\VisualStudio Projects\HL7\EHRSFM_EA_AddIn\EHRSFM\EHRS_FunctionalModel_Rel1.1.xml");

            EA.Package fmPackage = (EA.Package)rootPackage.Packages.AddNew("EHR-S FM R1.1", "Package");
            fmPackage.Alias       = xmlDoc.SelectSingleNode("/FunctionalModel/Name").InnerText;
            fmPackage.Version     = xmlDoc.SelectSingleNode("/FunctionalModel/Version").InnerText + " " + xmlDoc.SelectSingleNode("/FunctionalModel/Date").InnerText;
            fmPackage.IsNamespace = true;
            fmPackage.Update();
            fmPackage.Element.Locked = LOCK_ELEMENTS;

            XmlNodeList chapterList = xmlDoc.SelectNodes("/FunctionalModel/Chapter");

            foreach (XmlNode chapterNode in chapterList)
            {
                string     name           = chapterNode.SelectSingleNode("Name").InnerText;
                string     alias          = chapterNode.SelectSingleNode("Alias").InnerText;
                string     description    = chapterNode.SelectSingleNode("Description").InnerText;
                EA.Package chapterPackage = (EA.Package)fmPackage.Packages.AddNew(name, "Package");
                chapterPackage.Alias       = alias;
                chapterPackage.Notes       = description;
                chapterPackage.IsNamespace = true;
                chapterPackage.Update();
                if (chapterColors.ContainsKey(alias))
                {
                    chapterPackage.Element.SetAppearance(1 /*Base*/, 0 /*BGCOLOR*/, chapterColors[alias]);
                }
                chapterPackage.Element.Update();
                chapterPackage.Element.Locked = LOCK_ELEMENTS;

                XmlNodeList functionList = chapterNode.SelectNodes("Function");
                foreach (XmlNode functionNode in functionList)
                {
                    EA.Element functionElement = (EA.Element)chapterPackage.Elements.AddNew("", "Feature");
                    importFunctionOrHeader(functionElement, functionNode, Repository);
                    functionElement.Update();
                    functionElement.Locked = LOCK_ELEMENTS;
                }
            }

            for (int i = 0; i < functionSeeAlsoSource.Count; i++)
            {
                string sourceID = functionSeeAlsoSource[i];
                string targetID = functionSeeAlsoTarget[i];
                if (functions.ContainsKey(targetID))
                {
                    EA.Element   sourceElement = functions[sourceID];
                    EA.Element   targetElement = functions[targetID];
                    EA.Connector connector     = (EA.Connector)sourceElement.Connectors.AddNew("", "Association");
                    connector.Stereotype = "See Also";
                    connector.SupplierID = targetElement.ElementID;
                    connector.Update();
                }
                else
                {
                    EAHelper.LogMessage(string.Format("See Also from {0} to {1}, target not found.", sourceID, targetID));
                }
            }

            for (int i = 0; i < functionLinkSource.Count; i++)
            {
                string sourceID = functionLinkSource[i];
                string targetID = functionLinkTarget[i];
                if (functions.ContainsKey(targetID))
                {
                    EA.Element   sourceElement = functions[sourceID];
                    EA.Element   targetElement = functions[targetID];
                    EA.Connector connector     = (EA.Connector)sourceElement.Connectors.AddNew("", "Dependency");
                    connector.SupplierID = targetElement.ElementID;
                    connector.Update();
                }
                else
                {
                    EAHelper.LogMessage(string.Format("Function link from {0} to {1}, target not found.", sourceID, targetID));
                }
            }

            for (int i = 0; i < functionCompSource.Count; i++)
            {
                string sourceID = functionCompSource[i];
                string targetID = functionCompTarget[i];
                if (functions.ContainsKey(targetID))
                {
                    EA.Element   sourceElement = functions[sourceID];
                    EA.Element   targetElement = functions[targetID];
                    EA.Connector connector     = (EA.Connector)sourceElement.Connectors.AddNew("", "Aggregation");
                    connector.SupplierID = targetElement.ElementID;
                    connector.SupplierEnd.Aggregation = 2; // "composite"
                    connector.Update();
                }
                else
                {
                    EAHelper.LogMessage(string.Format("Function composition from {0} to {1}, target not found.", sourceID, targetID));
                }
            }

            Repository.EnableUIUpdates = true;
            Repository.BatchAppend     = false;

            Repository.RefreshModelView(fmPackage.PackageID);

            Repository.EnsureOutputVisible(Properties.Resources.OUTPUT_TAB_HL7_FM);
        }
Esempio n. 10
0
 public void CreateOutputTab(string Name)
 {
     eaRepository.CreateOutputTab(Name);
 }
Esempio n. 11
0
        //Called when user makes a selection in the menu.
        //This is your main exit point to the rest of your Add-in
        public void EA_MenuClick(EA.Repository Repository, string Location, string MenuName, string ItemName)
        {
            try
            {
                EA.Package selectedPackage = Repository.GetTreeSelectedPackage();
                switch (ItemName)
                {
                case "Import":
                    Repository.CreateOutputTab(MAX_TABNAME);
                    Repository.ClearOutput(MAX_TABNAME);
                    if (new Filters().import(Repository, selectedPackage))
                    {
                        // only popup when there were any issues
                        Repository.EnsureOutputVisible(MAX_TABNAME);
                    }
                    break;

                case "Import NoDelRel":
                    Repository.CreateOutputTab(MAX_TABNAME);
                    Repository.ClearOutput(MAX_TABNAME);
                    if (new Filters().import(Repository, selectedPackage, false))
                    {
                        // only popup when there were any issues
                        Repository.EnsureOutputVisible(MAX_TABNAME);
                    }
                    break;

                case "Export":
                    Repository.CreateOutputTab(MAX_TABNAME);
                    Repository.ClearOutput(MAX_TABNAME);
                    if (new Filters().export(Repository))
                    {
                        // only popup when there were any issues
                        Repository.EnsureOutputVisible(MAX_TABNAME);
                    }
                    break;

                case "Filters":
                    // TODO: create Config Filters Dialogs
                    MessageBox.Show("NYI");
                    break;

                case "Transform":
                    Repository.CreateOutputTab(MAX_TABNAME);
                    Repository.ClearOutput(MAX_TABNAME);
                    if (new TransformParamsForm().Show(Repository))
                    {
                        // only popup when there were any issues
                        Repository.EnsureOutputVisible(MAX_TABNAME);
                    }
                    break;

                case "Validate":
                    Repository.CreateOutputTab(MAX_TABNAME);
                    Repository.ClearOutput(MAX_TABNAME);
                    if (new ValidateParamsForm().Show(Repository))
                    {
                        // only popup when there were any issues
                        Repository.EnsureOutputVisible(MAX_TABNAME);
                    }
                    break;

                case "Merge Diagrams":
                    mergeDiagrams(Repository, selectedPackage);
                    break;

                case "Lock":
                    setLocked(selectedPackage, true);
                    break;

                case "Unlock":
                    setLocked(selectedPackage, false);
                    break;

                case "Batch":
                    batch(Repository);
                    break;

                case "Quick Access Tab":
                    if (view_ctrl == null || !view_ctrl.Visible)
                    {
                        if (view_ctrl != null)
                        {
                            // if control removed dispose old instance
                            view_ctrl.Dispose();
                        }
                        view_ctrl = (QuickAccessControl)Repository.AddTab(MAX_TABNAME, "MAX_EA_Extension.QuickAccessControl");
                        view_ctrl.SetRepository(Repository);
                        Repository.ActivateTab(MAX_TABNAME);
                    }
                    break;

                case "About...":
                    AboutBox about = new AboutBox();
                    about.ShowDialog();
                    break;
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
Esempio n. 12
0
        public void import(EA.Repository Repository, EA.Package rootPackage, string xmlFileName)
        {
            this.Repository            = Repository;
            Repository.EnableUIUpdates = false;
            Repository.BatchAppend     = true;

            Repository.CreateOutputTab(Properties.Resources.OUTPUT_TAB_HL7_FM);
            Repository.ClearOutput(Properties.Resources.OUTPUT_TAB_HL7_FM);
            Repository.EnsureOutputVisible(Properties.Resources.OUTPUT_TAB_HL7_FM);

            // Just make sure the lists,dictionaries are empty
            elements.Clear();
            compositions.Clear();
            consequenceLinks.Clear();

            // Read the XML
            XElement xModel = XElement.Load(xmlFileName);

            // setup progress window
            progress.Show();
            int functionCount = int.Parse(xModel.XPathEvaluate("count(//Function)").ToString());

            progress.setup(functionCount);

            // Create the main package
            string fmName = string.Format("{0} (imported)", getXElementValue(xModel, "Alias"));

            EA.Package fmPackage = (EA.Package)rootPackage.Packages.AddNew(fmName, "Package");
            fmPackage.Version     = getXElementValue(xModel, "Version") + " " + getXElementValue(xModel, "Date");
            fmPackage.Notes       = xModel.XPathSelectElement("Overview").CreateNavigator().InnerXml.Replace("<br />", "\r\n");
            fmPackage.IsNamespace = true;
            fmPackage.Update();
            fmPackage.Element.Stereotype = R2Const.ST_FM;
            fmPackage.Element.Author     = getXElementValue(xModel, "Author");
            fmPackage.Element.Phase      = getXElementValue(xModel, "Type");
            fmPackage.Element.Update();
            fmPackage.Element.Locked = LOCK_ELEMENTS;

            // Start with the chapters (section!) and iterate functions/headers and attach criteria
            foreach (XElement xChapter in xModel.Elements("Chapter"))
            {
                string name     = getXElementValue(xChapter, "Name");
                string ID       = getXElementValue(xChapter, "ID");
                string alias    = getXElementValue(xChapter, "Alias");
                string overview = getXElementValue(xChapter, "Overview");
                string example  = getXElementValue(xChapter, "Example");
                string actors   = getXElementValue(xChapter, "Actors");
                string notes    = string.Format("$OV${0}$EX${1}$AC${2}", overview, example, actors);

                EA.Package sectionPackage = (EA.Package)fmPackage.Packages.AddNew(name, "Package");
                sectionPackage.Notes       = notes;
                sectionPackage.IsNamespace = true;
                sectionPackage.TreePos     = int.Parse(ID);
                sectionPackage.Update();
                sectionPackage.Element.Alias      = alias;
                sectionPackage.Element.Stereotype = R2Const.ST_SECTION;
                R2Config.config.updateStyle(sectionPackage.Element);
                sectionPackage.Element.Update();
                sectionPackage.Element.Locked = LOCK_ELEMENTS;

                // Create TaggedValues for extra notes
                addTaggedValue(sectionPackage.Element, "ID", ID);

                int TPos = 0;
                foreach (XElement xFunction in xChapter.Elements("Function"))
                {
                    EA.Element functionElement;
                    string     parentID = getXElementValue(xFunction, "ParentID");
                    if (elements.ContainsKey(parentID))
                    {
                        EA.Element parentElement = elements[parentID];
                        functionElement = (EA.Element)parentElement.Elements.AddNew("", "Feature");
                    }
                    else // If the parent function doesnot exist; add to the sectionPackage; chapters are not in the functions dictionary
                    {
                        functionElement = (EA.Element)sectionPackage.Elements.AddNew("", "Feature");
                    }
                    string functionID = getXElementValue(xFunction, "ID");
                    addComposition(functionID, parentID);
                    importFunction(functionElement, xFunction);
                    functionElement.TreePos = TPos++; // Keep order from import file
                    functionElement.Update();
                    functionElement.Locked = LOCK_ELEMENTS;
                }
            }

            // Add ConsequenceLinks
            foreach (Link clink in consequenceLinks.Values)
            {
                if (elements.ContainsKey(clink.targetID))
                {
                    EA.Element   sourceElement = elements[clink.sourceID];
                    EA.Element   targetElement = elements[clink.targetID];
                    EA.Connector connector     = (EA.Connector)sourceElement.Connectors.AddNew("", "Dependency");
                    connector.Stereotype = R2Const.ST_CONSEQUENCELINK;
                    connector.Notes      = clink.notes;
                    connector.SupplierID = targetElement.ElementID;
                    connector.Update();
                }
                else
                {
                    EAHelper.LogMessage(string.Format("ConsequenceLink from {0} to {1}, target Function not found.", clink.sourceID, clink.targetID));
                }
            }

            // Add SeeAlso Links
            foreach (Link slink in seeAlsoLinks.Values)
            {
                if (elements.ContainsKey(slink.targetID))
                {
                    EA.Element   sourceElement = elements[slink.sourceID];
                    EA.Element   targetElement = elements[slink.targetID];
                    EA.Connector connector     = (EA.Connector)sourceElement.Connectors.AddNew("", "Dependency");
                    connector.Stereotype = R2Const.ST_SEEALSO;
                    connector.SupplierID = targetElement.ElementID;
                    connector.Update();
                }
                else
                {
                    EAHelper.LogMessage(string.Format("SeeAlso link from {0} to {1}, target Function not found.", slink.sourceID, slink.targetID));
                }
            }

            // Add compositions
            foreach (Link composition in compositions.Values)
            {
                if (elements.ContainsKey(composition.targetID))
                {
                    EA.Element   sourceElement = elements[composition.sourceID];
                    EA.Element   targetElement = elements[composition.targetID];
                    EA.Connector connector     = (EA.Connector)sourceElement.Connectors.AddNew("", "Aggregation");
                    connector.SupplierID = targetElement.ElementID;
                    connector.SupplierEnd.Aggregation = 2; // "composite"
                    connector.Update();
                }
                else
                {
                    // If the target is the section package then ignore the link
                    int?sectionColor = R2Config.config.getSectionColorInt(composition.targetID);
                    if (sectionColor == null)
                    {
                        EAHelper.LogMessage(string.Format("Function composition from {0} to {1}, target not found.", composition.sourceID, composition.targetID));
                    }
                }
            }
            progress.Close();

            Repository.EnableUIUpdates = true;
            Repository.BatchAppend     = false;
            Repository.RefreshModelView(fmPackage.PackageID);
            Repository.EnsureOutputVisible(Properties.Resources.OUTPUT_TAB_HL7_FM);
        }