-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRevigoWebService.cs
91 lines (75 loc) · 2.15 KB
/
RevigoWebService.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#if WINDOWS_SERVICE
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Rewrite;
using System.ServiceProcess;
namespace IRB.RevigoWeb
{
public class RevigoWebService : ServiceBase
{
private WebApplicationBuilder oBuilder;
private WebApplication oWebApplication;
public RevigoWebService()
{
if (OperatingSystem.IsWindows())
{
this.ServiceName = "Revigo Web Service";
this.CanHandlePowerEvent = false;
this.CanShutdown = false;
this.CanStop = true;
this.CanPauseAndContinue = false;
}
// not really needed, but for nullable sake
oBuilder = WebApplication.CreateBuilder();
oWebApplication = WebApplication.Create();
}
protected override void OnStart(string[] args)
{
oBuilder = WebApplication.CreateBuilder(args);
oBuilder.Services.Configure<FormOptions>(options =>
{
options.KeyLengthLimit = 16384;
options.ValueCountLimit = 8192;
options.ValueLengthLimit = 8388608;
});
// Add services to the container.
oBuilder.Services.AddRazorPages();
oWebApplication = oBuilder.Build();
var options = new RewriteOptions();
options.Rules.Add(new RewriteAspxUrl());
oWebApplication.UseRewriter(options);
// Configure the HTTP request pipeline.
if (!oWebApplication.Environment.IsDevelopment())
{
oWebApplication.UseExceptionHandler("/Error");
}
else
{
//app.UseExceptionHandler("/Error");
oWebApplication.UseDeveloperExceptionPage();
}
oWebApplication.UseStatusCodePagesWithReExecute("/ErrorCode", "?StatusCode={0}");
oWebApplication.UseStaticFiles();
//app.UseCookiePolicy();
oWebApplication.UseRouting();
//app.UseAuthorization();
oWebApplication.MapRazorPages();
oWebApplication.Lifetime.ApplicationStarted.Register(OnStarted);
oWebApplication.Lifetime.ApplicationStopped.Register(OnStopped);
oWebApplication.RunAsync();
}
private void OnStarted()
{
Global.StartApplication(oWebApplication.Configuration);
}
private void OnStopped()
{
Global.StopApplication();
}
protected override void OnStop()
{
Task oTask = oWebApplication.StopAsync(TimeSpan.FromMinutes(1.0));
oTask.Wait();
}
}
}
#endif