Fix warnings vari e semplificazione classe DB

This commit is contained in:
Samuele Locatelli
2022-03-18 09:52:57 +01:00
parent f2b24aa3ea
commit d2c0761f7b
9 changed files with 22 additions and 121 deletions
+1 -1
View File
@@ -53,7 +53,7 @@ if (string.IsNullOrEmpty(connStringDB))
}
else
{
dbController = new MpDbController(config);
dbController = new MpDbController();
Log.Info("DbController OK");
Console.WriteLine("DbController OK");
}
+1 -13
View File
@@ -17,8 +17,6 @@ namespace MP.MONO.Data
{
#region Private Fields
private IConfiguration _configuration;
#endregion Private Fields
#region Public Constructors
@@ -27,14 +25,6 @@ namespace MP.MONO.Data
{
}
public AdminContext(IConfiguration configuration)
{
_configuration = configuration;
}
public AdminContext(DbContextOptions<AdminContext> options) : base(options)
{
}
#endregion Public Constructors
@@ -43,7 +33,7 @@ namespace MP.MONO.Data
/// <summary>
/// User management
/// </summary>
public DbSet<UserPriv> UserList { get; set; }
public DbSet<UserPriv> UserList { get; set; } = null!;
#endregion Public Properties
@@ -60,8 +50,6 @@ namespace MP.MONO.Data
string connString = DbConfig.ADMIN_CONNECTION_STRING;
if (!optionsBuilder.IsConfigured)
{
//connString = _configuration.GetConnectionString("GWMS.Data");
//connString = "Server=localhost;port=3306;database=GWMS;user=GWMS;pwd=GWMS_secret_pwd;sslmode=None;";
var serverVersion = ServerVersion.AutoDetect(connString);
optionsBuilder.UseMySql(connString, serverVersion);
}
+5 -60
View File
@@ -14,13 +14,10 @@ namespace MP.MONO.Data.Controllers
{
public class MpDbController : IDisposable
{
private static IConfiguration _configuration;
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
public MpDbController(IConfiguration configuration)
{
_configuration = configuration;
}
public MpDbController()
{ }
public void Dispose()
{
@@ -38,7 +35,7 @@ namespace MP.MONO.Data.Controllers
public List<AlarmLogModel> AlarmLogGetFilt(int MachineId, int skipRec, int numRec)
{
List<AlarmLogModel> dbResult = new List<AlarmLogModel>();
using (MapoMonoContext localDbCtx = new MapoMonoContext(_configuration))
using (MapoMonoContext localDbCtx = new MapoMonoContext())
{
try
{
@@ -67,7 +64,7 @@ namespace MP.MONO.Data.Controllers
public async Task<bool> AlarmLogInsert(AlarmLogModel newItem)
{
bool fatto = false;
using (MapoMonoContext localDbCtx = new MapoMonoContext(_configuration))
using (MapoMonoContext localDbCtx = new MapoMonoContext())
{
try
{
@@ -115,58 +112,6 @@ namespace MP.MONO.Data.Controllers
// !!!FIXME TODO... è fake...
Random rand = new Random();
int stdCycle = 5;
#if false
var currVal = rand.NextDouble();
DisplayDataDTO displ01 = new DisplayDataDTO()
{
Order = 0,
Title = "OEE",
ValueNum = currVal,
IsNumeric = true,
Value = currVal.ToString("P1"),
Type = "OEE-75-90"
};
answ.Add(displ01);
currVal = rand.NextDouble();
DisplayDataDTO displ02 = new DisplayDataDTO()
{
Order = 0,
Title = "Avail",
ValueNum = currVal,
IsNumeric = true,
Value = currVal.ToString("P1"),
Type = "AVAIL-50-80"
};
answ.Add(displ02);
currVal = rand.NextDouble();
DisplayDataDTO displ03 = new DisplayDataDTO()
{
Order = 0,
Title = "Order fulfill",
ValueNum = currVal,
IsNumeric = true,
Value = currVal.ToString("P1"),
Type = "ORDER"
};
answ.Add(displ03);
double minTCiclo = stdCycle * rand.NextDouble();
TimeSpan durTCycle = TimeSpan.FromMinutes(minTCiclo);
DisplayDataDTO displ04 = new DisplayDataDTO()
{
Order = 0,
Title = "Cycle time",
ValueNum = 0,
IsNumeric = false,
Value = $"{durTCycle.Hours:00}:{durTCycle.Minutes:00}:{durTCycle.Seconds:00}",
Type = "TCycle"
};
answ.Add(displ04);
#endif
double currVal = 0;
currVal = rand.Next(10, 120) * 100;
DisplayDataDTO displ01 = new DisplayDataDTO()
@@ -204,7 +149,7 @@ namespace MP.MONO.Data.Controllers
};
answ.Add(displ03);
currVal = rand.NextDouble() *5000;
currVal = rand.NextDouble() * 5000;
DisplayDataDTO displ04 = new DisplayDataDTO()
{
Order = 0,
+2 -2
View File
@@ -18,8 +18,8 @@ namespace MP.MONO.Data.DbModels
{
#region Public Properties
public int Count { get; set; }
public string TableName { get; set; }
public int Count { get; set; } = 0;
public string TableName { get; set; } = "";
#endregion Public Properties
}
+7 -7
View File
@@ -15,16 +15,16 @@ namespace MP.MONO.Data
#region Public Properties
public string Host_Address { get; set; }
public string Host_Address { get; set; } = "";
public string Host_Password { get; set; }
public int Host_Port { get; set; }
public string Host_Password { get; set; } = "";
public int Host_Port { get; set; } = 0;
public SecureSocketOptions Host_SecureSocketOptions { get; set; }
public string Host_Username { get; set; }
public string Sender_EMail { get; set; }
public SecureSocketOptions Host_SecureSocketOptions { get; set; } = SecureSocketOptions.None;
public string Host_Username { get; set; } = "";
public string Sender_EMail { get; set; } = "";
public string Sender_Name { get; set; }
public string Sender_Name { get; set; } = "";
#endregion Public Properties
}
-27
View File
@@ -13,37 +13,16 @@ namespace MP.MONO.Data
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
private IConfiguration _configuration;
#endregion Private Fields
#region Public Constructors
public MapoMonoContext(IConfiguration configuration)
{
_configuration = configuration;
}
public MapoMonoContext()
{
//connString = "server=10.74.82.230;port=3306;database=MAPO.MONO;uid=steamware;pwd=Egalware_24068!;sslmode=None;";
}
#if false
public MapoMonoContext(DbContextOptions<MapoMonoContext> options) : base(options)
{
try
{
// se non ci fosse... crea o migra!
Database.Migrate();
}
catch (Exception exc)
{
Log.Error(exc, "Exception during context initialization 02");
}
}
#endif
#endregion Public Constructors
@@ -124,12 +103,6 @@ namespace MP.MONO.Data
}
catch
{ }
// se vuoto sistemo...
if (string.IsNullOrEmpty(connString))
{
connString = "server=10.74.82.230;port=3306;database=MAPO.MONO;uid=steamware;pwd=Egalware_24068!;sslmode=None;";
//connString = "server=localhost;port=3306;database=MAPO.MONO;uid=root;pwd=Egalware_24068!;sslmode=None;";
}
if (!optionsBuilder.IsConfigured)
{
var serverVersion = ServerVersion.AutoDetect(connString);
+4 -9
View File
@@ -15,23 +15,18 @@ namespace MP.MONO.Data
// se non ci fosse... crea o migra!
Database.Migrate();
}
catch (Exception exc)
catch
{ }
}
public UserIdentityDbContext(DbContextOptions<UserIdentityDbContext> options)
: base(options)
public UserIdentityDbContext(DbContextOptions<UserIdentityDbContext> options) : base(options)
{
#if false
// se non ci fosse... crea!
Database.EnsureCreated();
#endif
try
{
// se non ci fosse... crea o migra!
Database.Migrate();
}
catch (Exception exc)
catch
{ }
}
@@ -39,7 +34,7 @@ namespace MP.MONO.Data
#region Public Properties
public DbSet<TableCount> DbSetCounts { get; set; }
public DbSet<TableCount> DbSetCounts { get; set; } = null!;
#endregion Public Properties
+1 -1
View File
@@ -70,7 +70,7 @@ namespace MP.MONO.UI.Data
}
else
{
dbController = new MpDbController(configuration);
dbController = new MpDbController();
_logger.LogInformation("DbController OK");
}
}
+1 -1
View File
@@ -113,7 +113,7 @@ namespace MP.MONO.UI.Pages
{
isLoading = true;
ListRecords = null;
await Task.Delay(100);
await Task.Delay(300);
await ReloadData();
await Task.Delay(1);
await InvokeAsync(() =>