-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
154 lines (119 loc) · 4.95 KB
/
Copy pathProgram.cs
File metadata and controls
154 lines (119 loc) · 4.95 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
static private readonly CancellationTokenSource _ctsWritingPolling = new();
static private string userName = "";
static private string room = "";
static private string passwd = "";
static private IUserInterface ui = new UI();
static private IAudioService audio = new Audio();
static private IParsing parsers = new Parsers(audio, ui);
static private ITransportConnection? conn;
static private IRouter? router;
Console.OutputEncoding = System.Text.Encoding.UTF8;
Console.InputEncoding = System.Text.Encoding.UTF8;
Console.Title = "Eureka.lol";
RootCommand rootCommand = new("Eureka.lol - skinny courtroom client");
rootCommand.Options.Add(serverOption);
rootCommand.Options.Add(nameOption);
rootCommand.Options.Add(roomOption);
rootCommand.Options.Add(pwdOption);
ParseResult parseResult = rootCommand.Parse(args);
if (parseResult.Errors.Count > 0)
{
foreach (ParseError parseError in parseResult.Errors)
{
Console.Error.WriteLine(parseError.Message);
}
Shutdown(ExitCode.ArgumentError);
}
var host = parseResult.GetValue(serverOption);
if (!string.IsNullOrEmpty(host))
{
Constants.API_BASE = host;
}
if (!NetworkInterface.GetIsNetworkAvailable() || !await parsers.CheckConnection(Constants.API_BASE))
{
Console.Out.WriteLine("You don't have internet access, or the server is unavailable.");
Shutdown(ExitCode.NetworkError);
}
var (updateMessage, updateImportant) = await Parsers.CheckUpdate();
if (!string.IsNullOrEmpty(updateMessage))
{
await Console.Out.WriteAsync(updateMessage);
if (updateImportant)
{
await Console.Out.WriteLineAsync("This is required update.");
return (int)ExitCode.UpdateRequired;
}
}
userName = await ReadFromUser(parseResult.GetValue(nameOption) ?? "", ["Enter name you want to enter with: ", "Incorrect name, please try again."]);
(room, RoomData checkRoom) = await parsers.RoomCheck(parseResult.GetValue(roomOption) ?? "");
if (checkRoom == null)
{
await Console.Out.WriteLineAsync("An error accured while checking room.");
Shutdown(ExitCode.UnexpectedError);
}
#pragma warning disable CS8602 // checkRoom won't be null in any way.
if (checkRoom.PasswordRequired)
{
await Console.Out.WriteLineAsync("The courtroom is password-protected.");
passwd = await ReadFromUser(parseResult.GetValue(pwdOption) ?? "", ["Enter the password: ", "Incorrect password, please try again."]);
}
#pragma warning restore CS8602
conn = new Connection($"{Constants.API_BASE}{Constants.SOCKET_API}", room, userName, passwd);
router = new Router(conn, ui, parsers);
router.SubscribeToMain();
var status = await conn.Connect();
if (status != ConnectionStatus.OK)
{
Console.Out.WriteLine($"There was an error with the connection. Error: {status}");
Shutdown((status == ConnectionStatus.NetworkError) ? ExitCode.NetworkError : ExitCode.UnexpectedError);
}
Console.Title = $"Eureka.lol - {room}";
await ui.CreateUI();
await ui.WritePolling(_ctsWritingPolling.Token);
*/
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging.Console;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Hosting;
using System.Text.Json.Serialization;
using System.Text.Json;
using DotMake.CommandLine;
using System.Reflection;
using EurekaClient;
using System.CommandLine;
var builder = Host.CreateApplicationBuilder(args);
Cli.Ext.ConfigureServices(services =>
{
services.AddLogging(logging =>
logging.AddSimpleConsole(options =>
{
options.TimestampFormat = "[yyyy-MM-dd HH:mm:ss] ";
options.UseUtcTimestamp = true;
options.SingleLine = true;
options.ColorBehavior = LoggerColorBehavior.Enabled;
})
);
services.AddSingleton<JsonSerializerOptions>(_ => new()
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
WriteIndented = true,
ReferenceHandler = ReferenceHandler.IgnoreCycles,
TypeInfoResolver = EurekaJsonContext.Default
});
services.AddHttpClient();
}
);
/*.AddSingleton(provider =>
{
var client = new HttpClient()
{
BaseAddress = new Uri("https://spdx.org/licenses/"),
Timeout = TimeSpan.FromSeconds(30)
};
var version = Assembly.GetExecutingAssembly().GetName().Version?.ToString(3);
client.DefaultRequestHeaders.Add("User-Agent", $"Licensify/{version ?? "0.0.0"}");
return client;
})); */
using var host = builder.Build();
return await Cli.RunAsync<RootCommand>();