86 lines
2.8 KiB
C#
86 lines
2.8 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using NLog;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace GWMS.Data
|
|
{
|
|
public static class DbConfig
|
|
{
|
|
#region Public Fields
|
|
|
|
public static string DATABASE_NAME = "GWMS";
|
|
|
|
public static int DATABASE_PROCESS_TIMEOUT = 5;
|
|
public static string DATABASE_PWD = "viadante16";
|
|
|
|
// Database config
|
|
public static string DATABASE_SERV = "127.0.0.1";
|
|
|
|
public static string DATABASE_USER = "GWMS_User";
|
|
|
|
#endregion Public Fields
|
|
|
|
#region Public Properties
|
|
|
|
/// <summary>
|
|
/// DB Connection string per azioni amministrative
|
|
/// </summary>
|
|
public static string ADMIN_CONNECTION_STRING { get; set; } = "";
|
|
|
|
/// <summary>
|
|
/// DB Connection string
|
|
/// </summary>
|
|
public static string CONNECTION_STRING { get; set; } = "";
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Public Methods
|
|
|
|
public static bool CheckUser(string nKey, string sKey)
|
|
{
|
|
// esecuzione script di install locale
|
|
return DbAdmin.checkCreateUser(DATABASE_USER, DATABASE_PWD);
|
|
}
|
|
|
|
public static bool ExecMigrationIdentity()
|
|
{
|
|
Log.Info($"ExecMigrationIdentity: Start");
|
|
// esecuzione migrazione
|
|
var migrateTask = Task.Run(async () => await DbAdmin.migrateDbIdentity());
|
|
migrateTask.Wait();
|
|
Log.Info($"ExecMigrationIdentity: Completed");
|
|
return migrateTask.Result;
|
|
}
|
|
|
|
public static bool ExecMigrationMain()
|
|
{
|
|
Log.Info($"ExecMigrationMain: Start");
|
|
// esecuzione migrazione
|
|
var migrateTask = Task.Run(async () => await DbAdmin.migrateDbMain());
|
|
migrateTask.Wait();
|
|
Log.Info($"ExecMigrationMain: Completed");
|
|
return migrateTask.Result;
|
|
}
|
|
|
|
public static void InitDb(string server, string nKey, string sKey)
|
|
{
|
|
DATABASE_SERV = server;
|
|
DATABASE_NAME = $"GWMS_{nKey}";
|
|
DATABASE_USER = $"user_{nKey}";
|
|
DATABASE_PWD = $"pwd_{sKey}";
|
|
CONNECTION_STRING = $"server={DATABASE_SERV};port=3306;database={DATABASE_NAME};uid={DATABASE_USER};pwd={DATABASE_PWD};sslmode=None";
|
|
// stringa admin con utente root egalware...
|
|
ADMIN_CONNECTION_STRING = $"server={DATABASE_SERV};port=3306;database=mysql;uid=root;pwd=Egalware_24068!;sslmode=None";
|
|
}
|
|
|
|
public static ServerVersion MysqlServerVersion(string connString)
|
|
{
|
|
ServerVersion serverVersion = ServerVersion.AutoDetect(connString);
|
|
return serverVersion;
|
|
}
|
|
|
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
|
|
|
#endregion Public Methods
|
|
}
|
|
} |