-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
88 lines (65 loc) · 2.93 KB
/
Program.cs
File metadata and controls
88 lines (65 loc) · 2.93 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
using ElectronNET.API;
using ElectronNET.API.Entities;
using EventulaEntranceClient.Services;
using EventulaEntranceClient.Services.Interfaces;
using System.Net;
var builder = WebApplication.CreateBuilder(args);
builder.WebHost.UseElectron(args); // add this line here
// Add services to the container.
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();
builder.Services.AddElectron();
// Webcam pictures need to be transferred via SignalR and they need a bigger message size
builder.Services.AddSignalR(e => { e.MaximumReceiveMessageSize = 102400000; });
builder.Services.AddSingleton<CookieContainer>();
builder.Services.AddSingleton<BackgroundTrigger>();
builder.Services.AddSingleton<UiNotifyService>();
builder.Services.AddSingleton<IDataStore, LiteDbDataStore>();
builder.Services.AddSingleton<IBarcodeService, ZXingBarcodeService>();
builder.Services.AddScoped<SettingsService>();
builder.Services.AddScoped<EventulaApiService>();
builder.Services.AddScoped<ProtectionService>();
builder.Services.AddHttpClient(nameof(EventulaApiService), (serviceProvider, client) =>
{
using var scope = serviceProvider.CreateScope();
var settingsService = scope.ServiceProvider.GetService<SettingsService>();
client.BaseAddress = new Uri(settingsService.RetrieveEventulaApiBaseAddress());
}).ConfigurePrimaryHttpMessageHandler(sp =>
{
var cookieContainer = sp.GetRequiredService<CookieContainer>();
return new HttpClientHandler { CookieContainer = cookieContainer };
});
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.MapPost("/adduserbyticket", async (http) =>
{
using var reader = new StreamReader(http.Request.Body);
var body = await reader.ReadToEndAsync();
// Get ticket
var eventulaApiService = http.RequestServices.GetService<EventulaApiService>();
var ticket = await eventulaApiService.RequestTicket(body).ConfigureAwait(false);
// Store participant
var dataStore = http.RequestServices.GetService<IDataStore>();
dataStore.AddOrUpdate(ticket.Participant);
// Notify UI
var uiNotifyService = http.RequestServices.GetService<UiNotifyService>();
uiNotifyService.NotifyUi(ticket.Participant);
http.Response.StatusCode = 200;
});
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.MapBlazorHub();
app.MapFallbackToPage("/_Host");
await app.StartAsync();
if (HybridSupport.IsElectronActive)
{
var window = await Electron.WindowManager.CreateWindowAsync(new BrowserWindowOptions { AutoHideMenuBar = true, Fullscreen = true }).ConfigureAwait(false);
window.OnClosed += () => Electron.App.Exit();
}
await app.WaitForShutdownAsync().ConfigureAwait(false);