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();
        }
Пример #2
0
        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());
            }
        }
Пример #3
0
        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();
                }
            }
        }