Пример #1
0
        public void Write(string file, Solution solution)
        {
            var output = new StringBuilder();

            output.AppendLine("<graphviz dot>");
            output.AppendLine("digraph sample {");

            var existingNodes = new List <string>();

            foreach (var project in solution.Projects)
            {
                var normalizedProjectName = NodeFilter.NormalizeReference(project.ProjectName);
                InitReference(output, existingNodes, normalizedProjectName, Path.GetFileName(project.ProjectName), "box");

                foreach (var reference in project.BinaryReferences.Where(NodeFilter.BinaryParticipateInGraph))
                {
                    var normalizedReference = NodeFilter.NormalizeReference(reference);
                    InitReference(output, existingNodes, normalizedReference, reference, "box");
                }

                foreach (var reference in project.ProjectReferences)
                {
                    var normalizedReference = NodeFilter.NormalizeReference(reference);
                    InitReference(output, existingNodes, normalizedReference, Path.GetFileNameWithoutExtension(reference), "box");
                }

                foreach (var reference in project.PackageReferences.Where(NodeFilter.PackageParticipateInGraph))
                {
                    var normalizedReference = NodeFilter.NormalizeReference(reference);
                    InitReference(output, existingNodes, normalizedReference, reference, "ellipse");
                }
            }

            foreach (var project in solution.Projects)
            {
                foreach (var reference in project.BinaryReferences.Where(NodeFilter.BinaryParticipateInGraph))
                {
                    output.AppendLine($"{NodeFilter.NormalizeReference(project.ProjectName)} -> {NodeFilter.NormalizeReference(reference)} [color=red]");
                }

                foreach (var reference in project.ProjectReferences)
                {
                    output.AppendLine($"{NodeFilter.NormalizeReference(project.ProjectName)} -> {NodeFilter.NormalizeReference(reference)} [color=black]");
                }

                foreach (var reference in project.PackageReferences.Where(NodeFilter.PackageParticipateInGraph))
                {
                    output.AppendLine($"{NodeFilter.NormalizeReference(project.ProjectName)} -> {NodeFilter.NormalizeReference(reference)} [color=blue]");
                }
            }

            output.AppendLine("}");
            output.AppendLine("</graphviz>");
            File.WriteAllText(file, output.ToString());
        }
Пример #2
0
        private void LoadSolution(string solutionFile)
        {
            var solution = Solution.Parser(solutionFile);
            var graph    = new Graph("Dependencies");

            foreach (var project in solution.Projects)
            {
                var projectNode = graph.AddNode(NodeFilter.NormalizeReference(project.ProjectName));
                if ((project.TargetFrameworks != null) &&
                    project.TargetFrameworks.Any(x => x.StartsWith("netcore")))
                {
                    projectNode.Attr.FillColor = Color.PaleGreen;
                }

                foreach (var reference in project.BinaryReferences.Where(NodeFilter.BinaryParticipateInGraph))
                {
                    var targetNodeId = NodeFilter.NormalizeReference(reference);
                    var edge         = graph.AddEdge(projectNode.Id, targetNodeId);
                    var targetNode   = graph.FindNode(targetNodeId);
                    targetNode.Attr.FillColor = Microsoft.Msagl.Drawing.Color.LightYellow;
                    targetNode.Attr.Shape     = Shape.Trapezium;
                }

                foreach (var reference in project.ProjectReferences)
                {
                    var targetNodeId = NodeFilter.NormalizeReference(reference);
                    var edge         = graph.AddEdge(projectNode.Id, targetNodeId);
                }

                foreach (var reference in project.PackageReferences.Where(NodeFilter.PackageParticipateInGraph))
                {
                    var targetNodeId = NodeFilter.NormalizeReference(reference);
                    var edge         = graph.AddEdge(projectNode.Id, targetNodeId);
                    var targetNode   = graph.FindNode(targetNodeId);
                    targetNode.Attr.FillColor = Microsoft.Msagl.Drawing.Color.LightSkyBlue;
                    targetNode.Attr.Shape     = Shape.Trapezium;
                }
            }

            this.uxGraphViewer.CurrentLayoutMethod = LayoutMethod.MDS;
            this.uxGraphViewer.Graph = graph;
            //this.uxGraphViewer.CurrentLayoutMethod = LayoutMethod.Ranking;
            ////graph.LayoutAlgorithmSettings;
        }