- Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathProgram.cs
More file actions
Latest commit
94 lines (84 loc) · 3.42 KB
/
Copy pathProgram.cs
File metadata and controls
94 lines (84 loc) · 3.42 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
usingSystem;
usingSystem.Collections.Generic;
usingSystem.IO;
usingSystem.Linq;
usingSystem.Threading.Tasks;
usingMicrosoft.AspNetCore;
usingMicrosoft.AspNetCore.Hosting;
usingMicrosoft.Extensions.Configuration;
usingMicrosoft.Extensions.Logging;
usingSystem.Net;
usingSystem.Globalization;
usingMicrosoft.AspNetCore.Server.Kestrel.Https;
usingMicrosoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal;
usingMicrosoft.Extensions.DependencyInjection;
usingNewtonsoft.Json;
namespaceHashServer
{
publicclassProgram
{
publicstaticAppOptionsSettings;
publicstaticILoggerlog{get;set;}
publicIConfigurationRootConfiguration{get;set;}
publicvoidConfigureServices(IServiceCollectionservices)
{
services.AddOptions();
// Register the IConfiguration instance which MyOptions binds against.
services.Configure<AppOptions>(Configuration);
}
publicstaticTaskMain(string[]args)
{
TaskScheduler.UnobservedTaskException+=(sender,e)=>
{
Console.WriteLine("Unobserved exception: {0}",e.Exception);
};
varconfiguration=newConfigurationBuilder()
.AddEnvironmentVariables()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json",optional:false,reloadOnChange:true)
.Build();
Settings=configuration.GetSection("App").Get<AppOptions>();
Settings.ToString();
varbasePort=Settings.Host.BasePort;
varhost=newWebHostBuilder()
.ConfigureLogging((_,factory)=>
{
factory.ClearProviders();
factory.SetMinimumLevel(Enum.Parse<LogLevel>(Settings.Host.LogLevel));
factory.AddConsole();
})
.UseKestrel(options =>
{
// Run callbacks on the transport thread
options.ApplicationSchedulingMode=SchedulingMode.ThreadPool;
options.Listen(IPAddress.Any,basePort, listenOptions =>
{
// Uncomment the following to enable Nagle's algorithm for this endpoint.
listenOptions.NoDelay=false;
listenOptions.KestrelServerOptions.Limits.MaxConcurrentConnections=Settings.Host.MaxConcurrentConnections;
listenOptions.KestrelServerOptions.Limits.KeepAliveTimeout=TimeSpan.FromSeconds(1);
listenOptions.KestrelServerOptions.AllowSynchronousIO=true;
listenOptions.UseConnectionLogging();
});
options.Listen(IPAddress.Loopback,basePort+1, listenOptions =>
{
listenOptions.UseHttps(Settings.Host.CertificateFile,Settings.Host.CertificatePassword);
listenOptions.UseConnectionLogging();
});
})
.UseLibuv(options =>
{
#if DEBUG
options.ThreadCount=1;
#else
options.ThreadCount=Settings.Host.ThreadCount;
#endif
})
.UseContentRoot(Directory.GetCurrentDirectory())
.UseUrls(Settings.Internal.gRoot,Settings.InternalSSL.gRoot)
.UseStartup<Startup>()
.Build();
returnhost.RunAsync();
}
}
}