a873dce31b
- Modificato GetAllRecordsAsync per utilizzare la stessa connection string del discovery schema - Aggiunto metodo CreateConnection per creare connessioni DB appropriate per tipo - Migliorata gestione nomi tabelle con schema (es. "dbo.OCRD") - Rimossi metodi obsoleti di creazione entità (UpdateEntityData, CreateNewEntity) - Eliminati riferimenti a variabili non dichiarate (newEntityData, isCreatingEntity) - Aggiunto logging debug per connection string e query SQL - Completata implementazione trasferimento dati da database a REST API Il trasferimento dati ora utilizza la stessa connessione per discovery e estrazione, risolvendo problemi di accesso alle tabelle durante l'operazione di upsert.
72 lines
2.2 KiB
C#
72 lines
2.2 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;
|
|
|
|
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();
|
|
|