-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeServiceEntryPoint.cs
More file actions
71 lines (63 loc) · 2.82 KB
/
Copy pathCodeServiceEntryPoint.cs
File metadata and controls
71 lines (63 loc) · 2.82 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
namespace SystemExplorer.CodeService;
internal static class CodeServiceEntryPoint
{
private const int SuccessExitCode = 0;
private const int FatalFailureExitCode = 1;
private const int InvalidArgumentsExitCode = 2;
private const int OwnerValidationFailureExitCode = 3;
private const int LocalTransportStartupFailureExitCode = 4;
private const int SessionStartupFailureExitCode = 5;
private const int RoslynRuntimeProvisioningFailureExitCode = 6;
private static async Task<int> Main(string[] args)
{
try
{
CodeServiceStartupOptionsParseResult parseResult = CodeServiceStartupOptions.TryParse(args);
if (!parseResult.IsSuccess)
{
Console.Error.WriteLine($"SystemExplorer.CodeService: {parseResult.ErrorMessage}");
return InvalidArgumentsExitCode;
}
CodeServiceHostCreationResult hostResult =
await CodeServiceHost.TryCreateAsync(parseResult.Options!).ConfigureAwait(false);
ReportDiagnosticStartupMetadata(hostResult);
if (!hostResult.IsSuccess)
{
Console.Error.WriteLine($"SystemExplorer.CodeService: {hostResult.ErrorMessage}");
return hostResult.FailureKind switch
{
CodeServiceHostCreationFailureKind.OwnerValidationFailure
=> OwnerValidationFailureExitCode,
CodeServiceHostCreationFailureKind.TransportStartupFailure
=> LocalTransportStartupFailureExitCode,
CodeServiceHostCreationFailureKind.SessionStartupFailure
=> SessionStartupFailureExitCode,
CodeServiceHostCreationFailureKind.RoslynRuntimeProvisioningFailure
=> RoslynRuntimeProvisioningFailureExitCode,
_ => FatalFailureExitCode,
};
}
await using CodeServiceHost host = hostResult.Host!;
await host.RunAsync().ConfigureAwait(false);
return SuccessExitCode;
}
catch (Exception exception)
{
Console.Error.WriteLine($"SystemExplorer.CodeService: fatal error: {exception.Message}");
return FatalFailureExitCode;
}
}
private static void ReportDiagnosticStartupMetadata(CodeServiceHostCreationResult hostResult)
{
if (hostResult.DiagnosticLogPath is not null)
{
Console.Error.WriteLine(
$"SystemExplorer.CodeService: diagnostic log: {hostResult.DiagnosticLogPath}");
}
else if (hostResult.DiagnosticLoggingWarning is not null)
{
Console.Error.WriteLine(
$"SystemExplorer.CodeService: warning: {hostResult.DiagnosticLoggingWarning}");
}
}
}