-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
49 lines (45 loc) · 2.09 KB
/
Copy pathProgram.cs
File metadata and controls
49 lines (45 loc) · 2.09 KB
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
using System;
using System.Diagnostics;
using System.IO;
namespace FluentApi.Graph
{
class Program
{
// Для решения этой задачи установленный graphviz не нужен.
// Однако этот Main демонстрирует ради чего всё это делается.
// Чтобы этот проект заработал, установите себе graphviz.
// Инструкции есть на сайте https://www.graphviz.org/download/
// Укажите путь до исполняемого файла dot в константе ниже:
private const string PathToGraphviz = @"C:\Program Files\Graphviz\bin\dot.exe";
static void Main(string[] args)
{
var dot =
DotGraphBuilder.DirectedGraph("CommentParser")
.AddNode("START").With(a => a.Shape(NodeShape.Ellipse).Color("green"))
.AddNode("comment").With(a => a.Shape(NodeShape.Box))
.AddEdge("START", "slash").With(a => a.Label("'/'"))
.AddEdge("slash", "comment").With(a => a.Label("'/'"))
.AddEdge("comment", "comment").With(a => a.Label("other chars"))
.AddEdge("comment", "START").With(a => a.Label("'\\\\n'"))
.Build();
Console.WriteLine(dot);
ShowRenderedGraph(dot);
}
private static void ShowRenderedGraph(string dot)
{
File.WriteAllText("comment.dot", dot);
var processStartInfo = new ProcessStartInfo(PathToGraphviz)
{
UseShellExecute = false,
Arguments = "comment.dot -Tpng -o comment.png",
RedirectStandardError = true,
RedirectStandardOutput = true,
};
var p = Process.Start(processStartInfo);
p.WaitForExit();
Console.WriteLine(p.StandardError.ReadToEnd());
Console.WriteLine("Result is saved to comment.png");
Process.Start("comment.png");
}
}
}