-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGateway.cs
70 lines (59 loc) · 1.83 KB
/
Gateway.cs
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
using DSM.Core.Ops;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace DSM.GatewayEngine
{
public class Gateway : IDisposable
{
internal static LogManager _logManager = LogManager.GetManager("DSM.GatewayEngine");
private readonly IWebHost _server;
private static readonly IConfiguration _config = AppSettingsManager.GetConfiguration();
public Gateway()
{
int port = _config.GetValue<int>("Host:Port");
string localIpAddr = Core.Ops.Extensions.GetLocalIPAddress();
IList<string> hosts = new List<string>
{
$"http://localhost:{port}",
$"http://{localIpAddr}:{port}"
};
_logManager.Write($"Hosts -> {string.Join(", ", hosts)}");
_server = new WebHostBuilder()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseUrls(hosts.ToArray())
.UseStartup<Startup>()
.UseKestrel(options =>
{
options.AllowSynchronousIO = true;
})
.Build();
_server.Run();
XConsole.SetTitle("DSM Gateway");
_logManager.Write($"Gateway RUNNING UP!");
}
~Gateway()
{
Dispose(false);
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
if (_server != null)
{
_server.StopAsync();
_server.Dispose();
}
}
}
}
}