Interfaccia web, parte 1: ospite, sicurezza, API, modalità dimostrativa, libreria, visualizzatore e account
Febe.Web: AddFebeWeb/UseFebe/FebeWebHost per le due vesti, interfaccia incorporata con IFileProvider proprio, indirizzi italiani, API JSON con contesto generato, eventi SSE, controlli di Host/Origin, gettone del desktop e password con blocco (§13.1), INativeShell e capacità per veste. Modalità --demo con 38 account e circa 18.000 elementi finti e scene del motore. Pagine Libreria, Visualizzatore, Account, Aggiungi account e Scheda account (contenuti, impostazioni con piano, cronologia); schermate in docs/schermate con le differenze dai mockup; prove delle API, della sicurezza, dell'esportazione CSV e dei dati dimostrativi. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Mzbb6zeFTjT6Rp8b92AVkA
This commit is contained in:
76 files changed
+12503
-17
No files matched your search
@@ -0,0 +1,122 @@
|
||||
using System.Globalization;
|
||||
using System.Runtime.InteropServices;
|
||||
using Febe.Web;
|
||||
using Febe.Web.Demo;
|
||||
|
||||
namespace Febe.Server;
|
||||
|
||||
/// <summary>
|
||||
/// <c>--demo [--porta 8480] [--fuso Europe/Rome]</c> (spec §10.6): the interface with demo data, without browser and
|
||||
/// without network, on 127.0.0.1 only and without password. Everything lives in a temporary folder that is removed
|
||||
/// at the end (Ctrl+C). Exit code 0 at the end, 2 for wrong arguments.
|
||||
/// </summary>
|
||||
internal static class DemoCommand
|
||||
{
|
||||
public const string Flag = "--demo";
|
||||
|
||||
public static bool Matches(string[] args) => args.Any(a => string.Equals(a, Flag, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
public static async Task<int> RunAsync(string[] args, TextWriter output, TextWriter error)
|
||||
{
|
||||
if (!TryParse(args, out var options, out var problem))
|
||||
{
|
||||
await error.WriteLineAsync(problem).ConfigureAwait(false);
|
||||
await error.WriteLineAsync("Uso: --demo [--porta 8480] [--fuso Europe/Rome]").ConfigureAwait(false);
|
||||
return 2;
|
||||
}
|
||||
|
||||
using var stop = new CancellationTokenSource();
|
||||
ConsoleCancelEventHandler onCancel = (_, e) =>
|
||||
{
|
||||
e.Cancel = true;
|
||||
stop.Cancel();
|
||||
};
|
||||
Console.CancelKeyPress += onCancel;
|
||||
|
||||
// A container or a service manager stops with SIGTERM: the temporary folder must go away then too.
|
||||
using var terminate = PosixSignalRegistration.Create(PosixSignal.SIGTERM, context =>
|
||||
{
|
||||
context.Cancel = true;
|
||||
stop.Cancel();
|
||||
});
|
||||
try
|
||||
{
|
||||
await output.WriteLineAsync("Febe, modalità dimostrativa: preparo una libreria finta in una cartella temporanea…").ConfigureAwait(false);
|
||||
DemoHost demo;
|
||||
try
|
||||
{
|
||||
demo = await DemoHost.StartAsync(options, stop.Token).ConfigureAwait(false);
|
||||
}
|
||||
catch (IOException ex) when (ex.InnerException is not null || ex.Message.Contains("address", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
await error.WriteLineAsync($"La porta {options.Port} è già occupata: chiudi l'altro programma che la usa, oppure scegline un'altra con --porta.").ConfigureAwait(false);
|
||||
return 1;
|
||||
}
|
||||
|
||||
await using var running = demo;
|
||||
var address = new Uri(demo.Address, "/libreria");
|
||||
await output.WriteLineAsync($"Pronto: {demo.World.Accounts} account e {Febe.Core.Engine.ItalianText.Number(demo.World.Entries)} elementi dimostrativi.").ConfigureAwait(false);
|
||||
await output.WriteLineAsync($"Apri {address}").ConfigureAwait(false);
|
||||
await output.WriteLineAsync("Scene: ?scena=normale, sessione, fermo, scollegato; tema: ?tema=chiaro o scuro; veste: ?veste=desktop o docker.").ConfigureAwait(false);
|
||||
await output.WriteLineAsync("Premi Ctrl+C per chiudere: la cartella temporanea viene cancellata.").ConfigureAwait(false);
|
||||
try
|
||||
{
|
||||
await Task.Delay(Timeout.Infinite, stop.Token).ConfigureAwait(false);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
}
|
||||
|
||||
await output.WriteLineAsync("Chiudo la dimostrazione.").ConfigureAwait(false);
|
||||
return 0;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Console.CancelKeyPress -= onCancel;
|
||||
}
|
||||
}
|
||||
|
||||
internal static bool TryParse(string[] args, out DemoOptions options, out string problem)
|
||||
{
|
||||
var port = FebeListen.DefaultPort;
|
||||
TimeZoneInfo? zone = null;
|
||||
problem = string.Empty;
|
||||
options = new DemoOptions();
|
||||
for (var i = 0; i < args.Length; i++)
|
||||
{
|
||||
switch (args[i].ToLowerInvariant())
|
||||
{
|
||||
case Flag:
|
||||
break;
|
||||
case "--porta" when i + 1 < args.Length:
|
||||
if (!int.TryParse(args[++i], NumberStyles.Integer, CultureInfo.InvariantCulture, out port) || port is < 0 or > 65535)
|
||||
{
|
||||
problem = "Porta non valida: un numero fra 1 e 65535.";
|
||||
return false;
|
||||
}
|
||||
|
||||
break;
|
||||
case "--fuso" when i + 1 < args.Length:
|
||||
try
|
||||
{
|
||||
zone = TimeZoneInfo.FindSystemTimeZoneById(args[++i]);
|
||||
}
|
||||
catch (TimeZoneNotFoundException)
|
||||
{
|
||||
problem = $"Fuso orario sconosciuto: {args[i]}.";
|
||||
return false;
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
problem = $"Opzione sconosciuta: {args[i]}.";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Development: FEBE_INTERFACCIA=src/Febe.Web/wwwroot serves the pages from the sources (edit, reload).
|
||||
var folder = Environment.GetEnvironmentVariable("FEBE_INTERFACCIA");
|
||||
options = new DemoOptions(port, zone, null, string.IsNullOrWhiteSpace(folder) || !Directory.Exists(folder) ? null : folder);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,18 @@
|
||||
// Composition root for Linux and Docker. Filled in by milestones M3–M5.
|
||||
using Febe.Server;
|
||||
|
||||
Console.OutputEncoding = System.Text.Encoding.UTF8;
|
||||
|
||||
if (SimulateCommand.Matches(args))
|
||||
{
|
||||
Console.OutputEncoding = System.Text.Encoding.UTF8;
|
||||
return await SimulateCommand.RunAsync(args, Console.Out, Console.Error);
|
||||
}
|
||||
|
||||
if (DemoCommand.Matches(args))
|
||||
{
|
||||
return await DemoCommand.RunAsync(args, Console.Out, Console.Error);
|
||||
}
|
||||
|
||||
Console.WriteLine("Febe");
|
||||
Console.WriteLine("Comandi: --demo (interfaccia con dati dimostrativi), --simula 30g --profilo prudente (simulazione del motore).");
|
||||
return 0;
|
||||
Reference in new issue
Block a user