- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
Latest commit
92 lines (82 loc) · 3.26 KB
/
Copy pathProgram.cs
File metadata and controls
92 lines (82 loc) · 3.26 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
85
86
87
88
89
90
91
92
namespaceptr727.LanguageTags.Create;
internalsealedclassProgram(
CommandLine.OptionscommandLineOptions,
CancellationTokencancellationToken
)
{
privateconststringDataDirectory="LanguageData";
privateconststringCodeDirectory="LanguageTags";
internalstaticasyncTask<int>Main(string[]args)
{
try
{
// Parse commandline
CommandLinecommandLine=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))
{
returnawaitcommandLine.Result.InvokeAsync().ConfigureAwait(false);
}
// Create logger
Log.Logger=LoggerFactory.Create(
commandLine.CreateOptions(commandLine.Result).LogOptions
);
ILoggerFactoryloggerFactory=LoggerFactory.CreateLoggerFactory();
LogOptions.SetFactory(loggerFactory);
Utilities.LogOptions.SetFactory(loggerFactory);
// Invoke command
Log.Logger.LogOverrideContext().Information("Starting: {Args}",args);
returnawaitcommandLine.Result.InvokeAsync().ConfigureAwait(false);
}
catch(Exceptionex)when(Log.Logger.LogAndHandle(ex))
{
return1;
}
finally
{
awaitLog.CloseAndFlushAsync().ConfigureAwait(false);
}
}
internalasyncTask<int>ExecuteAsync()
{
try
{
// Data and code directories
stringsolutionDirectory=Path.GetFullPath(commandLineOptions.CodePath.FullName);
stringdataDirectory=Path.Combine(solutionDirectory,DataDirectory);
stringcodeDirectory=Path.Combine(solutionDirectory,CodeDirectory);
if(!Directory.Exists(dataDirectory))
{
Log.Error("Data directory does not exist: {DataDirectory}",dataDirectory);
return1;
}
if(!Directory.Exists(codeDirectory))
{
Log.Error("Code directory does not exist: {CodeDirectory}",codeDirectory);
return1;
}
// Obtain the source data: download fresh from upstream, or, in offline mode, use the data
// already committed under LanguageData/ so codegen can be re-exercised with no network.
CreateTagDatacreateTagData=new(dataDirectory,codeDirectory,cancellationToken);
if(commandLineOptions.SkipDownload)
{
createTagData.UseExistingData();
}
else
{
awaitcreateTagData.DownloadDataAsync().ConfigureAwait(false);
}
// Convert data files to JSON
awaitcreateTagData.CreateJsonDataAsync().ConfigureAwait(false);
// Generate code files
awaitcreateTagData.GenerateCodeAsync().ConfigureAwait(false);
return0;
}
catch(Exceptionex)when(Log.Logger.LogAndHandle(ex))
{
return1;
}
}
}