-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
90 lines (81 loc) · 2.16 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
87
88
89
90
namespace CSharpInteractive;
using Core;
/// <summary>
/// Class entry point to the application.
/// </summary>
public class Program
{
// ReSharper disable once UnusedMember.Global
/// <summary>
/// Method entry point to the application.
/// </summary>
/// <returns></returns>
public static int Main()
{
using (Composition.Shared)
{
return Composition.Shared.Root.Program.Run();
}
}
private readonly ILog<Program> _log;
private readonly IEnumerable<IActive> _activeObjects;
private readonly IInfo _info;
private readonly ISettings _settings;
private readonly IExitTracker _exitTracker;
private readonly Func<IScriptRunner> _runner;
private readonly IStatistics _statistics;
internal Program(
ILog<Program> log,
IEnumerable<IActive> activeObjects,
IInfo info,
ISettings settings,
IExitTracker exitTracker,
Func<IScriptRunner> runner,
IStatistics statistics)
{
_log = log;
_activeObjects = activeObjects;
_info = info;
_settings = settings;
_exitTracker = exitTracker;
_runner = runner;
_statistics = statistics;
}
// ReSharper disable once MemberCanBePrivate.Global
internal int Run()
{
if (_settings.ShowVersionAndExit)
{
_info.ShowVersion();
return 0;
}
_info.ShowHeader();
if (_settings.ShowHelpAndExit)
{
_info.ShowHelp();
return 0;
}
using var exitToken = _exitTracker.Track();
try
{
using (Disposable.Create(_activeObjects.Select(i => i.Activate()).ToArray()))
{
var result = _runner().Run();
if (_statistics.Items.Any(i => i.Type == StatisticsType.Error))
{
result = 1;
}
return result;
}
}
catch (Exception error)
{
_log.Error(ErrorId.Unhandled, error);
return 1;
}
finally
{
_info.ShowFooter();
}
}
}