/// <summary> /// Adds a package and its children to the node /// </summary> /// <param name="node">Node to be added to</param> /// <param name="package">Package to be added</param> /// <returns>A node with the package information and its children</returns> private TreeNode AddPackageNode(TreeNode node, IEAPackage package) { node.ImageKey = package.GUID; node.Text = package.Name; foreach (IEAPackage el in package.Packages) { //Skip history package and packages without elements if (el.Stereotype.Equals(EAConstants.ChronologicalStereoType) || !el.GetAllElementsOfSubTree().Any()) { continue; } node.Nodes.Add(AddPackageNode(new TreeNode(), el)); } foreach (IEAElement el in package.Elements) { if (el.Name.Equals("") || el.IsHistoryDecision()) { continue; } if (_decision && (!el.IsDecision() && !el.IsTopic())) { continue; } node.Nodes.Add(AddElementToNode(new TreeNode(), el)); } return(node); }
public ChronologicalViewpointGenerator(List <IEAElement> decisions, IEAPackage historyPackage, IEADiagram chronologicalViewpoint) { _chronologicalViewpoint = chronologicalViewpoint; _historyPackage = historyPackage; _decisions = decisions; }
public static void CreateAndTraceTopic() { IEARepository repository = EAMain.Repository; if (repository.GetContextItemType() == EANativeType.Element) { var eaelement = repository.GetContextObject <IEAElement>(); if (eaelement != null && !EAMain.IsDecision(eaelement) && !EAMain.IsTopic(eaelement)) { string nameSuggestion = string.Format(Messages.NameSuggestionTopic, eaelement.Name); var createTopicView = new CreateTopicDialog(nameSuggestion); if (createTopicView.ShowDialog() == DialogResult.OK) { IEAPackage dvPackage = createTopicView.GetDecisionViewPackage(); IEAElement topic = dvPackage.CreateElement(createTopicView.GetName(), EAConstants.TopicStereoType, EAConstants.ActivityMetaType); topic.MetaType = EAConstants.TopicMetaType; topic.AddTaggedValue(EATaggedValueKeys.DecisionStateModifiedDate, DateTime.Now.ToString(CultureInfo.InvariantCulture)); eaelement.ConnectTo(topic, EAConstants.AbstractionMetaType, EAConstants.RelationTrace); topic.Update(); dvPackage.RefreshElements(); repository.RefreshModelView(dvPackage.ID); topic.ShowInProjectView(); } } } }
public static void Generate() { if (EANativeType.Package != EAMain.Repository.GetContextItemType()) { return; } var eapackage = EAMain.Repository.GetContextObject <IEAPackage>(); if (null == eapackage) { return; } var view = new GenerateChronologyViewDialog(); if (DialogResult.OK == view.ShowDialog()) { IEADiagram chronologicalView = CreateChronologyDiagram(eapackage, view.ViewName); IEAPackage historyPackage = eapackage.GetSubpackageByName("History data for " + chronologicalView.Name); if (historyPackage != null) { historyPackage.ParentPackage.DeletePackage(historyPackage); } historyPackage = eapackage.CreatePackage("History data for " + chronologicalView.Name, EAConstants.ChronologicalStereoType); var generator = new ChronologicalViewpointGenerator(view.Decisions, historyPackage, chronologicalView); generator.GenerateViewpoint(); } }
public void EA_ConfirmMDG() { bool validMDG = false; IEAPackage package = _e.GetDecisionPackage(); IEnumerable <IEAElement> topics = package.GetAllTopics(); Assert.IsTrue(topics.Any()); foreach (IEAElement topic in topics) { // Confirm the topic contains decision elements IEnumerable <IEAElement> elems = topic.GetElements(); foreach (IEAElement elem in elems) { if (EAConstants.DecisionMetaType == elem.MetaType) { validMDG = true; break; } } if (validMDG) { break; } } Assert.IsTrue(validMDG); }
private void add_Click(object sender, EventArgs e) { TreeNode node = treeAllDecisions.SelectedNode; string guid = node.ImageKey; switch (EAUtilities.IdentifyGUIDType(guid)) { case EANativeType.Package: case EANativeType.Model: IEAPackage package = EAMain.Repository.GetPackageByGUID(guid); foreach (IEAElement d in package.GetAllDecisions()) { if (!Decisions.Contains(d)) { Decisions.Add(d); listSelectedDecisions.Items.Add(d); node.Checked = true; } } break; case EANativeType.Element: IEAElement decision = EAMain.Repository.GetElementByGUID(guid); if (!Decisions.Contains(decision)) { Decisions.Add(decision); listSelectedDecisions.Items.Add(decision); node.Checked = true; } break; } UpdateButtonStates(); }
public IEAPackage GetDecisionPackageFolder() { IEAPackage package = GetDecisionPackage(); IList <IEAPackage> folder = package.Packages; Assert.IsTrue(folder.Any()); // Use first topic return(folder.First()); }
public string GetProjectPath() { IEAPackage current = ParentPackage; string path = current.Name; while (!current.IsModelRoot()) { current = current.ParentPackage; path = current.Name + "/" + path; } path = "//" + path; return(path); }
public IEAPackage GetSubpackageByName(string data) { IList <IEAPackage> packages = Packages; if (packages.Any()) { IEAPackage foundPackage = packages.FirstOrDefault(e => e.Name.Equals(data)); if (foundPackage != null) { return(foundPackage); } } return(null); }
public IEnumerable <IEADiagram> GetAllDiagrams() { var diagrams = new List <IEADiagram>(); var packagesStack = new Stack <IEAPackage>(); packagesStack.Push(this); while (packagesStack.Count > 0) { IEAPackage package = packagesStack.Pop(); package.GetDiagrams().ToList().ForEach(diagrams.Add); package.Packages.ToList().ForEach(packagesStack.Push); } return(diagrams); }
public IEAPackage GetDecisionPackage() { Assert.IsNotNull(Repo); EAMain.UpdateRepository(Repo); IEnumerable <IEAPackage> packages = EAMain.Repository.GetAllPackages(); Assert.IsNotNull(packages); // Top level package IEAPackage example = packages.First(); // Use the first decision package IEAPackage decisions = example.GetSubpackageByName("Decisions"); Assert.IsNotNull(decisions); return(decisions); }
public void DeletePackage(IEAPackage package) { short index = 0; foreach (Package p in _native.Packages.Cast <Package>()) { if (p.PackageGUID.Equals(package.GUID)) { _native.Packages.DeleteAt(index, true); _native.Packages.Refresh(); EARepository.Instance.RefreshModelView(_native.PackageID); return; } index++; } }
private bool deleteElementFromPackage(IEAPackage package, IEAElement element) { short i = 0; bool found = false; foreach (IEAElement e in package.Elements) { if (element.ID == e.ID) { package.DeleteElement(i); found = true; break; } i++; } return(found); }
private IEADiagram GetDecisionRelationshipDiagram() { IEADiagram diagram = null; IEAPackage package = GetDecisionPackage(); IEnumerable <IEADiagram> diagrams = package.GetAllDiagrams(); Assert.IsNotNull(diagrams); // Find a forces viewpoint foreach (IEADiagram d in diagrams) { if (d.IsRelationshipView()) { diagram = d; break; } } Assert.IsNotNull(diagram); return(diagram); }
private IEADiagram GetDecisionStakeholderDiagram() { IEADiagram diagram = null; IEAPackage package = GetDecisionPackage(); IEnumerable <IEADiagram> diagrams = package.GetAllDiagrams(); Assert.IsNotNull(diagrams); // Find a forces viewpoint foreach (IEADiagram d in diagrams) { if (d.IsStakeholderInvolvementView()) { diagram = d; break; } } Assert.IsNotNull(diagram); return(diagram); }
/// <summary> /// Adds a package and its children to the node /// </summary> /// <param name="node">Node to be added to</param> /// <param name="package">Package to be added</param> /// <returns>A node with the package information and its children</returns> private TreeNode AddPackageNode(TreeNode node, IEAPackage package) { node.ImageKey = package.GUID; node.Text = package.Name; foreach (IEAPackage subPackage in package.Packages) { //Skip history package and packages without elements if (subPackage.Stereotype.Equals(EAConstants.ChronologicalStereoType) || !subPackage.GetAllElementsOfSubTree().Any()) { continue; } TreeNode subPackageNode = AddPackageNode(new TreeNode(), subPackage); if (null != subPackageNode) { node.Nodes.Add(subPackageNode); } } int count = 0; foreach (IEAElement element in package.Elements) { if (element.Name.Equals("") || EAMain.IsHistoryDecision(element)) { continue; } if (_decision && (!EAMain.IsDecision(element) && !EAMain.IsTopic(element))) { continue; } node.Nodes.Add(AddElementToNode(new TreeNode(), element)); ++count; } if (node.GetNodeCount(true) == 0) { return(null); } return(node); }
public Element GetDecisionPackageElement() { IEAPackage folder = GetDecisionPackageFolder(); Package root = Repo.Models.GetAt(0); Assert.IsNotNull(root); Package example = root.Packages.GetByName("Example"); Assert.IsNotNull(example); Package decisions = example.Packages.GetByName("Decisions"); Assert.IsNotNull(decisions); Package topics = decisions.Packages.GetByName(folder.Name); Assert.IsNotNull(topics); Assert.IsTrue(0 < topics.Elements.Count); Element element = topics.Elements.GetAt(0); Assert.IsNotNull(element); return(element); }
public IEnumerable <IEAElement> GetAllElementsOfSubTree() { var elements = new List <IEAElement>(); var packagesStack = new Stack <IEAPackage>(); var elementsStack = new Stack <IEAElement>(); packagesStack.Push(this); while (packagesStack.Count > 0) { IEAPackage package = packagesStack.Pop(); package.Elements.ToList().ForEach(elementsStack.Push); package.Packages.ToList().ForEach(packagesStack.Push); } while (elementsStack.Count > 0) { IEAElement element = elementsStack.Pop(); element.GetElements().ForEach(elementsStack.Push); elements.Add(element); } return(elements); }
private TreeNode CreateTreeNode(IEAPackage package) { TreeNode packageNode = null; IEnumerable <TreeNode> decisions = package.Elements.Where(e => EAMain.IsDecision(e) && !EAMain.IsHistoryDecision(e)) .Select(e => new TreeNode(Name = e.Name) { ImageKey = e.GUID }); IEnumerable <TreeNode> subpackages = package.Packages.Select(CreateTreeNode).Where(node => node != null); IOrderedEnumerable <TreeNode> subtree = decisions.Union(subpackages).OrderBy(node => node.Name); if (subtree.Any()) { packageNode = new TreeNode(package.Name, subtree.ToArray()) { ImageKey = package.GUID }; } return(packageNode); }
public IEADiagram GetDecisionForcesDiagram() { IEADiagram diagram = null; IEAPackage folder = GetDecisionPackageFolder(); IList <IEAElement> topics = folder.Elements; Assert.IsTrue(topics.Any()); // Use the first topic IEAElement topic = topics.First(); IEnumerable <IEADiagram> diagrams = topic.GetDiagrams(); Assert.IsNotNull(diagrams); // Find a forces viewpoint foreach (IEADiagram d in diagrams) { if (d.IsStakeholderInvolvementView()) { diagram = d; break; } } Assert.IsNotNull(diagram); return(diagram); }
public virtual bool OnPostNewPackage(IEAPackage package) { return(true); }
public virtual bool OnPreDeletePackage(IEAPackage pacakge) { return(true); }
public void AddSubPackage(IEAPackage package) { subPackages.Add(package); package.ParentPackage = this; }
private static IEADiagram CreateChronologyDiagram(IEAPackage package, string viewName) { return(package.CreateDiagram(viewName, "generated", EAConstants.DiagramMetaTypeChronological)); }
public static void GenerateReport(IEAPackage decisionViewPackage, string filename, ReportType reportType) { IEARepository repository = EAMain.Repository; List <IDecision> decisions = decisionViewPackage.GetAllDecisions().Select(element => Decision.Load(element)).ToList(); List <IEADiagram> diagrams = decisionViewPackage.GetAllDiagrams().ToList(); IReportDocument report = null; try { string filenameExtension = filename.Substring(filename.IndexOf('.')); var saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Title = Messages.SaveReportAs; saveFileDialog1.Filter = "Microsoft " + reportType.ToString() + " (*" + filenameExtension + ")|*" + filenameExtension; saveFileDialog1.FilterIndex = 0; if (saveFileDialog1.ShowDialog() != DialogResult.OK) { return; } saveFileDialog1.CheckFileExists = true; saveFileDialog1.CheckPathExists = true; string reportFilename = saveFileDialog1.FileName; report = ReportFactory.Create(reportType, reportFilename); //if the report cannot be created because is already used by another program a message will appear if (report == null) { MessageBox.Show("Check if another program is using this file.", "Fail to create report", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } report.Open(); //Insert Decision Relationship Viewpoint foreach (IEADiagram diagram in diagrams.Where(diagram => diagram.IsRelationshipView())) { report.InsertDiagramImage(diagram); } //Retrieve Topics List <ITopic> topics = (from IEAElement element in repository.GetAllElements() where EAMain.IsTopic(element) select Topic.Load(element)).ToList(); report.InsertDecisionDetailViewMessage(); // Insert Decisions that have a Topic foreach (ITopic topic in topics) { report.InsertTopicTable(topic); //Insert Decisions with parent element the current Topic foreach (IDecision decision in decisions) { IEAElement parent = EAMain.Repository.GetElementByGUID(decision.Topic.GUID); if (parent != null && EAMain.IsTopic(parent)) { if (parent.GUID.Equals(topic.GUID)) { report.InsertDecisionTable(decision); } } } } // Insert an appropriate message before the decisions that are not included in a topic report.InsertDecisionWithoutTopicMessage(); // Insert decisions without a Topic foreach (IDecision decision in decisions) { IEAElement parent = EAMain.Repository.GetElementByID(decision.ID).ParentElement; if (parent == null || !EAMain.IsTopic(parent)) { report.InsertDecisionTable(decision); } } foreach ( IEADiagram diagram in diagrams.Where(diagram => !diagram.IsForcesView() && !diagram.IsRelationshipView())) { report.InsertDiagramImage(diagram); } foreach (IEADiagram diagram in diagrams.Where(diagram => diagram.IsForcesView())) { report.InsertForcesTable(new ForcesModel(diagram)); } var customMessage = new ExportReportsCustomMessageBox(reportType.ToString(), reportFilename); customMessage.Show(); } finally { if (report != null) { report.Close(); } } }
public void EA_DiagramTests() { // Properties { IEADiagram diagram = _e.GetDecisionForcesDiagram(); Assert.IsTrue(DateTime.Now > diagram.Created); Assert.IsTrue(EANativeType.Diagram == diagram.EANativeType); Assert.IsTrue("" != diagram.GUID); Assert.IsTrue(0 < diagram.ID); Assert.IsTrue("" != diagram.Metatype); Assert.IsTrue(DateTime.Now > diagram.Modified); Assert.IsTrue("" != diagram.Name); Assert.IsTrue("" == diagram.Notes); Assert.IsNotNull(diagram.ParentElement); Assert.IsNotNull(diagram.ParentPackage); Assert.IsTrue("" != diagram.Version); } // Operations { // IsForcesView / AddElement / Contains / OpenAndSelectElement / HideConnectors / RemoveElement IEAPackage package = _e.GetDecisionPackage(); IEADiagram diagram = _e.GetDecisionForcesDiagram(); IEAElement element = package.CreateElement("MyNote", "MyStereotype", "Note"); package.RefreshElements(); diagram.AddElement(element); Assert.IsTrue(diagram.Contains(element)); diagram.OpenAndSelectElement(element); diagram.HideConnectors(new[] { EAConstants.RelationAlternativeFor, EAConstants.RelationCausedBy, EAConstants.RelationDependsOn, EAConstants.RelationExcludedBy, EAConstants.RelationReplaces, EAConstants.RelationFollowedBy }); diagram.RemoveElement(element); Assert.IsFalse(diagram.Contains(element)); Assert.IsTrue(deleteElementFromPackage(package, element)); } { // ShowInProjectView / DiagramToStream IEAPackage package = _e.GetDecisionPackage(); IEADiagram diagram = _e.GetDecisionForcesDiagram(); diagram.ShowInProjectView(); FileStream fs = diagram.DiagramToStream(); Assert.IsNotNull(fs); Assert.IsTrue(fs.Name.Contains(".emf")); } { // GetElements IEAPackage package = _e.GetDecisionPackage(); IEADiagram diagram = _e.GetDecisionForcesDiagram(); List <IEADiagramObject> objs = diagram.GetElements(); Assert.IsNotNull(objs); Assert.IsTrue(0 < objs.Count); } /* TODO: adjust for Decision Architect MDG * { // IsChronologicalView * IEAPackage package = _e.GetDecisionPackage(); * IEADiagram diagram = _e.GetDecisionChronologicalDiagram(); * } * * { // IsRelationshipView * IEAPackage package = _e.GetDecisionPackage(); * IEADiagram diagram = _e.GetDecisionRelationshipDiagram(); * } * * { // IsStakeholderInvolvementView * IEAPackage package = _e.GetDecisionPackage(); * IEADiagram diagram = _e.GetDecisionStakeholderDiagram(); * } */ }
public void EA_PackageTests() { // Properties { IEAPackage folder = _e.GetDecisionPackageFolder(); Assert.IsTrue(DateTime.Now > folder.Created); Assert.IsTrue(EANativeType.Package == folder.EANativeType); Assert.IsTrue(folder.Elements.Any()); Assert.IsTrue("" != folder.GUID); Assert.IsTrue(0 < folder.ID); Assert.IsTrue(DateTime.Now > folder.Modified); Assert.IsTrue("" != folder.Name); Assert.IsTrue("" == folder.Notes); Assert.IsTrue(!folder.Packages.Any()); Assert.IsNotNull(folder.ParentPackage); Assert.IsTrue("1.0" == folder.Version); Assert.IsTrue("system" == folder.Stereotype); } // Operations // See the Type property in the EAMain Element class documentation for a list of valid element types. { // CreatePackage / DeletePackage IEAPackage package = _e.GetDecisionPackage(); IEAPackage inner = package.CreatePackage("MyPackage", "MyStereotype"); Assert.IsNotNull(inner); package.RefreshElements(); Assert.IsTrue("MyPackage" == inner.Name); Assert.IsTrue("MyStereotype" == inner.Stereotype); package.DeletePackage(inner); } { // CreateElement IEAPackage package = _e.GetDecisionPackage(); IEAElement element = package.CreateElement("MyNote", "MyStereotype", "Note"); Assert.IsNotNull(element); package.RefreshElements(); Assert.IsTrue("MyNote" == element.Name); Assert.IsTrue("MyStereotype" == element.Stereotype); Assert.IsTrue("Note" == element.Type); Assert.IsTrue(deleteElementFromPackage(package, element)); } { // GetAllDiagrams / GetDiagram IEAPackage folder = _e.GetDecisionPackageFolder(); IEnumerable <IEADiagram> diagrams = folder.GetAllDiagrams(); Assert.IsNotNull(diagrams); IEADiagram first = diagrams.ElementAt(0); IEADiagram diagram = folder.GetDiagram(first.Name); Assert.IsNotNull(diagram); Assert.IsTrue(first.ID == diagram.ID); } { // RefreshElements IEAPackage package = _e.GetDecisionPackage(); package.RefreshElements(); } { // AddElement / DeleteElement IEAPackage package = _e.GetDecisionPackage(); IEAElement element = package.AddElement("MyNote", "Note"); Assert.IsNotNull(element); package.RefreshElements(); Assert.IsTrue("MyNote" == element.Name); Assert.IsTrue("" == element.Stereotype); Assert.IsTrue("Note" == element.Type); Assert.IsTrue(deleteElementFromPackage(package, element)); } { // GetAllElementsOfSubTree IEAPackage package = _e.GetDecisionPackage(); IEnumerable <IEAElement> elements = package.GetAllElementsOfSubTree(); Assert.IsNotNull(elements); Assert.IsTrue(elements.Any()); } { // GetAllDecisions IEAPackage package = _e.GetDecisionPackage(); IEnumerable <IEAElement> actions = package.GetAllDecisions(); Assert.IsNotNull(actions); Assert.IsTrue(actions.Any()); } { // GetAllTopics IEAPackage package = _e.GetDecisionPackage(); IEnumerable <IEAElement> elements = package.GetAllTopics(); Assert.IsNotNull(elements); Assert.IsTrue(elements.Any()); } { // GetSubpackageByName IEAPackage package = _e.GetDecisionPackage(); IEAPackage subPackage = package.GetSubpackageByName("High-level Decisions"); Assert.IsNotNull(subPackage); } { // GetDiagrams IEAPackage folder = _e.GetDecisionPackageFolder(); IEnumerable <IEADiagram> diagrams = folder.GetDiagrams(); Assert.IsNotNull(diagrams); Assert.IsTrue(diagrams.Any()); } }