Repositories now read and write indented, human-readable JSON
(System.Text.Json, shared settings in JsonStorage). File names and folders
are unchanged apart from the extension.
XmlToJsonMigrator runs at startup before the app serves requests. It converts
the known Data/*.xml files under every year/mandator, verifies the JSON reads
back to the same data, and moves the XML to
{year}/backup/{mandator}/xml-{timestamp}/. Bank-statement XMLs in uploads/ are
never touched. Any failure stops startup and leaves that file's XML in place.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
64 lines
2.3 KiB
C#
64 lines
2.3 KiB
C#
using System.Globalization;
|
|
using Microsoft.AspNetCore.Localization;
|
|
using Microsoft.Extensions.Options;
|
|
using Microsoft.FluentUI.AspNetCore.Components;
|
|
using Schaad.Accounting.Repositories;
|
|
using Schaad.Accounting.Datasets;
|
|
using Schaad.Accounting.UI.Components;
|
|
|
|
namespace Schaad.Accounting.UI
|
|
{
|
|
public class Program
|
|
{
|
|
public static async Task Main(string[] args)
|
|
{
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
// Add services to the container.
|
|
builder.Services.AddRazorComponents()
|
|
.AddInteractiveServerComponents();
|
|
|
|
builder.Services.AddFluentUIComponents();
|
|
|
|
builder.Services.Configure<SettingsDataset>(
|
|
builder.Configuration.GetSection("Settings"));
|
|
builder.Services.AddSingleton(sp =>
|
|
sp.GetRequiredService<IOptions<SettingsDataset>>().Value);
|
|
|
|
builder.Services.AddAccounting();
|
|
|
|
|
|
var app = builder.Build();
|
|
|
|
// Convert any remaining XML data files to JSON before serving requests. Throws (and
|
|
// stops startup) if a file can't be converted, rather than running on partial data.
|
|
await app.Services.GetRequiredService<XmlToJsonMigrator>()
|
|
.MigrateAsync(app.Services.GetRequiredService<SettingsDataset>().DataPath);
|
|
|
|
// Configure the HTTP request pipeline.
|
|
if (!app.Environment.IsDevelopment())
|
|
{
|
|
app.UseExceptionHandler("/Error");
|
|
// 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.UseHttpsRedirection();
|
|
|
|
var supportedCultures = new[] { new CultureInfo("de-CH") };
|
|
app.UseRequestLocalization(new RequestLocalizationOptions
|
|
{
|
|
DefaultRequestCulture = new RequestCulture(supportedCultures[0]),
|
|
SupportedCultures = supportedCultures,
|
|
SupportedUICultures = supportedCultures
|
|
});
|
|
|
|
app.UseAntiforgery();
|
|
app.MapStaticAssets();
|
|
app.MapRazorComponents<App>()
|
|
.AddInteractiveServerRenderMode();
|
|
|
|
await app.RunAsync();
|
|
}
|
|
}
|
|
}
|