Implementato il supporto per la scoperta e la visualizzazione dello schema del database, inclusa la creazione di provider specifici per SQL Server e l'integrazione con il servizio di connessione al database.
This commit is contained in:
@@ -6,6 +6,7 @@ using DataConnection.Interfaces;
|
||||
using DataConnection.EF;
|
||||
using DataConnection.EF.DatabaseDiscovery;
|
||||
using DataConnection.Enums;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Data_Coupler.Data
|
||||
{
|
||||
@@ -13,6 +14,8 @@ namespace Data_Coupler.Data
|
||||
{
|
||||
private readonly IDatabaseDiscovery _sqlServerDiscovery;
|
||||
private readonly IDatabaseDiscovery _mySqlDiscovery;
|
||||
private readonly DbManagerOptions _dbManagerOptions;
|
||||
private IDatabaseManager _databaseManager;
|
||||
|
||||
public DatabaseType SelectedDatabaseType { get; set; } = DatabaseType.SqlServer;
|
||||
public string ConnectionString { get; set; }
|
||||
@@ -22,9 +25,10 @@ namespace Data_Coupler.Data
|
||||
public bool IsConnected { get; private set; }
|
||||
public string ErrorMessage { get; private set; }
|
||||
|
||||
public DatabaseConnectionService()
|
||||
public DatabaseConnectionService(DbManagerOptions dbManagerOptions)
|
||||
{
|
||||
_sqlServerDiscovery = new SqlServerDatabaseDiscovery();
|
||||
_dbManagerOptions = dbManagerOptions ?? new DbManagerOptions();
|
||||
// Se in futuro verrà implementata la discovery MySQL, potremmo aggiungerla qui
|
||||
// _mySqlDiscovery = new MySqlDatabaseDiscovery();
|
||||
}
|
||||
@@ -104,5 +108,43 @@ namespace Data_Coupler.Data
|
||||
// Per altri tipi di database, implementare la logica appropriata
|
||||
return ConnectionString;
|
||||
}
|
||||
|
||||
public IDatabaseManager GetDatabaseManager()
|
||||
{
|
||||
if (_databaseManager != null)
|
||||
return _databaseManager;
|
||||
|
||||
// Configura le opzioni del database manager
|
||||
_dbManagerOptions.ServerConnectionString = ConnectionString;
|
||||
_dbManagerOptions.DatabaseName = SelectedDatabase;
|
||||
|
||||
// Configura il contesto in base al tipo di database
|
||||
_dbManagerOptions.DbContextConfigurator = options =>
|
||||
{
|
||||
switch (SelectedDatabaseType)
|
||||
{
|
||||
case DatabaseType.SqlServer:
|
||||
options.UseSqlServer(BuildConnectionStringWithDatabase(),
|
||||
sqlOptions => sqlOptions.CommandTimeout(_dbManagerOptions.CommandTimeout));
|
||||
break;
|
||||
// Aggiungi altri tipi di database quando implementati
|
||||
default:
|
||||
throw new NotSupportedException($"Tipo di database non supportato: {SelectedDatabaseType}");
|
||||
}
|
||||
};
|
||||
|
||||
// Crea il database manager
|
||||
_databaseManager = new EFCoreDatabaseManager(_dbManagerOptions);
|
||||
return _databaseManager;
|
||||
}
|
||||
|
||||
public void DisposeDatabaseManager()
|
||||
{
|
||||
if (_databaseManager != null)
|
||||
{
|
||||
_databaseManager.Dispose();
|
||||
_databaseManager = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user