forked from pedropombeiro/FactoryGenerator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
86 lines (65 loc) · 2.55 KB
/
Program.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
86
namespace DeveloperInTheFlow.FactoryGenerator
{
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Threading.Tasks;
using Common.Logging;
using Microsoft.CodeAnalysis.MSBuild;
using NLog.Config;
internal class Program
{
#region Static Fields
private static readonly ILog Logger;
#endregion
#region Constructors and Destructors
static Program()
{
ConfigurationItemFactory.Default.RegisterItemsFromAssembly(Assembly.GetExecutingAssembly());
Logger = LogManager.GetLogger<Program>();
}
#endregion
#region Properties
internal static CommandLineOptions CommandLineOptions { get; private set; }
#endregion
#region Methods
private static async Task GenerateFactoriesAsync(string solutionPath,
IEnumerable<string> attributeImportList,
bool writeXmlDoc,
string templatePath)
{
var workspace = MSBuildWorkspace.Create();
var solution = await workspace.OpenSolutionAsync(solutionPath);
var factoryGenerator = new FactoryGenerator(workspace, solution, attributeImportList, writeXmlDoc, templatePath);
await factoryGenerator.ExecuteAsync();
}
private static void Main(string[] args)
{
CommandLineOptions = new CommandLineOptions();
if (!CommandLine.Parser.Default.ParseArguments(args, CommandLineOptions))
{
Environment.Exit(1);
}
try
{
GenerateFactoriesAsync(CommandLineOptions.SolutionPath,
CommandLineOptions.AttributeImportList.Split(new[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries),
CommandLineOptions.WriteXmlDoc,
CommandLineOptions.TemplatePath)
.Wait();
}
catch (AggregateException e)
{
var innerException = e.Flatten().InnerException;
Logger.Fatal(innerException.Message, e);
Environment.ExitCode = innerException.HResult;
}
finally
{
NLog.LogManager.Flush();
NLog.LogManager.Shutdown();
}
}
#endregion
}
}