33bd5e2bbf
- Aggiunge selezione tipo fonte dati (database o file) nella UI - Implementa caricamento e parsing di file Excel (.xlsx, .xls) usando ExcelDataReader - Implementa parsing CSV con rilevamento automatico separatore (,;|\t) - Aggiunge preview paginato dei dati file con controlli navigazione - Estende mapping campi per supportare sia database che file - Corregge errori strutturali HTML/Razor e gestione chiavi dizionario - Migliora logica trasferimento dati per fonti multiple - Aggiunge supporto encoding per file Excel legacy (.xls) Modifiche principali: - DataCoupler.razor: UI completa per gestione file + correzioni strutturali - Data_Coupler.csproj: Dipendenze ExcelDataReader per supporto Excel - Program.cs: Registrazione provider encoding per compatibilità .xls Il sistema ora supporta completamente sia database che file come fonte dati con parsing robusto, preview interattivo e mapping flessibile.
75 lines
2.4 KiB
C#
75 lines
2.4 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;
|
|
|
|
// 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();
|
|
|
|
// 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>();
|
|
|
|
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();
|
|
|