diff options
Diffstat (limited to 'src/wixcop/Program.cs')
-rw-r--r-- | src/wixcop/Program.cs | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/src/wixcop/Program.cs b/src/wixcop/Program.cs new file mode 100644 index 00000000..b26bd6c9 --- /dev/null +++ b/src/wixcop/Program.cs | |||
@@ -0,0 +1,67 @@ | |||
1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. | ||
2 | |||
3 | namespace WixCop | ||
4 | { | ||
5 | using System; | ||
6 | using WixCop.CommandLine; | ||
7 | using WixCop.Interfaces; | ||
8 | using WixToolset.Core; | ||
9 | using WixToolset.Extensibility; | ||
10 | using WixToolset.Extensibility.Data; | ||
11 | using WixToolset.Extensibility.Services; | ||
12 | using WixToolset.Tools.Core; | ||
13 | |||
14 | /// <summary> | ||
15 | /// Wix source code style inspector and converter. | ||
16 | /// </summary> | ||
17 | public sealed class Program | ||
18 | { | ||
19 | /// <summary> | ||
20 | /// The main entry point for the application. | ||
21 | /// </summary> | ||
22 | /// <param name="args">The commandline arguments.</param> | ||
23 | /// <returns>The number of errors that were found.</returns> | ||
24 | [STAThread] | ||
25 | public static int Main(string[] args) | ||
26 | { | ||
27 | var serviceProvider = new WixToolsetServiceProvider(); | ||
28 | var listener = new ConsoleMessageListener("WXCP", "wixcop.exe"); | ||
29 | |||
30 | serviceProvider.AddService<IMessageListener>((x, y) => listener); | ||
31 | serviceProvider.AddService<IWixCopCommandLineParser>((x, y) => new WixCopCommandLineParser(x)); | ||
32 | |||
33 | var program = new Program(); | ||
34 | return program.Run(serviceProvider, args); | ||
35 | } | ||
36 | |||
37 | /// <summary> | ||
38 | /// Run the application with the given arguments. | ||
39 | /// </summary> | ||
40 | /// <param name="serviceProvider">Service provider to use throughout this execution.</param> | ||
41 | /// <param name="args">The commandline arguments.</param> | ||
42 | /// <returns>The number of errors that were found.</returns> | ||
43 | public int Run(IServiceProvider serviceProvider, string[] args) | ||
44 | { | ||
45 | try | ||
46 | { | ||
47 | var listener = serviceProvider.GetService<IMessageListener>(); | ||
48 | var messaging = serviceProvider.GetService<IMessaging>(); | ||
49 | messaging.SetListener(listener); | ||
50 | |||
51 | var arguments = serviceProvider.GetService<ICommandLineArguments>(); | ||
52 | arguments.Populate(args); | ||
53 | |||
54 | var commandLine = serviceProvider.GetService<IWixCopCommandLineParser>(); | ||
55 | commandLine.Arguments = arguments; | ||
56 | var command = commandLine.ParseWixCopCommandLine(); | ||
57 | return command?.Execute() ?? 1; | ||
58 | } | ||
59 | catch (Exception e) | ||
60 | { | ||
61 | Console.Error.WriteLine("wixcop.exe : fatal error WXCP0001 : {0}\r\n\n\nStack Trace:\r\n{1}", e.Message, e.StackTrace); | ||
62 | |||
63 | return 1; | ||
64 | } | ||
65 | } | ||
66 | } | ||
67 | } | ||