-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
129 lines (103 loc) · 3.93 KB
/
Program.cs
File metadata and controls
129 lines (103 loc) · 3.93 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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.Reflection;
namespace HtmlDocGenerator; // Note: actual namespace depends on the project name.
internal class Program
{
const string PACKAGE_STORE_PATH = "packages\\";
static NugetManager _nuget;
static DocContext _context;
static void Main(string[] args)
{
Run(args);
#if DEBUG
Console.WriteLine("Press any key to exit...");
#endif
Console.ReadKey();
}
private static void Run(string[] args)
{
_context = DocContext.Load("Molten Engine Documentation", "config.xml");
if (_context == null)
return;
DocParser parser = new DocParser();
_nuget = new NugetManager(PACKAGE_STORE_PATH);
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
foreach (NugetDefinition nd in _context.Packages)
_nuget.LoadPackage(nd);
foreach (string def in _context.Definitions)
parser.LoadXml(_context, def);
string destPath = _context.DestinationPath;
if (!Path.IsPathFullyQualified(destPath))
destPath = Path.GetFullPath(destPath);
parser.Parse(_context, destPath);
JsonSerializerSettings settings = new JsonSerializerSettings()
{
NullValueHandling = NullValueHandling.Ignore,
#if DEBUG
Formatting = Formatting.Indented,
#else
Formatting = Formatting.None,
#endif
};
settings.Converters.Add(new StringEnumConverter());
string json = JsonConvert.SerializeObject(_context, settings);
json = $"var docData = {json};";
string jsPath = $"{destPath}js\\";
if (!Directory.Exists(jsPath))
Directory.CreateDirectory(jsPath);
using (FileStream stream = new FileStream($"{jsPath}data.js", FileMode.Create, FileAccess.Write))
{
using (StreamWriter writer = new StreamWriter(stream))
writer.Write(json);
}
// Copy source files to destination directory.
FileInfo[] srcFiles = _context.SourceDirectory.GetFiles("*.*", SearchOption.AllDirectories);
foreach(FileInfo srcInfo in srcFiles)
{
string relative = Path.GetRelativePath(_context.SourceDirectory.FullName, srcInfo.FullName);
FileInfo destInfo = new FileInfo($"{destPath}{relative}");
if (!destInfo.Directory.Exists)
destInfo.Directory.Create();
File.Copy(srcInfo.FullName, destInfo.FullName, true);
}
}
private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
string[] aParts = args.Name.Split(',');
string aName = aParts[0];
if (!_context.Assemblies.TryGetValue(aName, out DocAssembly da))
{
FileInfo requestingInfo = new FileInfo(args.RequestingAssembly.Location);
FileInfo assemblyInfo = new FileInfo($"{requestingInfo.Directory.FullName}\\{aName}.dll");
if (assemblyInfo.Exists)
{
da = new DocAssembly()
{
Name = aName,
FilePath = assemblyInfo.FullName,
Assembly = Assembly.LoadFile(assemblyInfo.FullName)
};
_context.Assemblies.Add(aName, da);
}
else
{
// Check nuget instead
if (_nuget.TryGetAssembly(aName, out Assembly nugetAssembly))
{
da = new DocAssembly()
{
Name = aName,
FilePath = nugetAssembly.Location,
Assembly = nugetAssembly
};
}
else
{
Console.WriteLine($"Error: Missing assembly '{args.Name}'");
}
}
}
return da?.Assembly;
}
}