-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMicrodocum.cs
85 lines (71 loc) · 3.02 KB
/
Microdocum.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
77
78
79
80
81
82
83
84
85
using System;
using System.IO;
using System.Linq;
using MicroDocum.Analyzers.Analizers;
using MicroDocum.Graphviz;
using MicroDocum.Themes.DefaultTheme;
using Nuke.Common;
using Nuke.Common.BuildServers;
using Nuke.Common.Tooling;
//https://github.com/nuke-build/nuke
partial class Build : NukeBuild
{
Target Microdocum => _ => _
.DependsOn(CompileDotNet)
.Executes(() =>
{
Console.WriteLine("Run custom target - Microdocum!");
var pathDot = Path.Combine(MySolutionDirectory.ToString(), "DTO_routing.dot");
var pathPng = Path.Combine(MySolutionDirectory.ToString(), "DTO_routing.png");
var loadedAssemblies = LoadDtoAssemblies();
var theme = new DefaultTheme();
var a = new AssemblyAnalizer<DefaultLinkStyle>(theme);
//var asm = AppDomain.CurrentDomain.GetAssemblies();
//var c = a.Analize(asm, theme.GetAvailableThemeAttributes());
var assemblies = loadedAssemblies.Dto.Select(x => x.Assembly).ToArray();
var attributes = theme.GetAvailableThemeAttributes();
var c = a.Analize(assemblies, attributes);
if(c.Nodes.Count == 0 && c.Edges.Count == 0)
WriteError("Microdocum - DTO not found");
var gen = new GraphvizDotGenerator<DefaultLinkStyle>(new DefaultTheme());
var graphwizFileData = gen.Generate(c);
/*
For example, if you have the graphviz exe files (dot.exe, fdp.exe etc.) in a folder in C:\GraphViz
then your web.config or app.config should have the following:
<appSettings>
<add key="graphVizLocation" value="C:\GraphViz" />
</appSettings>
*/
//EnvironmentInfo.SetVariable("graphVizLocation","");
var graphizBin = "";
if (Host == HostType.Console)
{
var packagesDirectory = NuGetPackageResolver.GetPackagesDirectory(null);
var dir = Path.Combine(packagesDirectory, "graphviz");
dir = Path.Combine(dir, Directory.EnumerateDirectories(dir).First());
graphizBin = Path.Combine(dir, "dot.exe");
}
if (AppVeyor.Instance != null)
graphizBin = "dot";
if (Travis.Instance != null)
graphizBin = "dot";
using (var file = new StreamWriter(pathDot, false))
{
file.Write(graphwizFileData);
Console.WriteLine("saved to " + pathDot);
}
var process = ProcessTasks.StartProcess(
graphizBin,
arguments: $"-Tpng \"{pathDot}\" -o \"{pathPng}\""
);
if (process != null)
{
process.WaitForExit();
Console.WriteLine("graphiz exit code " + process.ExitCode);
}
else
{
WriteError($"Can`t start graphiz {graphizBin}");
}
});
}