forked from reactiveui/ReactiveUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
166 lines (135 loc) · 5.78 KB
/
Program.cs
File metadata and controls
166 lines (135 loc) · 5.78 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
using EventBuilder.Cecil;
using EventBuilder.Platforms;
using Mono.Cecil;
using Nustache.Core;
using Serilog;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using Parser = CommandLine.Parser;
namespace EventBuilder
{
internal class Program
{
/// <summary>
/// The exit/return code (aka %ERRORLEVEL%) on application exit.
/// </summary>
public enum ExitCode
{
Success = 0,
Error = 1
}
private static string _mustacheTemplate = "DefaultTemplate.mustache";
private static void Main(string[] args)
{
Log.Logger = new LoggerConfiguration()
.ReadFrom.AppSettings()
.CreateLogger();
var options = new CommandLineOptions();
// allow app to be debugged in visual studio.
if (Debugger.IsAttached)
{
//args = "--help ".Split(' ');
args = "--platform=ios".Split(' ');
//args = new[]
//{
// "--platform=none",
// @"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Xamarin.iOS\v1.0\Xamarin.iOS.dll"
//};
}
// Parse in 'strict mode'; i.e. success or quit
if (Parser.Default.ParseArgumentsStrict(args, options))
{
try
{
if (!string.IsNullOrWhiteSpace(options.Template))
{
_mustacheTemplate = options.Template;
Log.Debug("Using {template} instead of the default template.", _mustacheTemplate);
}
IPlatform platform = null;
switch (options.Platform)
{
case AutoPlatform.None:
if (!options.Assemblies.Any())
{
throw new Exception("Assemblies to be used for manual generation were not specified.");
}
platform = new Bespoke();
platform.Assemblies = options.Assemblies;
if (PlatformHelper.IsRunningOnMono())
{
platform.CecilSearchDirectories =
platform.Assemblies.Select(x => Path.GetDirectoryName(x)).Distinct().ToList();
}
else
{
platform.CecilSearchDirectories.Add(@"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5");
}
break;
case AutoPlatform.Android:
platform = new Android();
break;
case AutoPlatform.iOS:
platform = new iOS();
break;
case AutoPlatform.Mac:
platform = new Mac();
break;
case AutoPlatform.NET45:
platform = new Net45();
break;
case AutoPlatform.XamForms:
platform = new XamForms();
break;
case AutoPlatform.UWP:
platform = new UWP();
break;
case AutoPlatform.WP81:
platform = new WP81();
break;
case AutoPlatform.WPA81:
platform = new WPA81();
break;
default:
throw new ArgumentOutOfRangeException();
}
ExtractEventsFromAssemblies(platform);
Environment.Exit((int) ExitCode.Success);
}
catch (Exception ex)
{
Log.Fatal(ex.ToString());
}
}
Environment.Exit((int) ExitCode.Error);
}
public static void ExtractEventsFromAssemblies(IPlatform platform)
{
Log.Debug("Extracting events from the following assemblies: {assemblies}", platform.Assemblies);
Log.Debug("Using the following search directories: {assemblies}", platform.CecilSearchDirectories);
var targetAssemblyDirs = platform.CecilSearchDirectories;
var rp = new ReaderParameters
{
AssemblyResolver = new PathSearchAssemblyResolver(targetAssemblyDirs.ToArray())
};
var targetAssemblies = platform.Assemblies.Select(x => AssemblyDefinition.ReadAssembly(x, rp)).ToArray();
Log.Debug("Using {template} as the mustache template", _mustacheTemplate);
var template = File.ReadAllText(_mustacheTemplate, Encoding.UTF8);
var namespaceData = EventTemplateInformation.Create(targetAssemblies);
var delegateData = DelegateTemplateInformation.Create(targetAssemblies);
var result = Render.StringToString(template,
new {Namespaces = namespaceData, DelegateNamespaces = delegateData})
.Replace("System.String", "string")
.Replace("System.Object", "object")
.Replace("<", "<")
.Replace(">", ">")
.Replace("`1", "")
.Replace("`2", "")
.Replace("`3", "");
Console.WriteLine(result);
}
}
}