private void appendSvrlMessagesToOutputTab(EA.Repository repository, IEnumerable <XElement> xSvrlMessages, Dictionary <string, EA.Element> eaElementDict, XmlNamespaceManager nsmgr) { foreach (XElement xSvrlMessage in xSvrlMessages) { string idtxt = xSvrlMessage.XPathSelectElement("svrl:text", nsmgr).Value; // Not all issues are associated to an element XElement xSvrlDiag = xSvrlMessage.XPathSelectElement("svrl:diagnostic-reference", nsmgr); string code = xSvrlDiag.Attribute("diagnostic").Value; string message = xSvrlDiag.Value.Trim(); if (eaElementDict.ContainsKey(idtxt)) { EA.Element element = eaElementDict[idtxt]; string issueName = string.Format("{0}:{1} - {2}", code, message, element.Name); EAHelper.LogMessage(issueName, element.ElementID); } else { string issueName = string.Format("{0}:{1}", code, message); EAHelper.LogMessage(issueName); } //EA.ProjectIssues issue = (EA.ProjectIssues)Repository.Issues.AddNew(issueName, "ProjectIssues"); //issue.Update(); } }
private void setCompilerInstruction(R2ModelElementHolder dl, R2Const.Qualifier qualifier, string change_note = null) { // If there is no Compiler Instruction, create one if (dl.compilerInstructionEAElement == null) { dl.compilerInstructionEAElement = (EA.Element)profileDefinitionPackage.Elements.AddNew(dl.baseModelEAElement.Name, "Class"); dl.compilerInstructionEAElement.Stereotype = R2Const.ST_COMPILERINSTRUCTION; dl.compilerInstructionEAElement.Update(); if (dl.baseModelEAElement.Type == "Package") { EA.Connector con = (EA.Connector)dl.compilerInstructionEAElement.Connectors.AddNew("", "Dependency"); con.Stereotype = "Generalization"; con.SupplierID = dl.baseModelEAElement.ElementID; con.Update(); } else { EA.Connector con = (EA.Connector)dl.compilerInstructionEAElement.Connectors.AddNew("", "Generalization"); con.SupplierID = dl.baseModelEAElement.ElementID; con.Update(); } dl.compilerInstructionEAElement.Connectors.Refresh(); dl.modelElement = R2ModelV2.EA_API.Factory.Create(repository, dl.compilerInstructionEAElement); profileDefinitionPackage.Elements.Refresh(); } switch (qualifier) { case R2Const.Qualifier.Deprecate: EAHelper.SetTaggedValue(dl.compilerInstructionEAElement, R2Const.TV_QUALIFIER, "DEP"); break; case R2Const.Qualifier.Delete: EAHelper.SetTaggedValue(dl.compilerInstructionEAElement, R2Const.TV_QUALIFIER, "D"); break; case R2Const.Qualifier.Exclude: EAHelper.SetTaggedValue(dl.compilerInstructionEAElement, R2Const.TV_QUALIFIER, "EXCLUDE"); break; case R2Const.Qualifier.None: default: EAHelper.SetTaggedValue(dl.compilerInstructionEAElement, R2Const.TV_QUALIFIER, ""); break; } if (!string.IsNullOrEmpty(change_note)) { EAHelper.SetTaggedValue(dl.compilerInstructionEAElement, R2Const.TV_CHANGENOTE, "<memo>", change_note); } else { EAHelper.DeleteTaggedValue(dl.compilerInstructionEAElement, R2Const.TV_CHANGENOTE); } dl.compilerInstructionEAElement.TaggedValues.Refresh(); dl.compilerInstructionEAElement.Refresh(); }
// Last argument is ID of Element (used for double click!) public void writeOutput(string format, params object[] arg) { int ID = -1; object lastArg = arg[arg.Count() - 1]; if (lastArg is int) { ID = (int)lastArg; } EAHelper.LogMessage(string.Format(format, arg), ID); }
private bool addLink(string sourceID, string targetID, EA.Repository Repository) { // Check for dubbles for (int i = 0; i < functionLinkSource.Count; i++) { if (functionLinkSource[i] == sourceID && functionLinkTarget[i] == targetID) { EAHelper.LogMessage(string.Format("Duplicate Function link from {0} to {1}", sourceID, targetID)); return(false); } } functionLinkSource.Add(sourceID); functionLinkTarget.Add(targetID); return(true); }
private bool addSeeAlsoLink(string sourceID, string targetID) { // Check for dubbles string key = string.Format("{0}-{1}", sourceID, targetID); if (seeAlsoLinks.ContainsKey(key)) { EAHelper.LogMessage(string.Format("Function {0} see-also to {1}, already there", sourceID, targetID)); return(false); } else { seeAlsoLinks[key] = new Link(sourceID, targetID, null); return(true); } }
private bool addConsequenceLink(string sourceID, string targetID, string notes) { // Check for dubbles string key = string.Format("{0}-{1}", sourceID, targetID); if (consequenceLinks.ContainsKey(key)) { EAHelper.LogMessage(string.Format("Function {0} link to {1}, already there", sourceID, targetID)); return(false); } else { consequenceLinks[key] = new Link(sourceID, targetID, notes); return(true); } }
//This event occurs when a user has double-clicked (or pressed [Enter]) //on the item in context, either in a diagram or in the Project Browser. public bool EA_OnContextItemDoubleClicked(EA.Repository repository, string GUID, EA.ObjectType ot) { if (ot == EA.ObjectType.otElement) { EA.Element element = repository.GetElementByGuid(GUID); R2ModelElement modelElement = R2ModelV2.EA_API.Factory.Create(repository, element); if (modelElement != null) { switch (modelElement.Stereotype) { case R2Const.ST_SECTION: // For Section Compiler Instruction! new SectionForm().Show((R2Section)modelElement); return(true); case R2Const.ST_HEADER: case R2Const.ST_FUNCTION: new FunctionForm().Show((R2Function)modelElement); return(true); case R2Const.ST_CRITERION: new CriterionForm().Show((R2Criterion)modelElement); return(true); } } } else if (ot == EA.ObjectType.otPackage) { EA.Element element = repository.GetPackageByGuid(GUID).Element; switch (element.Stereotype) { case R2Const.ST_FM_PROFILE: return(false); case R2Const.ST_FM_PROFILEDEFINITION: EA.Package profDefPackage = repository.GetPackageByGuid(GUID); R2ProfileDefinition profDef = (R2ProfileDefinition)R2ModelV2.EA_API.Factory.Create(repository, profDefPackage.Element); profDef.BaseModelName = EAHelper.getAssociatedBaseModelName(repository, profDefPackage); new ProfileMetadataForm().Show(profDef); return(true); case R2Const.ST_SECTION: new SectionForm().Show((R2ModelV2.Base.R2Section)R2ModelV2.EA_API.Factory.Create(repository, element)); return(true); } } return(false); }
public static EA.Package getAssociatedOutputProfile(EA.Repository Repository, EA.Package ProfileDefinitionPackage) { EA.Connector con = ProfileDefinitionPackage.Connectors.Cast <EA.Connector>().SingleOrDefault(t => R2Const.ST_TARGETPROFILE.Equals(t.Stereotype)); if (con != null) { EA.Element packageElement = Repository.GetElementByID(con.SupplierID); if (R2Const.ST_FM_PROFILE.Equals(packageElement.Stereotype)) { // con.SupplierID is the ElementID of the PackageElement // Find the Package with the PackageElement by selecting the child Package in the parent Package where // the ElementID is con.SupplierID return(Repository.GetPackageByID(packageElement.PackageID).Packages.Cast <EA.Package>().Single(p => p.Element.ElementID == con.SupplierID)); } } EAHelper.LogMessage("Expected <create> relationship to a <HL7-FM-Profile> Package == Compiled Profile Model"); return(null); }
public static EA.Package getAssociatedProfileDefinition(EA.Repository repository, EA.Package selectedSectionPackage) { EA.Package baseModel = repository.GetPackageByID(selectedSectionPackage.ParentID); EA.Connector con = baseModel.Connectors.Cast <EA.Connector>().SingleOrDefault(t => R2Const.ST_BASEMODEL.Equals(t.Stereotype) || "Usage".Equals(t.Type)); if (con != null) { EA.Element packageElement = repository.GetElementByID(con.ClientID); if (R2Const.ST_FM_PROFILEDEFINITION.Equals(packageElement.Stereotype)) { // con.ClientID is the ElementID of the PackageElement // Find the Package with the PackageElement by selecting the child Package in the parent Package where // the ElementID is con.ClientID return(repository.GetPackageByID(packageElement.PackageID).Packages.Cast <EA.Package>().Single(p => p.Element.ElementID == con.ClientID)); } } EAHelper.LogMessage("Expected <use> relationship to a <HL7-FM> Package == Base Model"); return(null); }
private void updateListViewItem(ListViewItem item) { bool _ignoreEvent = ignoreEvent; ignoreEvent = true; R2ModelElementHolder dl = (R2ModelElementHolder)item.Tag; if (dl.compilerInstructionEAElement != null) { switch (EAHelper.GetTaggedValue(dl.compilerInstructionEAElement, R2Const.TV_QUALIFIER, "")) { case "DEP": item.ForeColor = Color.White; item.BackColor = BACKCOLOR_DEPRECATED; item.Checked = true; break; case "D": item.ForeColor = Color.White; item.BackColor = BACKCOLOR_DELETED; item.Checked = false; break; case "EXCLUDE": // special for excluded criteria; excluded is kind of deleted item.ForeColor = Color.LightGray; item.BackColor = BACKCOLOR_EXCLUDED; item.Checked = false; break; default: // "" item.ForeColor = Color.White; item.BackColor = BACKCOLOR_INCLUDED; item.Checked = true; break; } } else { item.ForeColor = Color.Black; item.BackColor = BACKCOLOR_EXCLUDED; item.Checked = false; } ignoreEvent = _ignoreEvent; }
/** * 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."); } }
//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 R1.1": new R11Importer().import(Repository, SelectedPackage); break; case "Import R2": new R2Importer().import(Repository, SelectedPackage); break; case "Validate": new R2Validator().validate(Repository, SelectedPackage); break; case "Update Style": UpdateStyle_recurseEaPackage(SelectedPackage); break; case "Edit Profile": new ProfilingForm().Show(Repository, SelectedPackage); break; case "Compile Profile": CompileProfile(Repository, SelectedPackage); break; case "Merge Profiles": new MergeProfilesForm().PopulateAndShow(); break; case "Create Diagram": CreateDiagram(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("HL7 FM", "HL7_FM_EA_Extension.QuickAccessControl"); view_ctrl.SetRepository(Repository); Repository.ActivateTab("HL7 FM"); } break; case "FM Browser Tab": if (mb_ctrl == null || !mb_ctrl.Visible) { if (mb_ctrl != null) { // if control removed dispose old instance mb_ctrl.Dispose(); } mb_ctrl = (ModelBrowserControl)Repository.AddTab("FM Browser", "HL7_FM_EA_Extension.ModelBrowserControl"); mb_ctrl.SetRepository(Repository); Repository.ActivateTab("FM Browser"); } break; case "About": AboutBox about = new AboutBox(); about.ShowDialog(); break; } } catch (Exception e) { EAHelper.LogMessage(e.ToString()); MessageBox.Show(e.ToString(), "FATAL", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
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); }
public void Show(EA.Repository repository, EA.Package selectedPackage) { toolTip1.SetToolTip(button1, "Click to select the current Criterion in the Project Browser.\nNote that if there is a Compiler Instruction that will be selected instead."); toolTip1.SetToolTip(button2, "Click to select the current Element in the Project Browser.\nNote that if there is a Compiler Instruction that will be selected instead."); toolTip1.SetToolTip(excludeRadioButton, "The current Element (and children) will be excluded."); toolTip1.SetToolTip(includeRadioButton, "The current Element (and children) will be included."); toolTip1.SetToolTip(deprecateRadioButton, "The current Element (and children) will be included and marked as deprecated."); toolTip1.SetToolTip(deleteRadioButton, "The current Element (and children) will be included and marked as deleted."); toolTip1.SetToolTip(groupCheckBox, "If checked the Elements will be grouped. If unchecked the Elements will be presented in a list."); this.repository = repository; if (repository.GetTreeSelectedItemType() == EA.ObjectType.otElement) { EA.Element selectedElement = (EA.Element)repository.GetTreeSelectedObject(); if (R2Const.ST_HEADER.Equals(selectedElement.StereotypeEx) || R2Const.ST_FUNCTION.Equals(selectedElement.StereotypeEx)) { profileDefinitionPackage = EAHelper.getAssociatedProfileDefinition(repository, selectedPackage); if (profileDefinitionPackage != null) { Text = string.Format("Profile Definition for {0}: {1}", selectedElement.StereotypeEx, selectedElement.Name); Show(); Refresh(); mainListView.Items.Clear(); mainListView.Groups.Clear(); mainGroup = new ListViewGroup(""); mainListView.Groups.Add(mainGroup); ListViewItem item = createListViewItem(selectedElement); item.Group = mainGroup; mainListView.Items.Add(item); createElementGroup(string.Format("«{0}» {1}", selectedElement.StereotypeEx, selectedElement.Name), selectedElement.Elements); } else { MessageBox.Show(Main.MESSAGE_PROFILE_DEFINITION, "Complete setup", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } } else if (selectedPackage != null && R2Const.ST_SECTION.Equals(selectedPackage.StereotypeEx)) { profileDefinitionPackage = EAHelper.getAssociatedProfileDefinition(repository, selectedPackage); if (profileDefinitionPackage != null) { Text = string.Format("Profile Definition for Section: {0}", selectedPackage.Name); Show(); Refresh(); mainListView.Items.Clear(); mainListView.Groups.Clear(); mainGroup = new ListViewGroup(""); mainListView.Groups.Add(mainGroup); ListViewItem item = createListViewItem(selectedPackage); item.Group = mainGroup; mainListView.Items.Add(item); Cursor = Cursors.WaitCursor; visitPackage(selectedPackage); Cursor = Cursors.Default; } else { MessageBox.Show(Main.MESSAGE_PROFILE_DEFINITION, "Complete setup", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } else { MessageBox.Show("Select a Base FM Section to Profile.", "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
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); }