-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApplication.cs
57 lines (51 loc) · 1.52 KB
/
Application.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
using System.CommandLine;
using Marauder.Mini.Commands;
using Marauder.Mini.Models;
using Microsoft.Extensions.Logging;
namespace Marauder.Mini;
public class Application : RootCommand
{
private readonly EventId Cancel = new();
private readonly EventId Error = new();
private readonly EventId Finish = new();
private readonly CancellationTokenSource _tokenSource;
private readonly ILogger<Application> _logger;
public Application(
BuildCommand buildCommand,
RunCommand run,
TestCommand test,
CancellationTokenSource tokenSource,
ILogger<Application> logger) : base("Maurading and such")
{
_tokenSource = tokenSource;
_logger = logger;
AddCommand(buildCommand);
AddCommand(run);
AddCommand(test);
}
public async Task<int> RunAsync(string[] args)
{
try
{
await this.InvokeAsync(args);
_logger.LogTrace(Finish, "Finished");
return 0x00;
}
catch(ProcessModuleNotFoundException)
{
_logger.LogError(Error, "An unhandled exception was caught in the main thread");
return 0x01;
}
catch(Exception ex)
{
_logger.LogError(Error, ex, $"An unhandled exception was caught in the main thread: {ex.Message}");
return 0x01;
}
}
public async Task<int> CancelAsync()
{
_logger.LogTrace(Cancel, "Canceling");
await _tokenSource.CancelAsync();
return 0x01;
}
}