-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
100 lines (89 loc) · 3.82 KB
/
Program.cs
File metadata and controls
100 lines (89 loc) · 3.82 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
// <copyright file="Program.cs" company="SoluiNet">
// Copyright (c) SoluiNet. All rights reserved.
// </copyright>
namespace SoluiNet.DevTools.Console
{
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using CommandLine;
using NLog;
using SoluiNet.DevTools.Console.Options;
using SoluiNet.DevTools.Core.Application;
/// <summary>
/// The main entrance point for the SoluiNet.DevTools.Console application.
/// </summary>
internal class Program
{
/// <summary>
/// The main method which should be called when executing this application.
/// </summary>
/// <param name="args">The arguments.</param>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "All exceptions should be catched and written to log")]
public static void Main(string[] args)
{
try
{
#if DEBUG
Debugger.Launch();
#endif
ApplicationContext.Application = new ConsoleApplication();
(ApplicationContext.Application as BaseSoluiNetApp).Initialize();
CommandLine.Parser.Default.ParseArguments<RunOptions>(args)
.WithParsed(Run)
.WithNotParsed(Error);
}
catch (Exception exception)
{
var logger = LogManager.GetCurrentClassLogger();
logger.Error(string.Format(
CultureInfo.InvariantCulture,
"Error while executing SoluiNet.DevTools.Console - {0}",
exception.ToString()));
Console.WriteLine(string.Format(
CultureInfo.InvariantCulture,
"Error while executing SoluiNet.DevTools.Console - {0}",
exception.ToString()));
}
}
/// <summary>
/// Run with parsed options.
/// </summary>
/// <param name="options">The parsed options.</param>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Globalization", "CA1303:Do not pass literals as localized parameters", Justification = "We want to provide a neutral console tool. So there won't be any localizations for now.")]
internal static void Run(RunOptions options)
{
Console.WriteLine($@"SoluiNet.DevTools.Console v{Assembly.GetEntryAssembly()?.GetName().Version.ToString()}");
Console.WriteLine($@"Current Arguments: -v {options.Verbose} -h {options.Help}");
if (options.Help)
{
Console.WriteLine(@"You can use the following options:");
Console.WriteLine(@"v, verbose Use verbose output");
Console.WriteLine(@"h, help Open additional information about the usage of this application");
foreach (var plugin in (ApplicationContext.Application.Plugins as ConsoleApplication).CommandLinePlugins)
{
Console.WriteLine(plugin.HelpText);
}
}
}
/// <summary>
/// Couldn't identify the options.
/// </summary>
/// <param name="errors">A enumerable which holds the errors.</param>
internal static void Error(IEnumerable<Error> errors)
{
var logger = LogManager.GetCurrentClassLogger();
foreach (var error in errors)
{
logger.Error(string.Format(
CultureInfo.InvariantCulture,
"Error while executing SoluiNet.DevTools.Console - Run - {0} (stops processing: {1})",
error.Tag.ToString(),
error.StopsProcessing));
}
}
}
}