-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
82 lines (72 loc) · 2.89 KB
/
Program.cs
File metadata and controls
82 lines (72 loc) · 2.89 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
namespace ptr727.LanguageTags.Create;
internal sealed class Program(
CommandLine.Options commandLineOptions,
CancellationToken cancellationToken
)
{
private const string DataDirectory = "LanguageData";
private const string CodeDirectory = "LanguageTags";
internal static async Task<int> Main(string[] args)
{
try
{
// Parse commandline
CommandLine commandLine = new(args);
commandLine.Result.InvocationConfiguration.EnableDefaultExceptionHandler = false;
commandLine.Result.InvocationConfiguration.ProcessTerminationTimeout = null;
// Bypass startup for errors or help and version commands
if (CommandLine.BypassStartup(commandLine.Result))
{
return await commandLine.Result.InvokeAsync().ConfigureAwait(false);
}
// Create logger
Log.Logger = LoggerFactory.Create(
commandLine.CreateOptions(commandLine.Result).LogOptions
);
LogOptions.SetFactory(LoggerFactory.CreateLoggerFactory());
// Invoke command
Log.Logger.LogOverrideContext().Information("Starting: {Args}", args);
return await commandLine.Result.InvokeAsync().ConfigureAwait(false);
}
catch (Exception ex) when (Log.Logger.LogAndHandle(ex))
{
return 1;
}
finally
{
await Log.CloseAndFlushAsync().ConfigureAwait(false);
}
}
internal async Task<int> ExecuteAsync()
{
try
{
// Data and code directories
string solutionDirectory = Path.GetFullPath(commandLineOptions.CodePath.FullName);
string dataDirectory = Path.Combine(solutionDirectory, DataDirectory);
string codeDirectory = Path.Combine(solutionDirectory, CodeDirectory);
if (!Directory.Exists(dataDirectory))
{
Log.Error("Data directory does not exist: {DataDirectory}", dataDirectory);
return 1;
}
if (!Directory.Exists(codeDirectory))
{
Log.Error("Code directory does not exist: {CodeDirectory}", codeDirectory);
return 1;
}
// Download data files
CreateTagData createTagData = new(dataDirectory, codeDirectory, cancellationToken);
await createTagData.DownloadDataAsync().ConfigureAwait(false);
// Convert data files to JSON
await createTagData.CreateJsonDataAsync().ConfigureAwait(false);
// Generate code files
await createTagData.GenerateCodeAsync().ConfigureAwait(false);
return 0;
}
catch (Exception ex) when (Log.Logger.LogAndHandle(ex))
{
return 1;
}
}
}