-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
93 lines (76 loc) · 2.37 KB
/
Program.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
92
93
using Microsoft.AspNetCore.Rewrite;
using IRB.RevigoWeb;
using System.Reflection;
using Microsoft.AspNetCore.Http.Features;
#if WINDOWS_SERVICE
using System.ServiceProcess;
#endif
internal class Program
{
#if WORKER_SERVICE
// To do: Implement Worker Service
#elif WINDOWS_SERVICE
private static void Main()
{
if (OperatingSystem.IsWindows())
{
// ensure that CWD is the assembly path to be able to access contents and configuration files
string? path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
if (!string.IsNullOrEmpty(path))
Directory.SetCurrentDirectory(path);
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[] { new RevigoWebService() };
ServiceBase.Run(ServicesToRun);
}
}
#else
private static WebApplication? oWebApplication = null;
private static void Main(string[] args)
{
// ensure that CWD is the assembly path to be able to access contents and configuration files
string? path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
if (!string.IsNullOrEmpty(path))
Directory.SetCurrentDirectory(path);
var oBuilder = WebApplication.CreateBuilder(args);
oBuilder.Services.Configure<FormOptions>(options =>
{
options.KeyLengthLimit = 8192;
options.ValueCountLimit = 4096;
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.Run();
}
private static void OnStarted()
{
Global.StartApplication(oWebApplication?.Configuration);
}
private static void OnStopped()
{
Global.StopApplication();
}
#endif
}