009fa51155
Introdotta una nuova interfaccia utente Blazor Server moderna, dark e responsive, con sidebar di navigazione, statistiche animate, banner utente, gestione stato aste e browser integrato. Aggiunti servizi per stato aste e impostazioni, ampio set di stili CSS e animazioni, integrazione JS per l'iframe browser, nuovi layout e configurazione di avvio per sviluppo e produzione. L'app è ora pronta per un'esperienza web professionale e cross-platform.
126 lines
3.3 KiB
C#
126 lines
3.3 KiB
C#
using AutoBidder.Services;
|
|
using AutoBidder.Data;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.AspNetCore.Components.Web;
|
|
using Microsoft.AspNetCore.DataProtection;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
// Configura Kestrel per accesso remoto con supporto HTTPS
|
|
builder.WebHost.ConfigureKestrel(options =>
|
|
{
|
|
options.ListenAnyIP(5000); // HTTP
|
|
options.ListenAnyIP(5001, listenOptions =>
|
|
{
|
|
listenOptions.UseHttps(); // HTTPS
|
|
});
|
|
});
|
|
|
|
// Add services to the container
|
|
builder.Services.AddRazorPages();
|
|
builder.Services.AddServerSideBlazor();
|
|
|
|
// Configura Data Protection per evitare CryptographicException
|
|
var dataProtectionPath = Path.Combine(
|
|
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
|
"AutoBidder",
|
|
"DataProtection-Keys"
|
|
);
|
|
|
|
if (!Directory.Exists(dataProtectionPath))
|
|
{
|
|
Directory.CreateDirectory(dataProtectionPath);
|
|
}
|
|
|
|
builder.Services.AddDataProtection()
|
|
.PersistKeysToFileSystem(new DirectoryInfo(dataProtectionPath))
|
|
.SetApplicationName("AutoBidder");
|
|
|
|
// Configura HTTPS Redirection per produzione
|
|
if (!builder.Environment.IsDevelopment())
|
|
{
|
|
builder.Services.AddHsts(options =>
|
|
{
|
|
options.MaxAge = TimeSpan.FromDays(365);
|
|
options.IncludeSubDomains = true;
|
|
options.Preload = true;
|
|
});
|
|
}
|
|
|
|
// Configura Database SQLite per statistiche
|
|
builder.Services.AddDbContext<StatisticsContext>(options =>
|
|
{
|
|
var dbPath = Path.Combine(
|
|
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
|
"AutoBidder",
|
|
"statistics.db"
|
|
);
|
|
|
|
// Crea directory se non esiste
|
|
var directory = Path.GetDirectoryName(dbPath);
|
|
if (!string.IsNullOrEmpty(directory) && !Directory.Exists(directory))
|
|
{
|
|
Directory.CreateDirectory(directory);
|
|
}
|
|
|
|
options.UseSqlite($"Data Source={dbPath}");
|
|
});
|
|
|
|
// Registra servizi applicazione come Singleton per condividere stato
|
|
var htmlCacheService = new HtmlCacheService(
|
|
maxConcurrentRequests: 3,
|
|
requestsPerSecond: 5,
|
|
cacheExpiration: TimeSpan.FromMinutes(5),
|
|
maxRetries: 2
|
|
);
|
|
|
|
var auctionMonitor = new AuctionMonitor();
|
|
htmlCacheService.OnLog += (msg) => Console.WriteLine(msg);
|
|
|
|
builder.Services.AddSingleton(auctionMonitor);
|
|
builder.Services.AddSingleton(htmlCacheService);
|
|
builder.Services.AddSingleton(sp => new SessionService(auctionMonitor.GetApiClient()));
|
|
builder.Services.AddScoped<StatsService>(sp =>
|
|
{
|
|
var ctx = sp.GetRequiredService<StatisticsContext>();
|
|
return new StatsService(ctx);
|
|
});
|
|
builder.Services.AddScoped<AuctionStateService>();
|
|
|
|
// Configura SignalR per real-time updates
|
|
builder.Services.AddSignalR(options =>
|
|
{
|
|
options.MaximumReceiveMessageSize = 102400; // 100KB
|
|
options.EnableDetailedErrors = true;
|
|
});
|
|
|
|
var app = builder.Build();
|
|
|
|
// Crea database se non esiste (senza migrations)
|
|
using (var scope = app.Services.CreateScope())
|
|
{
|
|
var db = scope.ServiceProvider.GetRequiredService<StatisticsContext>();
|
|
db.Database.EnsureCreated(); // Crea schema automaticamente se non esiste
|
|
}
|
|
|
|
// Configure the HTTP request pipeline
|
|
if (!app.Environment.IsDevelopment())
|
|
{
|
|
app.UseExceptionHandler("/Error");
|
|
app.UseHsts();
|
|
}
|
|
else
|
|
{
|
|
app.UseDeveloperExceptionPage();
|
|
}
|
|
|
|
app.UseHttpsRedirection();
|
|
app.UseStaticFiles();
|
|
app.UseRouting();
|
|
|
|
app.MapBlazorHub();
|
|
app.MapFallbackToPage("/_Host");
|
|
|
|
app.Run();
|