-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModVerifyApplication.cs
More file actions
68 lines (62 loc) · 2.14 KB
/
ModVerifyApplication.cs
File metadata and controls
68 lines (62 loc) · 2.14 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
using AET.ModVerify.App.Settings;
using AnakinRaW.ApplicationBase;
using AnakinRaW.ApplicationBase.Utilities;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Serilog;
using System;
using System.Threading.Tasks;
using ILogger = Microsoft.Extensions.Logging.ILogger;
namespace AET.ModVerify.App;
internal sealed class ModVerifyApplication(AppSettingsBase settings, IServiceProvider services)
{
private readonly ILogger? _logger = services.GetService<ILoggerFactory>()?.CreateLogger(typeof(ModVerifyApplication));
public async Task<int> RunAsync()
{
using (new UnhandledExceptionHandler(services))
using (new UnobservedTaskExceptionHandler(services))
return await RunCoreAsync().ConfigureAwait(false);
}
private async Task<int> RunCoreAsync()
{
_logger?.LogDebug("Raw command line: {CommandLine}", Environment.CommandLine);
try
{
var action = CreateAppAction();
return await action.ExecuteAsync().ConfigureAwait(false);
}
catch (Exception e)
{
_logger?.LogCritical(e, e.Message);
ConsoleUtilities.WriteApplicationFatalError(ModVerifyConstants.AppNameString, e);
return e.HResult;
}
finally
{
#if NET
await Log.CloseAndFlushAsync();
#else
Log.CloseAndFlush();
#endif
if (settings is AppVerifySettings { IsInteractive: true })
{
Console.WriteLine();
ConsoleUtilities.WriteHorizontalLine('-');
Console.WriteLine("Press any key to exit");
Console.ReadLine();
}
}
}
private IModVerifyAppAction CreateAppAction()
{
switch (settings)
{
case AppVerifySettings verifySettings:
return new VerifyAction(verifySettings, services);
case AppBaselineSettings baselineSettings:
return new CreateBaselineAction(baselineSettings, services);
default:
throw new InvalidOperationException("Unknown settings");
}
}
}