From da6e3a77f414def0376bb3f795c4bc8d9a91c7d4 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Tue, 1 Mar 2022 08:56:34 +0100 Subject: [PATCH] modifica x invio dati ULog x iobGen + iobSim --- IOB-WIN-NEXT/IobGeneric.cs | 252 +++++++++++++++++++------------------ IOB-WIN-NEXT/IobSimula.cs | 71 ++++++----- 2 files changed, 167 insertions(+), 156 deletions(-) diff --git a/IOB-WIN-NEXT/IobGeneric.cs b/IOB-WIN-NEXT/IobGeneric.cs index 89702448..75198d69 100644 --- a/IOB-WIN-NEXT/IobGeneric.cs +++ b/IOB-WIN-NEXT/IobGeneric.cs @@ -1069,16 +1069,16 @@ namespace IOB_WIN_NEXT /// public int counterFLog { get; set; } - /// - /// Contatore x invio dati UserLog - /// - public int counterULog { get; set; } - /// /// Contatore x invio dati SignalIN /// public int counterSigIN { get; set; } + /// + /// Contatore x invio dati UserLog + /// + public int counterULog { get; set; } + /// /// Verifica se sia in modalità DEMO --> da tipo IOB SIMULA... /// @@ -2183,36 +2183,26 @@ namespace IOB_WIN_NEXT { if (IobOnline) { - // se ho + di 2 elementi in coda --> uso invio JSON in blocco... - if (QueueULog.Count > 1) + List listaValori = new List(); + // se ho + di maxJsonData elementi --> invio un set di dati alla volta + if (QueueULog.Count > maxJsonData) { - List listaValori = new List(); - // se ho + di maxJsonData elementi --> invio un set di dati alla volta - if (QueueULog.Count > maxJsonData) + // prendoi primi maxJsonDataValori + for (int j = 0; j < maxJsonData; j++) { - // prendoi primi maxJsonDataValori - for (int j = 0; j < maxJsonData; j++) - { - QueueULog.TryDequeue(out currVal); - listaValori.Add(currVal); - } - sendDataBlock(urlType.ULog, listaValori); - } - else - { - // invio in blocco - listaValori = QueueULog.ToList(); - // invio - sendDataBlock(urlType.ULog, listaValori); - // svuoto! - QueueULog = new ConcurrentQueue(); + QueueULog.TryDequeue(out currVal); + listaValori.Add(currVal); } + sendDataBlock(urlType.ULog, listaValori); } else { - // INVIO SINGOLO...!!! - QueueULog.TryDequeue(out currVal); - sendToMoonPro(urlType.ULog, currVal); + // invio in blocco + listaValori = QueueULog.ToList(); + // invio + sendDataBlock(urlType.ULog, listaValori); + // svuoto! + QueueULog = new ConcurrentQueue(); } } else @@ -2540,6 +2530,38 @@ namespace IOB_WIN_NEXT return answ; } + /// + /// Effettua logging DEBUG corretto impostanto anche la variabile IOB prima di scrivere... + /// + /// + protected void lgDebug(string message, bool sendToForm = true) + { + //if (isVerboseLog) + //{ + lg.Factory.Configuration.Variables["codIOB"] = cIobConf.codIOB; + lg.Debug(message); + if (sendToForm) + { + sendToLogWatch("DEBUG", message); + } + //} + } + + /// + /// Effettua logging DEBUG corretto impostanto anche la variabile IOB prima di scrivere... + /// + /// + /// + protected void lgDebug(string message, params object[] args) + { + //if (isVerboseLog) + //{ + lg.Factory.Configuration.Variables["codIOB"] = cIobConf.codIOB; + lg.Debug(message, args); + sendToLogWatch("DEBUG", message, args); + //} + } + /// /// Effettua logging ERROR corretto impostanto anche la variabile IOB prima di scrivere... /// @@ -2669,36 +2691,6 @@ namespace IOB_WIN_NEXT lg.Trace(message, args); sendToLogWatch("INFO", message, args); } - /// - /// Effettua logging DEBUG corretto impostanto anche la variabile IOB prima di scrivere... - /// - /// - protected void lgDebug(string message, bool sendToForm = true) - { - //if (isVerboseLog) - //{ - lg.Factory.Configuration.Variables["codIOB"] = cIobConf.codIOB; - lg.Debug(message); - if (sendToForm) - { - sendToLogWatch("DEBUG", message); - } - //} - } - /// - /// Effettua logging DEBUG corretto impostanto anche la variabile IOB prima di scrivere... - /// - /// - /// - protected void lgDebug(string message, params object[] args) - { - //if (isVerboseLog) - //{ - lg.Factory.Configuration.Variables["codIOB"] = cIobConf.codIOB; - lg.Debug(message, args); - sendToLogWatch("DEBUG", message, args); - //} - } /// /// Legge il file di conf di una MAP di informazioni da gestire con lettura set memoria @@ -3289,28 +3281,6 @@ namespace IOB_WIN_NEXT } } - - - /// - /// Accumula in coda i valori USER LOG e logga... - /// - /// VALORE RAW (x display) - /// VALORE già processato con qEncodeULog(...) - public void accodaUserLog(string val, string encodedVal) - { - // mostro dati variati letti... - displayOtherData(val); - // accodo IN PRIMIS al FluxLog --> accodo (valore già formattato)! - QueueULog.Enqueue(encodedVal); - - // loggo! - lgInfo(string.Format("[QUEUE-USER-LOG] {0}", encodedVal)); - counterULog++; - if (counterULog > 9999) - { - counterFLog = 0; - } - } /// /// Accumula in coda i valori Flux Log e logga... /// @@ -3384,6 +3354,27 @@ namespace IOB_WIN_NEXT } } + /// + /// Accumula in coda i valori USER LOG e logga... + /// + /// VALORE RAW (x display) + /// VALORE già processato con qEncodeULog(...) + public void accodaUserLog(string val, string encodedVal) + { + // mostro dati variati letti... + displayOtherData(val); + // accodo IN PRIMIS al FluxLog --> accodo (valore già formattato)! + QueueULog.Enqueue(encodedVal); + + // loggo! + lgInfo(string.Format("[QUEUE-USER-LOG] {0}", encodedVal)); + counterULog++; + if (counterULog > 9999) + { + counterFLog = 0; + } + } + /// /// Update visualizzaizone BIT in ingresso /// Parametri da aggiornare x display in form @@ -4010,6 +4001,7 @@ namespace IOB_WIN_NEXT lgError($"FLog Errore in costruzione jsonPayload:{Environment.NewLine}{exc}"); } break; + case urlType.SignIN: evData currSigData = new evData(); evJsonPayload fullEvObj = new evJsonPayload(); @@ -4040,7 +4032,10 @@ namespace IOB_WIN_NEXT lgError($"SignIN Errore in costruzione jsonPayload:{Environment.NewLine}{exc}"); } break; + case urlType.ULog: + int numVal = 0; + int matrOp = 0; ulogData currUlData = new ulogData(); ulogJsonPayload fullUlObj = new ulogJsonPayload(); fullUlObj.fluxData = new List(); @@ -4050,14 +4045,19 @@ namespace IOB_WIN_NEXT valori = qDecodeIN(item); CultureInfo provider = CultureInfo.InvariantCulture; DateTime.TryParseExact(valori[0], "yyyyMMddHHmmssfff", provider, DateTimeStyles.AssumeLocal, out dtEve); - int.TryParse(valori[3], out counter); + int.TryParse(valori[3], out matrOp); + int.TryParse(valori[5], out numVal); + int.TryParse(valori[6], out counter); currUlData = new ulogData() { flux = valori[1], valore = valori[2], dtEve = dtEve, dtCurr = DateTime.Now, - cnt = counter + cnt = counter, + matrOpr = matrOp, + label = valori[4], + valNum = numVal }; fullUlObj.fluxData.Add(currUlData); } @@ -4071,6 +4071,7 @@ namespace IOB_WIN_NEXT lgError($"ULog Errore in costruzione jsonPayload:{Environment.NewLine}{exc}"); } break; + default: break; } @@ -4643,27 +4644,12 @@ namespace IOB_WIN_NEXT } /// - /// Fornisce il valore di flusso e valore in formato valido x messa in coda nel formato dtEve#flux#value#cont + /// Fornisce il valore di flusso e valore in formato valido x messa in coda nel formato + /// dtEve#flusso#valore#cont /// Flusso dati /// Valore da salvare /// public string qEncodeFLog(string flusso, string valore) - { - string answ = ""; - try - { - answ = string.Format("{0:yyyyMMddHHmmssfff}#{1}#{2}#{3}", DateTime.Now, flusso, valore, counterFLog); - } - catch - { } - return answ; - } - /// - /// Fornisce il valore di UserLog e valore in formato valido x messa in coda nel formato dtEve#flux#value#cont - /// Flusso dati (RC/RS/DI) - /// Valore da inviare - /// - public string qEncodeULog(string flusso, string valore) { string answ = ""; try @@ -4686,7 +4672,28 @@ namespace IOB_WIN_NEXT string answ = ""; try { - answ = string.Format("{0:yyyyMMddHHmmssfff}#{1}#{2}#{3}", eventDT, flusso, valore, counterFLog); + answ = $"{eventDT:yyyyMMddHHmmssfff}#{flusso}#{valore}#{counterFLog}"; + } + catch + { } + return answ; + } + + /// + /// Fornisce il valore di UserLog e valore in formato valido x messa in coda nel formato: + /// dtEve#flusso#value#cont#matrOpr#label#valNum + /// Flusso dati (RC/RS/DI) + /// Valore da inviare (valString + /// Matricola operatore + /// Valore etichetta: causale scarto / tagCode + /// Valore numerico: esitoOk (0/1) / nuo scarti + /// + public string qEncodeULog(string flusso, string valore, int matrOpr, string label, int valNum) + { + string answ = ""; + try + { + answ = $"{DateTime.Now:yyyyMMddHHmmssfff}#{flusso}#{valore}#{matrOpr}#{label}#{valNum}#{counterULog}"; } catch { } @@ -4993,10 +5000,6 @@ namespace IOB_WIN_NEXT lastUrl = urlInput(queueVal); break; - case urlType.ULog: - lastUrl = urlULog(queueVal); - break; - default: lastUrl = ""; break; @@ -5404,12 +5407,15 @@ namespace IOB_WIN_NEXT case urlType.FLog: tipoComando = cIobConf.serverData.CMDFLOG_JSON; break; + case urlType.SignIN: tipoComando = cIobConf.serverData.CMDBASE_JSON; break; + case urlType.ULog: tipoComando = cIobConf.serverData.CMDULOG_JSON; break; + default: break; } @@ -5436,24 +5442,6 @@ namespace IOB_WIN_NEXT return answ; } - /// - /// Fornisce URL di tipo UserLog - /// - /// valore salvato in coda nel formato dtEve#flux#valore#counter - /// - public string urlULog(string queueVal) - { - // URL base x input - string answ = $@"{cIobConf.serverData.TRANSP}://{cIobConf.serverData.MPIP}{cIobConf.serverData.MPURL}{cIobConf.serverData.CMDULOG}"; - // decodifica valore! - string[] valori = qDecodeIN(queueVal); - // aggiungo macchina e valore... - answ += string.Format(@"{0}?flux={1}&&valore={2}", cIobConf.codIOB, valori[1], valori[2]); - // aggiondo dataOra evento e corrente + contatore... - answ += string.Format(@"&&dtEve={0}&&dtCurr={1:yyyyMMddHHmmssfff}&&cnt={2}", valori[0], DateTime.Now, valori[3]); - return answ; - } - /// /// Fornisce URL INPUT per i parametri richiesti /// @@ -5472,6 +5460,24 @@ namespace IOB_WIN_NEXT return answ; } + /// + /// Fornisce URL di tipo UserLog + /// + /// valore salvato in coda nel formato dtEve#flux#valore#counter + /// + public string urlULog(string queueVal) + { + // URL base x input + string answ = $@"{cIobConf.serverData.TRANSP}://{cIobConf.serverData.MPIP}{cIobConf.serverData.MPURL}{cIobConf.serverData.CMDULOG}"; + // decodifica valore! + string[] valori = qDecodeIN(queueVal); + // aggiungo macchina e valore... + answ += string.Format(@"{0}?flux={1}&&valore={2}", cIobConf.codIOB, valori[1], valori[2]); + // aggiondo dataOra evento e corrente + contatore... + answ += string.Format(@"&&dtEve={0}&&dtCurr={1:yyyyMMddHHmmssfff}&&cnt={2}", valori[0], DateTime.Now, valori[3]); + return answ; + } + #endregion Public Methods } diff --git a/IOB-WIN-NEXT/IobSimula.cs b/IOB-WIN-NEXT/IobSimula.cs index 22d98a7e..2c4046a6 100644 --- a/IOB-WIN-NEXT/IobSimula.cs +++ b/IOB-WIN-NEXT/IobSimula.cs @@ -45,26 +45,6 @@ namespace IOB_WIN_NEXT /// protected int cP = 1; - /// - /// Simulazione effettuazione controlli utente - /// - protected simPar simRC; - - /// - /// Simulazione registro scarti utente - /// - protected simPar simRS; - - /// - /// Simulazione registrazione dichiarazioni utente - /// - protected simPar simDich; - - /// - /// Matricola OPR simulato - /// - protected int matrOpr = 1; - protected bool disableSimStatus = false; /// @@ -77,6 +57,11 @@ namespace IOB_WIN_NEXT /// protected DateTime lastSimData; + /// + /// Matricola OPR simulato + /// + protected int matrOpr = 1; + /// /// Durata minima ODL x reset quando pezzi iob > pezzi macchina... /// @@ -97,11 +82,26 @@ namespace IOB_WIN_NEXT /// protected bool sigPzCount = false; + /// + /// Simulazione registrazione dichiarazioni utente + /// + protected simPar simDich; + /// /// BOOL: indica se simulare powerOn/Off (bit 0 e 1) compresi WarmUp e CoolDown /// protected bool simPowerOnOff; + /// + /// Simulazione effettuazione controlli utente + /// + protected simPar simRC; + + /// + /// Simulazione registro scarti utente + /// + protected simPar simRS; + /// /// Tempo di MINIMO attesa x simulazione parametri /// @@ -503,11 +503,11 @@ namespace IOB_WIN_NEXT { // preparo record controlli... guasto se mi esce un secondo divisibile x 25 DateTime adesso = DateTime.Now; - bool esitoOk = adesso.Second % 25 == 0 ? false : true; - string note = esitoOk ? "" : $"SIM Controllo fallito alle {DateTime.Now:yyyy-MM-dd HH:mm:ss}"; - string sVal = $"MatrOpr: {matrOpr} | Esito: {esitoOk} | note: {note}"; + int esitoNum = adesso.Second % 25 == 0 ? 0 : 1; + string note = esitoNum == 1 ? "" : $"SIM Controllo fallito alle {DateTime.Now:yyyy-MM-dd HH:mm:ss}"; + string sVal = $"MatrOpr: {matrOpr} | Esito: {esitoNum} | note: {note}"; // accodo x invio - accodaUserLog(sVal, qEncodeULog("RC", $"{esitoOk}|{note}")); + accodaUserLog(sVal, qEncodeULog("RC", note, matrOpr, "", esitoNum)); // decremento duration simRC.duration--; // controllo se sia scaduta la duration... in quel caso reset... @@ -520,11 +520,13 @@ namespace IOB_WIN_NEXT { // preparo record controlli... guasto se mi esce un secondo divisibile x 25 DateTime adesso = DateTime.Now; - int causale = adesso.Second % 5; - string note = $"SIM Scarto alle {DateTime.Now:yyyy-MM-dd HH:mm:ss} | causale: {causale}"; + int causaleInt = adesso.Second % 7 + 1; + int numSca = adesso.Second % 5 + 1; + string causale = $"{causaleInt:00}"; + string note = $"SIM Scarto [{causale} x {numSca}] {DateTime.Now:yyyy-MM-dd HH:mm:ss}"; string sVal = $"MatrOpr: {matrOpr} | Causale: {causale} | note: {note}"; // accodo x invio - accodaUserLog(sVal, qEncodeULog("RS", $"{causale:00}|{note}")); + accodaUserLog(sVal, qEncodeULog("RS", note, matrOpr, causale, numSca)); // decremento duration simRS.duration--; // controllo se sia scaduta la duration... in quel caso reset... @@ -535,13 +537,14 @@ namespace IOB_WIN_NEXT } if (simDich.wait <= 0) { - // preparo record controlli... guasto se mi esce un secondo divisibile x 25 + // preparo record dichiarazione... DateTime adesso = DateTime.Now; - bool esitoOk = adesso.Second % 25 == 0 ? false : true; - string note = esitoOk ? "" : $"SIM Nota automatica alle {DateTime.Now:yyyy-MM-dd HH:mm:ss}"; - string sVal = $"MatrOpr: {matrOpr} | Esito: {esitoOk} | note: {note}"; + bool recLogin = adesso.Second % 5 == 0 ? false : true; + string note = recLogin ? "SIM Login Utente STEAMWARE USER" : $"SIM Nota automatica alle {DateTime.Now:yyyy-MM-dd HH:mm:ss}"; + string codTag = recLogin ? "UserLogin" : "Note"; + string sVal = $"MatrOpr: {matrOpr} | codTag: {codTag} | note: {note}"; // accodo x invio - accodaUserLog(sVal, qEncodeULog("DI", $"{esitoOk}|{note}")); + accodaUserLog(sVal, qEncodeULog("DI", note, matrOpr, codTag, 0)); // decremento duration simDich.duration--; // controllo se sia scaduta la duration... in quel caso reset... @@ -551,7 +554,6 @@ namespace IOB_WIN_NEXT } } - // init obj display newDisplayData currDispData = new newDisplayData(); currDispData.counter = contapezziIOB; @@ -883,6 +885,9 @@ namespace IOB_WIN_NEXT bit3.wait--; bit4.wait--; bit5.wait--; + simDich.wait--; + simRC.wait--; + simRS.wait--; lastEvCheck = DateTime.Now; } }