-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
44 lines (38 loc) · 1.56 KB
/
Copy pathProgram.cs
File metadata and controls
44 lines (38 loc) · 1.56 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
using Microsoft.EntityFrameworkCore;
using MediRemind.Data;
using MediRemind.Services;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRazorPages();
builder.Services.AddDbContext<AppDbContext>(o => o.UseSqlite("Data Source=mediremind.db"));
builder.Services.AddDistributedMemoryCache();
builder.Services.AddSession(o => {
o.IdleTimeout = TimeSpan.FromMinutes(60);
o.Cookie.HttpOnly = true;
o.Cookie.IsEssential = true;
});
builder.Services.AddHttpContextAccessor();
builder.Services.AddHostedService<PushNotificationService>();
var app = builder.Build();
using (var scope = app.Services.CreateScope())
{
var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
db.Database.EnsureCreated();
try { db.Database.ExecuteSqlRaw("ALTER TABLE Medications ADD COLUMN PillCount INTEGER NULL"); } catch { }
try { db.Database.ExecuteSqlRaw("ALTER TABLE Medications ADD COLUMN PillsPerDose INTEGER NULL"); } catch { }
try { db.Database.ExecuteSqlRaw("ALTER TABLE DoseLogs ADD COLUMN ConfirmedAt TEXT NULL"); } catch { }
try { db.Database.ExecuteSqlRaw(@"
CREATE TABLE IF NOT EXISTS PushSubscriptions (
Id INTEGER PRIMARY KEY AUTOINCREMENT,
UserId INTEGER NOT NULL,
Endpoint TEXT NOT NULL,
P256dh TEXT NOT NULL,
Auth TEXT NOT NULL
)"); } catch { }
}
if (!app.Environment.IsDevelopment()) { app.UseExceptionHandler("/Error"); app.UseHsts(); }
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseSession();
app.MapRazorPages();
app.Run();