-
Notifications
You must be signed in to change notification settings - Fork 0
/
GraphvizDotOutput.cs
76 lines (65 loc) · 2.78 KB
/
GraphvizDotOutput.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace ItDepends
{
using ItDepends.Library;
public class GraphvizDotOutput
{
private void InitReference(StringBuilder output, List<string> existingNodes, string nodeName, string label, string shape)
{
if (!existingNodes.Contains(nodeName))
{
output.AppendLine($"{nodeName} [label=\"{label}\", shape={shape}]");
existingNodes.Add(nodeName);
}
}
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());
}
}
}