AccountingNext/Schaad.Accounting.UI/Program.cs
Claudio Schaad cbc1cd3f1f Restructure data folder to {mandator}/{year}, uploads and backup at root
New layout below DataPath (defined in DataFolders):
  {mandator}/{year}/*.json
  uploads/{mandator}/{year}/
  backup/{mandator}/{year}/

XmlToJsonMigrator becomes DataMigrator with two phases: first move the old
{year}/{mandator}/Data, uploads and {year}/backup folders into the new layout
unchanged, then convert the XML data files to JSON. Nothing is overwritten;
an identical file at the target is dropped, a different one stops startup.
Old folders are removed only once empty.

SettingsService builds the new paths; GetYearMandatorPath and
GetLastYearMandatorPath are removed as they now equal the data paths.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 13:57:58 +02:00

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();
// Move old-layout folders and convert XML data files to JSON before serving requests.
// Throws (and stops startup) if anything fails, rather than running on partial data.
await app.Services.GetRequiredService<DataMigrator>()
.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();
}
}
}