forked from fgalagorri/MultiCommandConsole
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
84 lines (74 loc) · 2.68 KB
/
Program.cs
File metadata and controls
84 lines (74 loc) · 2.68 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
using System;
using System.Diagnostics;
using System.Threading;
using Common.Logging;
using MultiCommandConsole.Services;
using MultiCommandConsole.Util;
using ObjectPrinter;
namespace MultiCommandConsole.Example
{
class Program
{
private static IConsoleWriter _writer;
private static ILog _logger;
static void Main(string[] args)
{
if (Array.Exists(args, s => s == "/debug") && Environment.UserInteractive)
{
Debugger.Break();
}
AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;
LogManager.Adapter = Log4NetFactoryAdapter.Load();
_logger = LogManager.GetLogger(typeof (Program));
_logger.InfoFormat("Logging configured");
Services.Config.EnableServiceMode();
_writer = ConsoleWriter.Get<Program>();
Config.ConsoleMode.Enabled = true;
Config.ConsoleMode.CommandPromptText = "console";
Config.ConsoleMode.HistorySize = 5;
Config.ConsoleMode.AppName = "example_console";
Config.ConsoleMode.OnBeginRunCommand += cmd => _writer.WriteLine(cmd.Dump());
Config.ShowViewArgsCommand = true;
Config.WriteRunTimeToConsole = true;
//Config.DefaultCommand = typeof (RepeatConsoleCommand);
Config.Help.GetCategoryDelegate = (name, type) =>
{
if (name.EndsWith("-service"))
{
return " - service -";
}
if (type.Assembly == typeof (Program).Assembly)
{
return " - example -";
}
return "";
};
Config.Help.GetAddlHelpDelegate = (s, type) => new[] { type.FullName };
Services.Config.Defaults.CommandLine = "ping /s=google.com /i=10";
try
{
new Engine(new[]
{
typeof(Program).Assembly,
typeof(InstallServiceCommand).Assembly
}).Run(args);
}
catch (Exception e)
{
_writer.WriteLine(e.Dump());
}
}
private static void CurrentDomainOnUnhandledException(object sender, UnhandledExceptionEventArgs unhandledExceptionEventArgs)
{
try
{
_writer.WriteErrorLine(unhandledExceptionEventArgs.ExceptionObject.Dump());
}
catch (Exception e)
{
_logger.Fatal(unhandledExceptionEventArgs.ExceptionObject.Dump());
}
((Stoplight)Config.ResolveTypeDelegate(typeof(Stoplight))).Stop();
}
}
}