7e450a358b
- Creata nuova libreria Components con componenti Blazor riutilizzabili * ProfileSelector: dropdown per selezione profili salvati * ProfileSaver: componente per salvare configurazioni correnti come profili * ProfileManagement: modale per gestione profili salvati * ProfileQuickActions: bottoni azioni rapide per operazioni sui profili - Esteso CredentialManager con entità e servizi per DataCouplerProfile * Aggiunto modello DataCouplerProfile con configurazioni mapping e metadati * Implementata migrazione Entity Framework per memorizzazione profili * Creato DataCouplerProfileService per operazioni CRUD * Aggiunto CredentialDbContextFactory per operazioni database design-time - Migliorato componente principale DataCoupler con integrazione profili * Integrata funzionalità caricamento/salvataggio profili * Aggiunto selettore profili nella parte superiore dell'interfaccia * Mantenuta retrocompatibilità con funzionalità esistenti * Migliorata esperienza utente con gestione configurazioni salvate - Aggiornata struttura progetto e dipendenze * Aggiunto progetto Components alla soluzione * Aggiornati riferimenti progetti e import * Rimosso progetto obsoleto TestDatabaseFix Questo aggiornamento migliora significativamente il flusso di lavoro permettendo agli utenti di salvare, caricare e gestire configurazioni complete di accoppiamento dati come
131 lines
4.7 KiB
C#
131 lines
4.7 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Logging;
|
|
using CredentialManager.Data;
|
|
using CredentialManager.Services;
|
|
|
|
namespace CredentialManager;
|
|
|
|
/// <summary>
|
|
/// Classe per la configurazione del CredentialManager
|
|
/// </summary>
|
|
public static class CredentialManagerConfiguration
|
|
{
|
|
/// <summary>
|
|
/// Registra i servizi del CredentialManager
|
|
/// </summary>
|
|
/// <param name="services">La collezione di servizi</param>
|
|
/// <param name="databasePath">Il percorso del database SQLite (opzionale, default: credentials.db)</param>
|
|
/// <returns>La collezione di servizi</returns>
|
|
public static IServiceCollection AddCredentialManager(
|
|
this IServiceCollection services,
|
|
string? databasePath = null)
|
|
{
|
|
// Imposta il percorso predefinito se non specificato
|
|
databasePath ??= Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
|
"CredentialManager", "credentials.db");
|
|
|
|
// Assicurati che la directory esista
|
|
var directory = Path.GetDirectoryName(databasePath);
|
|
if (!string.IsNullOrEmpty(directory) && !Directory.Exists(directory))
|
|
{
|
|
Directory.CreateDirectory(directory);
|
|
}
|
|
|
|
// Registra il DbContext
|
|
services.AddDbContext<CredentialDbContext>(options =>
|
|
options.UseSqlite($"Data Source={databasePath}"));
|
|
|
|
// Registra i servizi
|
|
services.AddScoped<IEncryptionService, EncryptionService>();
|
|
services.AddScoped<ICredentialService, CredentialService>();
|
|
services.AddScoped<IDatabaseInitializer, DatabaseInitializer>();
|
|
services.AddScoped<IDataCouplerProfileService, DataCouplerProfileService>();
|
|
|
|
return services;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Inizializza il database del CredentialManager
|
|
/// </summary>
|
|
/// <param name="serviceProvider">Il provider di servizi</param>
|
|
/// <returns>Task completato</returns>
|
|
public static async Task InitializeCredentialManagerAsync(this IServiceProvider serviceProvider)
|
|
{
|
|
using var scope = serviceProvider.CreateScope();
|
|
var initializer = scope.ServiceProvider.GetRequiredService<IDatabaseInitializer>();
|
|
await initializer.InitializeAsync();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Factory per creare un'istanza standalone del CredentialManager
|
|
/// </summary>
|
|
public static class CredentialManagerFactory
|
|
{
|
|
/// <summary>
|
|
/// Crea un'istanza standalone del CredentialManager
|
|
/// </summary>
|
|
/// <param name="databasePath">Il percorso del database SQLite (opzionale)</param>
|
|
/// <param name="loggerFactory">Factory per il logging (opzionale)</param>
|
|
/// <returns>Un'istanza di ICredentialService</returns>
|
|
public static async Task<ICredentialService> CreateAsync(
|
|
string? databasePath = null,
|
|
ILoggerFactory? loggerFactory = null)
|
|
{
|
|
// Configurazione dei servizi
|
|
var services = new ServiceCollection();
|
|
|
|
// Aggiungi logging se fornito
|
|
if (loggerFactory != null)
|
|
{
|
|
services.AddSingleton(loggerFactory);
|
|
services.AddLogging();
|
|
}
|
|
else
|
|
{
|
|
services.AddLogging(builder => builder.AddConsole());
|
|
}
|
|
|
|
// Aggiungi CredentialManager
|
|
services.AddCredentialManager(databasePath);
|
|
|
|
// Costruisci il provider di servizi
|
|
var serviceProvider = services.BuildServiceProvider();
|
|
|
|
// Inizializza il database
|
|
await serviceProvider.InitializeCredentialManagerAsync();
|
|
|
|
// Restituisci il servizio
|
|
return serviceProvider.GetRequiredService<ICredentialService>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Crea un'istanza standalone del CredentialManager con configurazione personalizzata
|
|
/// </summary>
|
|
/// <param name="configureServices">Azione per configurare servizi aggiuntivi</param>
|
|
/// <param name="databasePath">Il percorso del database SQLite (opzionale)</param>
|
|
/// <returns>Il provider di servizi configurato</returns>
|
|
public static async Task<IServiceProvider> CreateServiceProviderAsync(
|
|
Action<IServiceCollection>? configureServices = null,
|
|
string? databasePath = null)
|
|
{
|
|
var services = new ServiceCollection();
|
|
|
|
// Configurazione di base
|
|
services.AddLogging(builder => builder.AddConsole());
|
|
services.AddCredentialManager(databasePath);
|
|
|
|
// Configurazione personalizzata
|
|
configureServices?.Invoke(services);
|
|
|
|
// Costruisci il provider
|
|
var serviceProvider = services.BuildServiceProvider();
|
|
|
|
// Inizializza il database
|
|
await serviceProvider.InitializeCredentialManagerAsync();
|
|
|
|
return serviceProvider;
|
|
}
|
|
}
|