51c61eabf7
- Aggiunge rilevamento automatico Primary Key per connessioni database - Rimuove completamente il fallback automatico per lato sorgente - Implementa selezione manuale obbligatoria per file e sorgenti non-DB - Migliora UI con suggerimenti intelligenti e feedback visivo - Aggiunge validazione multi-livello (UI, pre-transfer, runtime) - Introduce metodo GetPrimaryKeyFieldAsync in IDatabaseManager - Modifica GenerateSourceKey per richiedere sempre campo specifico - Implementa controllo IsTransferButtonEnabled per validazione form Breaking changes: - La generazione automatica delle chiavi sorgente è stata rimossa - Il campo chiave sorgente è ora obbligatorio quando si usa il sistema associazioni Fixes: Risolve problema di discovery schema vuoto con selezione database
79 lines
2.5 KiB
C#
79 lines
2.5 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.AspNetCore.Components.Web;
|
|
using DataConnection;
|
|
using DataConnection.EF;
|
|
using DataConnection.Interfaces;
|
|
using DataConnection.EF.DatabaseDiscovery;
|
|
using DataConnection.Enums;
|
|
using DataConnection.CredentialManagement;
|
|
using CredentialManager;
|
|
using Data_Coupler.Services;
|
|
using System;
|
|
using System.Threading.Tasks;
|
|
using Data_Coupler.BackgrounServices;
|
|
|
|
// Registra il provider di encoding per ExcelDataReader (necessario per file .xls)
|
|
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
// Add services to the container.
|
|
builder.Services.AddRazorPages();
|
|
builder.Services.AddServerSideBlazor();
|
|
builder.Services.AddWindowsService();
|
|
builder.Services.AddHostedService<BackgroundServices>();
|
|
|
|
// Add CredentialManager services
|
|
var contentRoot = builder.Environment.ContentRootPath;
|
|
var dataPath = Path.Combine(contentRoot, "wwwroot", "data");
|
|
Directory.CreateDirectory(dataPath); // Assicurati che la directory esista
|
|
var dbPath = Path.Combine(dataPath, "credentials.db");
|
|
builder.Services.AddDataConnectionCredentialManagement($"Data Source={dbPath}");
|
|
|
|
// Register IHttpClientFactory
|
|
builder.Services.AddHttpClient();
|
|
|
|
// Register Data Connection Factory
|
|
builder.Services.AddScoped<IDataConnectionFactory, DataConnectionFactory>();
|
|
//builder.WebHost.UseUrls("http://*:7550");
|
|
|
|
var app = builder.Build();
|
|
|
|
// Initialize database
|
|
using (var scope = app.Services.CreateScope())
|
|
{
|
|
var logger = scope.ServiceProvider.GetRequiredService<ILogger<Program>>();
|
|
try
|
|
{
|
|
logger.LogInformation("Inizializzazione database in corso...");
|
|
var dbInitializer = scope.ServiceProvider.GetRequiredService<CredentialManager.Services.IDatabaseInitializer>();
|
|
dbInitializer.InitializeAsync().GetAwaiter().GetResult();
|
|
logger.LogInformation("Database inizializzato con successo.");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.LogError(ex, "Errore durante l'inizializzazione del database: {Message}", ex.Message);
|
|
throw; // Rilancia l'eccezione per non far partire l'app con un database non funzionante
|
|
}
|
|
}
|
|
|
|
// 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();
|
|
|
|
app.UseStaticFiles();
|
|
|
|
app.UseRouting();
|
|
|
|
app.MapBlazorHub();
|
|
app.MapFallbackToPage("/_Host");
|
|
|
|
app.Run();
|
|
|