Beispiel #1
0
        //-------------------------------------------------------------------------

        private void PopulateEntityList <T>(ListBox list,
                                            Entity dependant = null) where T : Entity
        {
            try
            {
                list.Items.Clear();

                ReadOnlyDictionary <int, T> entities;
                ActiveRoadmap.GetEntities(out entities);

                foreach (T entity in entities.Values)
                {
                    if (dependant == null ||
                        dependant.GetIsDependantOn(entity))
                    {
                        list.Items.Add(entity);
                    }
                }
            }
            catch (Exception ex)
            {
                Program.HandleException(ex);
            }
        }
Beispiel #2
0
        //-------------------------------------------------------------------------

        private void UpdateDiagram()
        {
            try
            {
                // Get graphviz bin path from settings.
                string graphvizBinPath =
                    (string)Properties.Settings.Default["graphvizBinPath"];

                if (graphvizBinPath == null ||
                    Directory.Exists(graphvizBinPath) == false)
                {
                    MessageBox.Show(
                        "GraphViz bin path not found.",
                        "GraphViz",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                    return;
                }

                // Create new diagram.
                GraphVizDiagram diagram =
                    new GraphVizDiagram(
                        graphvizBinPath,
                        "Diagrams" + Path.DirectorySeparatorChar + "DiagramTemplate.gv");

                // Get all the roadmap's entities.
                Dictionary <int, Entity> entities;
                ActiveRoadmap.GetEntities(out entities);

                // Update each entity's metrics and calculate totals so we can calc percentages later.
                double largestValuePoints    = 0.0;
                double largestEffortPoints   = 0.0;
                double largestPriorityPoints = 0.0;

                foreach (Entity entity in entities.Values)
                {
                    entity.Metrics.Calculate();

                    largestValuePoints    = Math.Max(largestValuePoints, entity.Metrics.DependantsValuePointsTotal);
                    largestEffortPoints   = Math.Max(largestEffortPoints, entity.Metrics.DependantsEffortPointsTotal);
                    largestPriorityPoints = Math.Max(largestPriorityPoints, entity.Metrics.DependantsPriorityPointsTotal);
                }

                // Add each entity to the diagram.
                foreach (Entity entity in entities.Values)
                {
                    // Determine node colour & shape based on entity type.
                    Color colour = Color.Gray;
                    GraphVizDiagram.Node.NodeShape shape = GraphVizDiagram.Node.NodeShape.PENTAGON;

                    if (entity is GoalEntity)
                    {
                        colour = Color.LightGreen;
                        shape  = GraphVizDiagram.Node.NodeShape.BOX;
                    }
                    else if (entity is StrategyEntity)
                    {
                        colour = Color.LightBlue;
                        shape  = GraphVizDiagram.Node.NodeShape.ELLIPSE;
                    }
                    else if (entity is RealisationEntity)
                    {
                        colour = Color.Bisque;
                        shape  = GraphVizDiagram.Node.NodeShape.OCTAGON;
                    }

                    // Build format string based on what we want to show.
                    string format = "<B>{0}</B>";

                    if (uiDiagramShowMetrics.Checked)
                    {
                        format += "<BR/><B>V:</B>{1} <B>E:</B>{2} <B>P:</B>{3} <B>D:</B>{4}";
                    }

                    // Build entity text.
                    string entityTitle =
                        string.Format(
                            format + ' ', // Trailing space prevents text being partially clipped.
                            HttpUtility.HtmlEncode(entity.Title),
                            (int)(entity.Metrics.DependantsValuePointsTotal / largestValuePoints * 100),
                            (int)(entity.Metrics.DependantsEffortPointsTotal / largestEffortPoints * 100),
                            (int)(entity.Metrics.DependantsPriorityPointsTotal / largestPriorityPoints * 100),
                            entity.Metrics.DependantCount);

                    string entityText = null;

                    if (uiDiagramShowDescriptions.Checked &&
                        entity.Description.Length > 0)
                    {
                        entityText +=
                            "<BR/>" +
                            HttpUtility.HtmlEncode(
                                entity.Description).Replace(
                                Environment.NewLine, "<BR ALIGN='LEFT' />") +
                            "<BR ALIGN='LEFT' />";
                    }

                    // Add a node for the entity.
                    diagram.AddNode(
                        entity.Id,
                        entityTitle,
                        entityText,
                        40,
                        colour,
                        shape);

                    // Add links for each of this entity's dependencies.
                    ReadOnlyCollection <Entity> dependencies;
                    entity.GetDependencies(out dependencies);

                    foreach (Entity dependency in dependencies)
                    {
                        diagram.AddLinkToNode(entity.Id, dependency.Id);
                    }
                }

                // Create the actual diagram file.
                string diagramFilename = diagram.CreateDiagram();

                if (diagramFilename != null)
                {
                    uiDiagram.Image = new Bitmap(diagramFilename);
                }
            }
            catch (Exception ex)
            {
                Program.HandleException(ex);
            }
        }