-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
60 lines (54 loc) · 1.77 KB
/
Program.cs
File metadata and controls
60 lines (54 loc) · 1.77 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
using System;
using System.IO;
using EasySocket.Core.Networks.Client;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace EasySocket.Core.Client
{
class Program
{
static void Main(string[] args)
{
string addr = GetArgsStringValue(args, 0, "127.0.0.1");
int port = GetArgsNumberValue(args, 1, 12000);
IConfiguration config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.Build();
ServiceProvider serviceProvider = new ServiceCollection()
.AddSingleton(config)
.AddLogging(logger =>
{
logger.AddConsole();
logger.SetMinimumLevel(LogLevel.Debug);
})
.AddTransient<EasyClient>()
.AddTransient<Startup>()
.BuildServiceProvider();
serviceProvider.GetRequiredService<Startup>().Run(addr, port);
}
private static int GetArgsNumberValue(String[] args, int index, int defaultValue)
{
if (args.Length > index && int.TryParse(args[index], out int value))
{
return value;
}
else
{
return defaultValue;
}
}
private static string GetArgsStringValue(String[] args, int index, string defaultValue)
{
if (args.Length > index)
{
return args[index];
}
else
{
return defaultValue;
}
}
}
}