diff --git a/MP.Data/Controllers/MpSpecController.cs b/MP.Data/Controllers/MpSpecController.cs index 94b5d405..eeab53e1 100644 --- a/MP.Data/Controllers/MpSpecController.cs +++ b/MP.Data/Controllers/MpSpecController.cs @@ -294,6 +294,81 @@ namespace MP.Data.Controllers return fatto; } + /// + /// Intera tab dati macchina + /// + /// + public List DatiMacchineGetAll() + { + List dbResult = new List(); + using (var dbCtx = new MoonProContext(_configuration)) + { + dbResult = dbCtx + .DbSetDatiMacchine + .AsNoTracking() + .OrderBy(x => x.IdxMacchina) + .ToList(); + } + return dbResult; + } + /// + /// Intera vista v_MSFD + /// + /// + public List VMSFDGetAll() + { + List dbResult = new List(); + using (var dbCtx = new MoonProContext(_configuration)) + { + dbResult = dbCtx + .DbSetMSFD + .AsNoTracking() + .OrderBy(x => x.IdxMacchina) + .ToList(); + } + return dbResult; + } + + /// + /// Vista v_MSFD CALCOALTA x singola macchina (da stored) - singolo record + /// + /// + public List VMSFDGetByMacc(string idxMacc) + { + List dbResult = new List(); + using (var dbCtx = new MoonProContext(_configuration)) + { + var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacc); + + dbResult = dbCtx + .DbSetMSFD + .FromSqlRaw("exec dbo.stp_MSFD_getMacc @IdxMacchina", IdxMacchina) + .AsNoTracking() + .AsEnumerable() + .ToList(); + } + return dbResult; + } + + /// + /// Intera tabella relazione master/slave in machine (gestione setup master --> slave) + /// + /// + public List Macchine2Slave() + { + List dbResult = new List(); + using (var dbCtx = new MoonProContext(_configuration)) + { + dbResult = dbCtx + .DbSetM2S + .AsNoTracking() + .OrderBy(x => x.IdxMacchina) + .ToList(); + } + return dbResult; + } + + public void Dispose() { _configuration = null; @@ -727,7 +802,7 @@ namespace MP.Data.Controllers } } } - catch(Exception exc) + catch (Exception exc) { Log.Error($"Eccezione in MacchineGetFilt{Environment.NewLine}{exc}"); } diff --git a/MP.Data/DatabaseModels/DatiMacchineModel.cs b/MP.Data/DatabaseModels/DatiMacchineModel.cs new file mode 100644 index 00000000..329a6a1f --- /dev/null +++ b/MP.Data/DatabaseModels/DatiMacchineModel.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; + +namespace MP.Data.DatabaseModels +{ + public partial class DatiMacchineModel + { + public string IdxMacchina { get; set; } + public bool? PalletChange { get; set; } + public string CodArticoloA { get; set; } + public string CodArticoloB { get; set; } + public string SerialPort { get; set; } + public int? RefreshPeriod { get; set; } + public bool? Simulazione { get; set; } + public bool? SimplePallet { get; set; } + /// + /// definisce se l'INSERT sia abilitato per la macchina (disabilitato in fase di ricostruzione batch...) + /// + public bool? InsEnabled { get; set; } + /// + /// definisce se sia abilitata la registrazione di TUTTI gli invii di dati in ingresso da questa specifica macchina + /// + public bool SLogEnabled { get; set; } + /// + /// Abilita o meno il trigger su DiarioDiBordo x ricalcolo eventi + /// + public bool? IsTrigerDbon { get; set; } + /// + /// Indica se la macchina abbia un COUNTER (assoluto) o meno, tipicamente true x IOB-WIN, false per IOB-PI + /// + public bool HasCounter { get; set; } + } +} diff --git a/MP.Data/DatabaseModels/Macchine2SlaveModel.cs b/MP.Data/DatabaseModels/Macchine2SlaveModel.cs new file mode 100644 index 00000000..6643c7d0 --- /dev/null +++ b/MP.Data/DatabaseModels/Macchine2SlaveModel.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace MP.Data.DatabaseModels +{ + public partial class Macchine2SlaveModel + { + public string IdxMacchina { get; set; } + public string IdxMacchinaSlave { get; set; } + } +} diff --git a/MP.Data/DatabaseModels/VMSFDModel.cs b/MP.Data/DatabaseModels/VMSFDModel.cs new file mode 100644 index 00000000..f9745bbf --- /dev/null +++ b/MP.Data/DatabaseModels/VMSFDModel.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; + +namespace MP.Data.DatabaseModels +{ + public partial class VMSFDModel + { + public string IdxMacchina { get; set; } + public string Codmacchina { get; set; } + public bool PalletChange { get; set; } + public string CodArticoloA { get; set; } + public string CodArticoloB { get; set; } + public bool SimplePallet { get; set; } + public bool InsEnabled { get; set; } + public bool SLogEnabled { get; set; } + public int IdxFamigliaIngresso { get; set; } + public int Multi { get; set; } + public int BitFilt { get; set; } + public int MaxVal { get; set; } + public int Bsr { get; set; } + public bool ExplodeBit { get; set; } + public int NumBit { get; set; } + public int IdxMicroStato { get; set; } + public int IdxFamiglia { get; set; } + public int IdxStato { get; set; } + public string LastVal { get; set; } + public string CodArticolo { get; set; } + public double TempoCicloBase { get; set; } + public int PzPalletProd { get; set; } + public int MatrOpr { get; set; } + public string Pallet { get; set; } + public string CodMaccArticolo { get; set; } + } +} diff --git a/MP.Data/MoonProContext.cs b/MP.Data/MoonProContext.cs index c971d028..3df58bd2 100644 --- a/MP.Data/MoonProContext.cs +++ b/MP.Data/MoonProContext.cs @@ -56,6 +56,9 @@ namespace MP.Data public virtual DbSet DbSetVocabolario { get; set; } public virtual DbSet DbOperatori { get; set; } public virtual DbSet DbSetGrp2Macc { get; set; } + public virtual DbSet DbSetDatiMacchine { get; set; } + public virtual DbSet DbSetMSFD { get; set; } + public virtual DbSet DbSetM2S { get; set; } #endregion Public Properties @@ -322,6 +325,125 @@ namespace MP.Data }); + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.IdxMacchina); + + entity.ToTable("DatiMacchine"); + + entity.Property(e => e.IdxMacchina) + .HasMaxLength(50) + .HasColumnName("idxMacchina"); + + entity.Property(e => e.CodArticoloA) + .HasMaxLength(50) + .HasColumnName("CodArticolo_A"); + + entity.Property(e => e.CodArticoloB) + .HasMaxLength(50) + .HasColumnName("CodArticolo_B"); + + entity.Property(e => e.HasCounter) + .HasColumnName("hasCounter") + .HasComment("Indica se la macchina abbia un COUNTER (assoluto) o meno, tipicamente true x IOB-WIN, false per IOB-PI"); + + entity.Property(e => e.InsEnabled) + .HasColumnName("insEnabled") + .HasDefaultValueSql("((1))") + .HasComment("definisce se l'INSERT sia abilitato per la macchina (disabilitato in fase di ricostruzione batch...)"); + + entity.Property(e => e.IsTrigerDbon) + .IsRequired() + .HasColumnName("isTrigerDBOn") + .HasDefaultValueSql("((1))") + .HasComment("Abilita o meno il trigger su DiarioDiBordo x ricalcolo eventi"); + + entity.Property(e => e.PalletChange).HasColumnName("palletChange"); + + entity.Property(e => e.RefreshPeriod).HasColumnName("refreshPeriod"); + + entity.Property(e => e.SLogEnabled) + .HasColumnName("sLogEnabled") + .HasComment("definisce se sia abilitata la registrazione di TUTTI gli invii di dati in ingresso da questa specifica macchina"); + + entity.Property(e => e.SerialPort) + .HasMaxLength(50) + .HasColumnName("serialPort"); + + entity.Property(e => e.SimplePallet).HasColumnName("simplePallet"); + + entity.Property(e => e.Simulazione).HasColumnName("simulazione"); + }); + + + modelBuilder.Entity(entity => + { + entity.HasNoKey(); + + entity.ToView("v_MSFD"); + + entity.Property(e => e.Bsr).HasColumnName("BSR"); + + entity.Property(e => e.CodArticolo) + .IsRequired() + .HasMaxLength(50); + + entity.Property(e => e.CodArticoloA) + .IsRequired() + .HasMaxLength(50) + .HasColumnName("CodArticolo_A"); + + entity.Property(e => e.CodArticoloB) + .IsRequired() + .HasMaxLength(50) + .HasColumnName("CodArticolo_B"); + + entity.Property(e => e.CodMaccArticolo) + .IsRequired() + .HasMaxLength(103); + + entity.Property(e => e.Codmacchina) + .IsRequired() + .HasMaxLength(50) + .HasColumnName("codmacchina"); + + entity.Property(e => e.IdxMacchina) + .IsRequired() + .HasMaxLength(50) + .HasColumnName("idxmacchina"); + + entity.Property(e => e.InsEnabled).HasColumnName("insEnabled"); + + entity.Property(e => e.LastVal) + .IsRequired() + .HasMaxLength(50) + .HasColumnName("lastVal"); + + entity.Property(e => e.Pallet) + .IsRequired() + .HasMaxLength(20) + .HasColumnName("pallet"); + + entity.Property(e => e.PalletChange).HasColumnName("palletChange"); + + entity.Property(e => e.SLogEnabled).HasColumnName("sLogEnabled"); + + entity.Property(e => e.SimplePallet).HasColumnName("simplePallet"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.IdxMacchina, e.IdxMacchinaSlave }) + .HasName("PK_Macc2Slave"); + + entity.ToTable("Macchine2Slave"); + + entity.Property(e => e.IdxMacchina).HasMaxLength(50); + + entity.Property(e => e.IdxMacchinaSlave).HasMaxLength(50); + }); + + OnModelCreatingPartial(modelBuilder); } diff --git a/MP.IOC/Controllers/BenchController.cs b/MP.IOC/Controllers/BenchController.cs new file mode 100644 index 00000000..65f99f6a --- /dev/null +++ b/MP.IOC/Controllers/BenchController.cs @@ -0,0 +1,344 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using MP.IOC.Data; +using Newtonsoft.Json; +using NLog; +using NLog.Fluent; +using System.Diagnostics; + +namespace MP.IOC.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class BenchController : ControllerBase + { + public BenchController(IConfiguration configuration, MpDataService DataService) + { + Log.Info("Starting MpDataService INIT"); + _configuration = configuration; + DService = DataService; + Log.Info("Avviata classe Recipe"); + } + + private static IConfiguration _configuration = null!; + + private static Logger Log = LogManager.GetCurrentClassLogger(); + /// + /// Dataservice x accesso DB + /// + protected MpDataService DService { get; set; } + + //// GET: IOB (è un check alive) + //public string Index() + //{ + // return "OK"; + //} + + /// + /// pulizia dati + /// api/Bench/RClean?id=100 + /// + /// + /// + [HttpGet("RClean")] + public string RCLEAN(int? id) + { + string answ = "ND"; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + // se id nullo --> KO! + if (id == null) + { + answ = "KO"; + } + else + { + string chiave; + KeyValuePair[] valori = new KeyValuePair[2]; + try + { + // svuoto i precedenti hash... CICLO! + for (int i = 0; i < id; i++) + { + chiave = string.Format("test:{0}", i); + DService.RedisDelKey(chiave); + } + answ = "OK"; + } + catch + { } + } + stopWatch.Stop(); + // Get the elapsed time as a TimeSpan value. + TimeSpan ts = stopWatch.Elapsed; + // accodo tempo! + answ += $"Elapsed: {ts.TotalMilliseconds}ms"; + // ritorno + return answ; + } + /// + /// Setup dati di test hash + /// api/Bench/RSetup?id=100 + /// + /// + /// + [HttpGet("RSetup")] + public string RSETUP(int? id) + { + string answ = "ND"; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + // se id nullo --> KO! + if (id == null) + { + answ = "KO"; + } + else + { + string chiave; + KeyValuePair[] valori = new KeyValuePair[2]; + try + { + // salvo il datasetet come insieme di hash in redis... + for (int i = 0; i < id; i++) + { + chiave = string.Format("test:{0}", i); + valori[0] = new KeyValuePair("numero", i.ToString()); + valori[1] = new KeyValuePair("doppio", (i * 2).ToString()); + DService.RedisSetHash(chiave, valori); + } + answ = "OK"; + } + catch + { } + } + stopWatch.Stop(); + // Get the elapsed time as a TimeSpan value. + TimeSpan ts = stopWatch.Elapsed; + // accodo tempo! + answ += $"Elapsed: {ts.TotalMilliseconds}ms"; + // ritorno + return answ; + } + /// + /// Recupero singolo valore hash + /// api/Bench/RSingleHash?id=50 + /// + /// + /// + [HttpGet("RSingleHash")] + public string RSH(int? id) + { + string answ = "ND"; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + // se id nullo --> KO! + if (id == null) + { + answ = "KO"; + } + else + { + answ = ""; + string chiave; + KeyValuePair[] valori = new KeyValuePair[2]; + try + { + // ora restituisco record completo dell'hash con ID indicato + chiave = string.Format("test:{0}", id); + valori = DService.RedisGetHash(chiave); + foreach (var item in valori) + { + answ += string.Format("{0}|{1}
", item.Key, item.Value); + } + } + catch + { } + } + stopWatch.Stop(); + // Get the elapsed time as a TimeSpan value. + TimeSpan ts = stopWatch.Elapsed; + // accodo tempo! + answ += $"Elapsed: {ts.TotalMilliseconds}ms"; + // ritorno + return answ; + } + /// + /// Bench recupero dati macchina + /// api/Bench/DtMac?id=SIMUL_01 + /// + /// + /// + [HttpGet("DtMac")] + public string DTMAC(string id) + { + string answ = "ND"; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + // se id nullo --> KO! + if (id == null) + { + answ = "KO"; + } + else + { + answ = ""; + try + { + Dictionary valori = DService.GetCurrMSFDMacc(id); + foreach (var item in valori) + { + answ += $"{item.Key}|{item.Value}{Environment.NewLine}"; + } + } + catch + { } + } + stopWatch.Stop(); + // Get the elapsed time as a TimeSpan value. + TimeSpan ts = stopWatch.Elapsed; + // accodo tempo! + answ += $"Elapsed: {ts.TotalMilliseconds}ms"; + // ritorno + return answ; + } + //// GET BENCH/CNTKEY/KEY_NAME + //public string CNTKEY(string id) + //{ + // string answ = "ND"; + // if (id == null) id = ""; + // Stopwatch stopWatch = new Stopwatch(); + // stopWatch.Start(); + // // conto quanti oggetti DTMac ho in memoria... + // string groupHash = DataLayer.mHash(""); + // if (id.Length > 0) + // { + // groupHash += id + ":"; + // } + // groupHash += "*"; + // answ = string.Format("Trovate {0} Hash per {1}", memLayer.ML.redCountKey(groupHash), groupHash); + // stopWatch.Stop(); + // // Get the elapsed time as a TimeSpan value. + // TimeSpan ts = stopWatch.Elapsed; + // // accodo tempo! + // answ += $"Elapsed: {ts.TotalMilliseconds}ms"; + // // ritorno + // return answ; + //} + //// GET BENCH/tSMI/1 + //public string tSMI(int? id) + //{ + // string answ = "ND"; + // long splitTime = 0; + // Stopwatch stopWatch = new Stopwatch(); + // stopWatch.Start(); + // // se id nullo --> KO! + // if (id == null) + // { + // answ = "KO"; + // } + // else + // { + // int idxFamIn = Convert.ToInt32(id); + // answ = ""; + // try + // { + // KeyValuePair[] valori = DataLayerObj.mTabSMI(idxFamIn); + // splitTime = stopWatch.ElapsedMilliseconds; + // foreach (var item in valori) + // { + // answ += string.Format("{0}|{1}
", item.Key, item.Value); + // } + // } + // catch + // { } + // } + // stopWatch.Stop(); + // // Get the elapsed time as a TimeSpan value. + // TimeSpan ts = stopWatch.Elapsed; + // // accodo tempo! + // answ += string.Format("
ReadTime: {0}ms
Total Time Elapsed: {1}ms", splitTime, ts.TotalMilliseconds); + // // ritorno + // return answ; + //} + //// GET BENCH/fSMI/18?idxMS=1&valore=1 + //public string fSMI(int? id, int? idxMS, int? valore) + //{ + // string answ = "ND"; + // Stopwatch stopWatch = new Stopwatch(); + // stopWatch.Start(); + // // se id nullo --> KO! + // if (id == null) + // { + // answ = "KO"; + // } + // else + // { + // // recupero dati x sapere quale famiglia SMI è necessaria e quale stato / segnale si sia ricevuto + // int idxFamIn = Convert.ToInt32(id); + // int idxMicroStato = Convert.ToInt32(idxMS); + // int valIOB = Convert.ToInt32(valore); + // // recupero microstato macchina da chiave relativa + // answ = ""; + // try + // { + // // verifico se ci sia in memoria tab della fam macchina relativa (sennò carico) + // string fiHASH = DataLayer.hSMI(idxFamIn); + // string outVal = ""; + // bool trovato = memLayer.ML.redHashPresentSz(fiHASH); + // if (!trovato) + // { + // // ricarico tabella! + // KeyValuePair[] valori = DataLayerObj.mTabSMI(idxFamIn); + // answ = string.Format("Ricaricata SMI per famiglia {0}
", fiHASH); + // } + // answ += string.Format("Trovata {0} Hash per {1}
", memLayer.ML.redCountKey(fiHASH), fiHASH); + // // recupero singolo valore (stringa) x chiave + // outVal = DataLayerObj.valoreSMI(idxFamIn, idxMicroStato, valIOB); + // // mostro output + // answ += string.Format("idxFamIN: {0} | idxMS: {1} | valIOB: {2} | out: {3}
", idxFamIn, idxMicroStato, valIOB, outVal); + // } + // catch + // { } + // } + // stopWatch.Stop(); + // // Get the elapsed time as a TimeSpan value. + // TimeSpan ts = stopWatch.Elapsed; + // // accodo tempo! + // answ += string.Format("
Total Time Elapsed: {0}ms", ts.TotalMilliseconds); + // // ritorno + // return answ; + //} + //// GET BENCH/INSEN/2004 + //public string INSEN(string id) + //{ + // string answ = "ND"; + // Stopwatch stopWatch = new Stopwatch(); + // stopWatch.Start(); + // // se id nullo --> KO! + // if (id == null) + // { + // answ = "KO"; + // } + // else + // { + // // recupero microstato macchina da chiave relativa + // answ = ""; + // try + // { + // answ += string.Format("Macchina {0}, insEnabled {1}
", id, DataLayerObj.insEnab(id)); + // } + // catch + // { } + // } + // stopWatch.Stop(); + // // Get the elapsed time as a TimeSpan value. + // TimeSpan ts = stopWatch.Elapsed; + // // accodo tempo! + // answ += string.Format("
Total Time Elapsed: {0}ms", ts.TotalMilliseconds); + // // ritorno + // return answ; + //} + } +} diff --git a/MP.IOC/Data/MpDataService.cs b/MP.IOC/Data/MpDataService.cs index 9581d271..040ad157 100644 --- a/MP.IOC/Data/MpDataService.cs +++ b/MP.IOC/Data/MpDataService.cs @@ -71,52 +71,6 @@ namespace MP.IOC.Data #endregion Public Properties - /// - /// Init ricetta - /// - /// - /// - /// - /// - public RecipeModel InitRecipe(string confPath, int idxPODL, Dictionary CalcArgs) - { - return mongoController.InitRecipe(confPath, idxPODL, CalcArgs); - } - - /// - /// Salva ricetta su MongoDB - /// - /// - /// - public async Task RecipeSetByPODL(RecipeModel currRecord) - { - bool answ = false; - answ = await mongoController.RecipeSetByPODL(currRecord); - return answ; - } - /// - /// Ricerca ricetta su MongoDB dato PODL - /// - /// - /// - public async Task RecipeGetByPODL(int idxPODL) - { - RecipeModel? result = null; - Stopwatch stopWatch = new Stopwatch(); - stopWatch.Start(); - string readType = "MongoDB"; - result = await mongoController.RecipeGetByPODL(idxPODL); - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"RecipeGetByPODL | Read from {readType}: {ts.TotalMilliseconds}ms"); - return result; - } - - public string CalcRecipe(RecipeModel currRecipe) - { - return mongoController.CalcRecipe(currRecipe); - } - #region Public Methods /// @@ -390,6 +344,11 @@ namespace MP.IOC.Data return answ; } + public string CalcRecipe(RecipeModel currRecipe) + { + return mongoController.CalcRecipe(currRecipe); + } + public async Task> ConfigGetAll() { Stopwatch stopWatch = new Stopwatch(); @@ -439,6 +398,41 @@ namespace MP.IOC.Data return await Task.FromResult(dbController.ConfigUpdate(updRec)); } + /// + /// Elenco completo valori DatiMacchine + /// + /// + public async Task> DatiMacchineGetAll() + { + List? result = new List(); + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + string readType = "DB"; + string currKey = $"{redisBaseAddr}:TabDatiMacchine:ALL"; + // cerco in redis dato valore sel macchina... + RedisValue rawData = redisDb.StringGet(currKey); + if (rawData.HasValue) + { + result = JsonConvert.DeserializeObject>($"{rawData}"); + readType = "REDIS"; + } + else + { + result = await Task.FromResult(dbController.DatiMacchineGetAll()); + // serializzo e salvo... + rawData = JsonConvert.SerializeObject(result); + redisDb.StringSet(currKey, rawData, getRandTOut(redisLongTimeCache)); + } + if (result == null) + { + result = new List(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"DatiMacchineGetAll | Read from {readType}: {ts.TotalMilliseconds}ms"); + return result; + } + /// /// Dispose del connettore ai dati /// @@ -463,7 +457,7 @@ namespace MP.IOC.Data result = await dbController.DossiersDeleteRecord(selRecord); // elimino cache redis... RedisValue pattern = new RedisValue($"{redisDossByMac}:*"); - bool answ = await ExecFlushRedisPattern(pattern); + bool answ = await RedisFlushPatternAsync(pattern); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; Log.Debug($"DossiersDeleteRecord | IdxMacchina {selRecord.IdxMacchina} | DtRif {selRecord.DtRif} | IdxODL {selRecord.IdxODL} | {ts.TotalMilliseconds}ms"); @@ -538,7 +532,7 @@ namespace MP.IOC.Data dbController.DossiersTakeParamsSnapshotLast(IdxMacchina, dtMin, dtMax); // elimino cache redis... RedisValue pattern = new RedisValue($"{redisDossByMac}:*"); - answ = await ExecFlushRedisPattern(pattern); + answ = await RedisFlushPatternAsync(pattern); Log.Info($"Svuotata cache dossier | {pattern}"); return answ; } @@ -654,12 +648,20 @@ namespace MP.IOC.Data { await Task.Delay(1); RedisValue pattern = new RedisValue($"{redisBaseAddrSpec}*"); - bool answ = await ExecFlushRedisPattern(pattern); + bool answ = await RedisFlushPatternAsync(pattern); // rileggo vocabolario.,.. ObjVocabolario = VocabolarioGetAll(); return answ; } + public async Task FlushRedisKey(string redKey) + { + await Task.Delay(1); + RedisValue pattern = new RedisValue($"{redisBaseAddrSpec}:{redKey}"); + bool answ = await RedisFlushPatternAsync(pattern); + return answ; + } + /// /// Elenco ultimi n record flux log dato macchina e flusso (ordinato x data registrazione) /// @@ -716,6 +718,84 @@ namespace MP.IOC.Data return Task.FromResult(currTagConf); } + /// + /// Restitusice elenco KVP dei campi DatiMacchine + StatoMacchine per l'impianto indicato + /// + /// + /// + public Dictionary GetCurrMSFDMacc(string idxMacc) + { + Dictionary? result = new Dictionary(); + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + string readType = "DB"; + string currKey = $"{redisBaseAddr}:DSMacc:{idxMacc}"; + // cerco in redis dato valore sel macchina... + RedisValue rawData = redisDb.StringGet(currKey); + if (rawData.HasValue) + { + result = JsonConvert.DeserializeObject>($"{rawData}"); + readType = "REDIS"; + } + else + { + var dbResults = dbController.VMSFDGetByMacc(idxMacc); + // converto in formato dizionario... + if (dbResults != null && dbResults.Count > 0) + { + var rowResult = dbResults[0]; + // salvo 1:1 i valori... STATO + result.Add("IdxMicroStato", $"{rowResult.IdxMicroStato}"); + result.Add("IdxStato", $"{rowResult.IdxStato}"); + result.Add("CodArticolo", $"{rowResult.CodArticolo}"); + result.Add("insEnabled", $"{rowResult.InsEnabled}"); + result.Add("sLogEnabled", $"{rowResult.SLogEnabled}"); + result.Add("pallet", $"{rowResult.Pallet}"); + result.Add("CodArticolo_A", $"{rowResult.CodArticoloA}"); + result.Add("CodArticolo_B", $"{rowResult.CodArticoloB}"); + result.Add("TempoCicloBase", $"{rowResult.TempoCicloBase}"); + result.Add("PzPalletProd", $"{rowResult.PzPalletProd}"); + result.Add("MatrOpr", $"{rowResult.MatrOpr}"); + result.Add("lastVal", $"{rowResult.LastVal}"); + result.Add("TCBase", $"{rowResult.TempoCicloBase}"); + + //...e SETUP + result.Add("CodMacc", $"{rowResult.Codmacchina}"); + result.Add("IdxFamIn", $"{rowResult.IdxFamigliaIngresso}"); + result.Add("Multi", $"{rowResult.Multi}"); + result.Add("BitFilt", $"{rowResult.BitFilt}"); + result.Add("MaxVal", $"{rowResult.MaxVal}"); + result.Add("BSR", $"{rowResult.Bsr}"); + result.Add("ExplodeBit", $"{rowResult.ExplodeBit}"); + result.Add("NumBit", $"{rowResult.NumBit}"); + result.Add("IdxFamMacc", $"{rowResult.IdxFamiglia}"); + result.Add("simplePallet", $"{rowResult.SimplePallet}"); + result.Add("palletChange", $"{rowResult.PalletChange}"); + } + // cerco info Master/slave... + var m2sTab = Macchine2SlaveGetAll(); + string isMaster = m2sTab.Where(x => x.IdxMacchina == idxMacc).Count() > 0 ? "1" : "0"; + string isSlave = m2sTab.Where(x => x.IdxMacchinaSlave == idxMacc).Count() > 0 ? "1" : "0"; + result.Add("Master", isMaster); + result.Add("Slave", isSlave); + + // serializzo + rawData = JsonConvert.SerializeObject(result); + // durata cache secondo valore insEnabled... + double numMinCache = (result["insEnabled"].ToLower() == "true") ? redisShortTimeCache / 4 : redisShortTimeCache; + // ...e salvo... + redisDb.StringSet(currKey, rawData, getRandTOut(numMinCache)); + } + if (result == null) + { + result = new Dictionary(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"GetCurrMSFDMacc | Read from {readType}: {ts.TotalMilliseconds}ms"); + return result; + } + public List getFluxLog(string Valore) { List answ = new List(); @@ -755,6 +835,18 @@ namespace MP.IOC.Data return outVal; } + /// + /// Init ricetta + /// + /// + /// + /// + /// + public RecipeModel InitRecipe(string confPath, int idxPODL, Dictionary CalcArgs) + { + return mongoController.InitRecipe(confPath, idxPODL, CalcArgs); + } + /// /// /// id odl da cercare @@ -913,6 +1005,41 @@ namespace MP.IOC.Data return result; } + /// + /// Elenco completo valori Macchine 2 Slave + /// + /// + public List Macchine2SlaveGetAll() + { + List? result = new List(); + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + string readType = "DB"; + string currKey = $"{redisBaseAddr}:M2STab"; + // cerco in redis dato valore sel macchina... + RedisValue rawData = redisDb.StringGet(currKey); + if (rawData.HasValue) + { + result = JsonConvert.DeserializeObject>($"{rawData}"); + readType = "REDIS"; + } + else + { + result = dbController.Macchine2Slave(); + // serializzo e salvo... + rawData = JsonConvert.SerializeObject(result); + redisDb.StringSet(currKey, rawData, getRandTOut(redisLongTimeCache)); + } + if (result == null) + { + result = new List(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"Macchine2SlaveGetAll | Read from {readType}: {ts.TotalMilliseconds}ms"); + return result; + } + /// /// Elenco di tutte le macchine gestite /// @@ -1322,7 +1449,7 @@ namespace MP.IOC.Data var dbResult = await dbController.PODLDeleteRecord(currRec); // elimino cache redis... RedisValue pattern = new RedisValue($"{redisXdlData}:*"); - bool answ = await ExecFlushRedisPattern(pattern); + bool answ = await RedisFlushPatternAsync(pattern); await Task.Delay(1); return dbResult; } @@ -1337,7 +1464,7 @@ namespace MP.IOC.Data var dbResult = await dbController.PODL_startSetup(currRec, 0, 1, 1, ""); // elimino cache redis... RedisValue pattern = new RedisValue($"{redisXdlData}:*"); - bool answ = await ExecFlushRedisPattern(pattern); + bool answ = await RedisFlushPatternAsync(pattern); await Task.Delay(1); return dbResult; } @@ -1352,11 +1479,149 @@ namespace MP.IOC.Data var dbResult = await dbController.PODLUpdateRecord(currRec); // elimino cache redis... RedisValue pattern = new RedisValue($"{redisXdlData}:*"); - bool answ = await ExecFlushRedisPattern(pattern); + bool answ = await RedisFlushPatternAsync(pattern); await Task.Delay(1); return dbResult; } + /// + /// Ricerca ricetta su MongoDB dato PODL + /// + /// + /// + public async Task RecipeGetByPODL(int idxPODL) + { + RecipeModel? result = null; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + string readType = "MongoDB"; + result = await mongoController.RecipeGetByPODL(idxPODL); + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"RecipeGetByPODL | Read from {readType}: {ts.TotalMilliseconds}ms"); + return result; + } + + /// + /// Salva ricetta su MongoDB + /// + /// + /// + public async Task RecipeSetByPODL(RecipeModel currRecord) + { + bool answ = false; + answ = await mongoController.RecipeSetByPODL(currRecord); + return answ; + } + + /// + /// Esegue eliminazione memoria redis keyVal + /// + /// + /// + public bool RedisDelKey(string keyVal) + { + bool answ = false; + var listEndpoints = redisConnAdmin.GetEndPoints(); + foreach (var endPoint in listEndpoints) + { + //var server = redisConnAdmin.GetServer(listEndpoints[0]); + var server = redisConnAdmin.GetServer(endPoint); + if (server != null) + { + redisDb.KeyDelete((RedisKey)keyVal); + answ = true; + } + } + return answ; + } + + /// + /// Esegue flush memoria redis dato keyVal + /// + /// + /// + public bool RedisFlushPattern(RedisValue pattern) + { + bool answ = false; + var listEndpoints = redisConnAdmin.GetEndPoints(); + foreach (var endPoint in listEndpoints) + { + //var server = redisConnAdmin.GetServer(listEndpoints[0]); + var server = redisConnAdmin.GetServer(endPoint); + if (server != null) + { + var keyList = server.Keys(redisDb.Database, pattern); + foreach (var item in keyList) + { + redisDb.KeyDelete(item); + } + // brutalmente rimuovo intero contenuto DB... DANGER + //await server.FlushDatabaseAsync(); + answ = true; + } + } + return answ; + } + + /// + /// Esegue flush memoria redis dato keyVal, async + /// + /// + /// + public async Task RedisFlushPatternAsync(RedisValue pattern) + { + bool answ = false; + var listEndpoints = redisConnAdmin.GetEndPoints(); + foreach (var endPoint in listEndpoints) + { + //var server = redisConnAdmin.GetServer(listEndpoints[0]); + var server = redisConnAdmin.GetServer(endPoint); + if (server != null) + { + var keyList = server.Keys(redisDb.Database, pattern); + foreach (var item in keyList) + { + await redisDb.KeyDeleteAsync(item); + } + answ = true; + } + } + return answ; + } + + public KeyValuePair[] RedisGetHash(string redKey) + { + HashEntry[] rawData = redisDb.HashGetAll($"{redisBaseAddrSpec}:{redKey}"); + var result = rawData.Where(x => !x.Name.IsNull).Select(x => new KeyValuePair(x.Name, x.Value)).ToArray(); + return result; + } + + public async Task[]> RedisGetHashAsync(string redKey) + { + HashEntry[] rawData = await redisDb.HashGetAllAsync($"{redisBaseAddrSpec}:{redKey}"); + var result = rawData.Where(x => !x.Name.IsNull).Select(x => new KeyValuePair(x.Name, x.Value)).ToArray(); + return result; + } + + public bool RedisSetHash(string redKey, KeyValuePair[] valori) + { + bool answ = false; + string rKey = $"{redisBaseAddrSpec}:{redKey}"; + HashEntry[] redHash = valori.Select(x => new HashEntry(x.Key, x.Value)).ToArray(); + redisDb.HashSet(rKey, redHash); + answ = true; + return answ; + } + + public async Task SetRedisKey(string redKey, string redVal) + { + await Task.Delay(1); + RedisValue pattern = new RedisValue($"{redisBaseAddrSpec}:{redKey}"); + bool answ = redisDb.StringSet(redKey, redVal); + return answ; + } + /// /// Statistiche ODL calcolate (da stored stp_STAT_ODL) /// @@ -1503,9 +1768,9 @@ namespace MP.IOC.Data /// /// /// - protected TimeSpan getRandTOut(int stdMinutes) + protected TimeSpan getRandTOut(double stdMinutes) { - double rndValue = (double)stdMinutes + (double)rand.Next(1, 60) / 60; + double rndValue = stdMinutes + (double)rand.Next(1, 60) / 60; return TimeSpan.FromMinutes(rndValue); } @@ -1544,14 +1809,11 @@ namespace MP.IOC.Data private const string redisPOdlByOdl = redisXdlData + "POdlByOdl"; private const string redisPOdlByPOdl = redisXdlData + "POdlByPOdl"; private const string redisPOdlList = redisXdlData + "POdlList"; + private const string redisRecipeConf = redisBaseAddrSpec + "Cache:Recipe:Conf"; private const string redisStatoCom = redisBaseAddrSpec + "Cache:StatoCom"; private const string redisTipoArt = redisBaseAddrSpec + "Cache:TipoArt"; private const string redisVocabolario = redisBaseAddrSpec + "Cache:Vocabolario"; private const string redisXdlData = redisBaseAddrSpec + "Cache:XDL:"; - - private const string redisRecipeConf = redisBaseAddrSpec + "Cache:Recipe:Conf"; - - private static IConfiguration _configuration = null!; private static ILogger _logger = null!; @@ -1578,47 +1840,18 @@ namespace MP.IOC.Data private IDatabase redisDb = null!; private int redisLongTimeCache = 5; - private int redisShortTimeCache = 4; + private int redisShortTimeCache = 2; #endregion Private Fields #region Private Methods - /// - /// Esegue flush memoria redis dato pattern - /// - /// - /// - private async Task ExecFlushRedisPattern(RedisValue pattern) - { - bool answ = false; - var listEndpoints = redisConnAdmin.GetEndPoints(); - foreach (var endPoint in listEndpoints) - { - //var server = redisConnAdmin.GetServer(listEndpoints[0]); - var server = redisConnAdmin.GetServer(endPoint); - if (server != null) - { - var keyList = server.Keys(redisDb.Database, pattern); - foreach (var item in keyList) - { - await redisDb.KeyDeleteAsync(item); - } - // brutalmente rimuovo intero contenuto DB... DANGER - //await server.FlushDatabaseAsync(); - answ = true; - } - } - - return answ; - } - private async Task resetCacheArticoli() { RedisValue pattern = new RedisValue($"{redisArtByDossier}:*"); - await ExecFlushRedisPattern(pattern); + await RedisFlushPatternAsync(pattern); pattern = new RedisValue($"{redisArtList}:*"); - await ExecFlushRedisPattern(pattern); + await RedisFlushPatternAsync(pattern); } #endregion Private Methods diff --git a/MP.IOC/MP.IOC.csproj b/MP.IOC/MP.IOC.csproj index d421005b..835fde66 100644 --- a/MP.IOC/MP.IOC.csproj +++ b/MP.IOC/MP.IOC.csproj @@ -12,6 +12,10 @@ <_WebToolingArtifacts Remove="Properties\PublishProfiles\IIS03.pubxml" /> + + + + diff --git a/MP.IOC/Program.cs b/MP.IOC/Program.cs index fd8e2884..6bfc3270 100644 --- a/MP.IOC/Program.cs +++ b/MP.IOC/Program.cs @@ -33,6 +33,10 @@ app.UseHttpsRedirection(); app.UseAuthorization(); +// aggiunta x index.html +app.UseDefaultFiles(); +app.UseStaticFiles(); + app.MapControllers(); app.Run(); diff --git a/MP.IOC/Resources/ChangeLog.html b/MP.IOC/Resources/ChangeLog.html index 07199d7e..36f3e633 100644 --- a/MP.IOC/Resources/ChangeLog.html +++ b/MP.IOC/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MP-IOC -

Versione: 6.16.2302.1417

+

Versione: 6.16.2302.1513


Note di rilascio:
  • diff --git a/MP.IOC/Resources/VersNum.txt b/MP.IOC/Resources/VersNum.txt index a30e9552..c3581cf7 100644 --- a/MP.IOC/Resources/VersNum.txt +++ b/MP.IOC/Resources/VersNum.txt @@ -1 +1 @@ -6.16.2302.1417 +6.16.2302.1513 diff --git a/MP.IOC/Resources/manifest.xml b/MP.IOC/Resources/manifest.xml index 06315e50..74a91bbc 100644 --- a/MP.IOC/Resources/manifest.xml +++ b/MP.IOC/Resources/manifest.xml @@ -1,6 +1,6 @@ - 6.16.2302.1417 + 6.16.2302.1513 https://nexus.steamware.net/repository/SWS/MP-SPEC/stable/LAST/MP.SPEC.zip https://nexus.steamware.net/repository/SWS/MP-SPEC/stable/LAST/ChangeLog.html false diff --git a/MP.IOC/libman.json b/MP.IOC/libman.json new file mode 100644 index 00000000..1a0be4d3 --- /dev/null +++ b/MP.IOC/libman.json @@ -0,0 +1,16 @@ +{ + "version": "1.0", + "defaultProvider": "cdnjs", + "libraries": [ + { + "provider": "cdnjs", + "library": "font-awesome@6.1.1", + "destination": "wwwroot/lib/font-awesome/" + }, + { + "provider": "cdnjs", + "library": "bootstrap@5.2.3", + "destination": "wwwroot/lib/bootstrap/" + } + ] +} \ No newline at end of file