From 789defb69dad6c4fc8cecfde3326a9719b1bf3bc Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Fri, 21 Apr 2023 15:14:37 +0200 Subject: [PATCH] update x acquisizione logtable da SOITAAB --- IOB-WIN-NEXT/DATA/CONF/IMI_SOITAAB_Z2342.json | 7 +- .../DATA/CONF/Tend_FIMAT_01__bck.json | 324 ------------------ IOB-WIN-NEXT/IOB-WIN-NEXT.csproj | 3 - IOB-WIN-NEXT/IobSqlServLantek.cs | 119 +++++-- IOB-WIN-NEXT/IobSqlServPama.cs | 6 +- 5 files changed, 106 insertions(+), 353 deletions(-) delete mode 100644 IOB-WIN-NEXT/DATA/CONF/Tend_FIMAT_01__bck.json diff --git a/IOB-WIN-NEXT/DATA/CONF/IMI_SOITAAB_Z2342.json b/IOB-WIN-NEXT/DATA/CONF/IMI_SOITAAB_Z2342.json index 898e2595..5e868603 100644 --- a/IOB-WIN-NEXT/DATA/CONF/IMI_SOITAAB_Z2342.json +++ b/IOB-WIN-NEXT/DATA/CONF/IMI_SOITAAB_Z2342.json @@ -1,6 +1,5 @@ { "mMapWrite": { - }, "mMapRead": { //"TotMerceProcTonn": { @@ -25,5 +24,9 @@ // "period": 60, // "factor": 1 //} + }, + "optKVP": { + "path-remBase": "C:\\Temp" + //"path-remBase": "\\\\ecs900\\Logs" } -} +} \ No newline at end of file diff --git a/IOB-WIN-NEXT/DATA/CONF/Tend_FIMAT_01__bck.json b/IOB-WIN-NEXT/DATA/CONF/Tend_FIMAT_01__bck.json deleted file mode 100644 index e2db329f..00000000 --- a/IOB-WIN-NEXT/DATA/CONF/Tend_FIMAT_01__bck.json +++ /dev/null @@ -1,324 +0,0 @@ -{ - "mMapWrite": { }, - "mMapRead": { - "StatoMacchina": { - "name": "StatoMacchina", - "description": "Stato della Macchina", - "memAddr": "40001", - "tipoMem": "Int", - "index": 1, - "size": 1, - "func": "MAX", - "period": 90, - "factor": 1, - "minVal": 0, - "maxVal": 10, - "unit": "#" - }, - "ElencoAnomalie": { - "name": "ElencoAnomalie", - "description": "Elenco Anomalie", - "memAddr": "40002", - "tipoMem": "Int", - "index": 2, - "size": 1, - "func": "MAX", - "period": 90, - "factor": 1, - "minVal": 0, - "maxVal": 10, - "unit": "#" - }, - "ElencoAttivita": { - "name": "ElencoAttivita", - "description": "Elenco Attivita", - "memAddr": "40003", - "tipoMem": "Int", - "index": 3, - "size": 1, - "func": "MAX", - "period": 90, - "factor": 1, - "minVal": 0, - "maxVal": 10, - "unit": "#" - }, - "StatoRicircolo": { - "name": "StatoRicircolo", - "description": "Stato Ricircolo Serbatoi", - "memAddr": "40004", - "tipoMem": "Int", - "index": 4, - "size": 1, - "func": "MAX", - "period": 90, - "factor": 1, - "minVal": 0, - "maxVal": 10, - "unit": "#" - }, - "NumAllarmi": { - "name": "NumAllarmi", - "description": "NUmero Allarmi Presenti", - "memAddr": "40005", - "tipoMem": "Int", - "index": 5, - "size": 1, - "func": "MAX", - "period": 90, - "factor": 1, - "minVal": 0, - "maxVal": 1000, - "unit": "#" - }, - "NumAllarmiNR": { - "name": "NumAllarmiNR", - "description": "NUmero Allarmi Non Riconosciuti", - "memAddr": "40006", - "tipoMem": "Int", - "index": 6, - "size": 1, - "func": "MAX", - "period": 90, - "factor": 1, - "minVal": 0, - "maxVal": 1000, - "unit": "#" - }, - "ModoPreparazione": { - "name": "ModoPreparazione", - "description": "Modo Preparazione Ricetta", - "memAddr": "40007", - "tipoMem": "Int", - "index": 7, - "size": 1, - "func": "MAX", - "period": 90, - "factor": 1, - "minVal": 0, - "maxVal": 10, - "unit": "#" - }, - "NumRicette": { - "name": "NumRicette", - "description": "Numero Ricette in coda", - "memAddr": "40008", - "tipoMem": "Int", - "index": 8, - "size": 1, - "func": "MAX", - "period": 90, - "factor": 1, - "minVal": 0, - "maxVal": 1000, - "unit": "#" - }, - "StatoImport": { - "name": "StatoImport", - "description": "Stato Importazione file ricette XML da esterno", - "memAddr": "40009", - "tipoMem": "Int", - "index": 9, - "size": 1, - "func": "MAX", - "period": 90, - "factor": 1, - "minVal": 0, - "maxVal": 10, - "unit": "#" - }, - "LivSerb01": { - "name": "LivSerb01", - "description": "Livello Servatoio 01", - "memAddr": "40020", - "tipoMem": "Int", - "index": 20, - "size": 1, - "func": "MAX", - "period": 90, - "factor": 1, - "minVal": 0, - "maxVal": 1000, - "unit": "#" - }, - "LivSerb02": { - "name": "LivSerb02", - "description": "Livello Servatoio 02", - "memAddr": "40021", - "tipoMem": "Int", - "index": 21, - "size": 1, - "func": "MAX", - "period": 90, - "factor": 1, - "minVal": 0, - "maxVal": 1000, - "unit": "#" - }, - "LivSerb03": { - "name": "LivSerb03", - "description": "Livello Servatoio 03", - "memAddr": "40022", - "tipoMem": "Int", - "index": 22, - "size": 1, - "func": "MAX", - "period": 90, - "factor": 1, - "minVal": 0, - "maxVal": 1000, - "unit": "#" - }, - "LivSerb04": { - "name": "LivSerb04", - "description": "Livello Servatoio 04", - "memAddr": "40023", - "tipoMem": "Int", - "index": 23, - "size": 1, - "func": "MAX", - "period": 90, - "factor": 1, - "minVal": 0, - "maxVal": 1000, - "unit": "#" - }, - "LivSerb05": { - "name": "LivSerb05", - "description": "Livello Servatoio 05", - "memAddr": "40024", - "tipoMem": "Int", - "index": 24, - "size": 1, - "func": "MAX", - "period": 90, - "factor": 1, - "minVal": 0, - "maxVal": 1000, - "unit": "#" - }, - "LivSerb06": { - "name": "LivSerb06", - "description": "Livello Servatoio 06", - "memAddr": "40025", - "tipoMem": "Int", - "index": 25, - "size": 1, - "func": "MAX", - "period": 90, - "factor": 1, - "minVal": 0, - "maxVal": 1000, - "unit": "#" - }, - "LivSerb07": { - "name": "LivSerb07", - "description": "Livello Servatoio 07", - "memAddr": "40026", - "tipoMem": "Int", - "index": 26, - "size": 1, - "func": "MAX", - "period": 90, - "factor": 1, - "minVal": 0, - "maxVal": 1000, - "unit": "#" - }, - "LivSerb08": { - "name": "LivSerb08", - "description": "Livello Servatoio 08", - "memAddr": "40027", - "tipoMem": "Int", - "index": 27, - "size": 1, - "func": "MAX", - "period": 90, - "factor": 1, - "minVal": 0, - "maxVal": 1000, - "unit": "#" - }, - "LivSerb09": { - "name": "LivSerb09", - "description": "Livello Servatoio 09", - "memAddr": "40028", - "tipoMem": "Int", - "index": 28, - "size": 1, - "func": "MAX", - "period": 90, - "factor": 1, - "minVal": 0, - "maxVal": 1000, - "unit": "#" - }, - "LivSerb10": { - "name": "LivSerb10", - "description": "Livello Servatoio 10", - "memAddr": "40029", - "tipoMem": "Int", - "index": 29, - "size": 1, - "func": "MAX", - "period": 90, - "factor": 1, - "minVal": 0, - "maxVal": 1000, - "unit": "#" - }, - "LivSerb11": { - "name": "LivSerb11", - "description": "Livello Servatoio 11", - "memAddr": "40030", - "tipoMem": "Int", - "index": 30, - "size": 1, - "func": "MAX", - "period": 90, - "factor": 1, - "minVal": 0, - "maxVal": 1000, - "unit": "#" - }, - "LivSerb12": { - "name": "LivSerb12", - "description": "Livello Servatoio 12", - "memAddr": "40031", - "tipoMem": "Int", - "index": 31, - "size": 1, - "func": "MAX", - "period": 90, - "factor": 1, - "minVal": 0, - "maxVal": 1000, - "unit": "#" - } - }, - "optMemPar": { - "AlarmIntCond": "40000|1=2", - "ManualBitCond": "40002.1=1", - "EStopBitCond": "40002.0=1", - "WorkIntCond": "40000|1=3", - "VarInt2Translate": "40001,40007", - "VarBit2Translate": "40003" - }, - "itemTranslation": { - "40001_0": "Stato non aggiornato per mancanza comunicazione da computer", - "40001_1": "Stato non aggiornato per mancanza comunicazione da PLC", - "40001_2": "Presenza di anomalie od attività che limitano il funzionamento", - "40001_3": "Macchina impegnata per attività normale in corso", - "40001_4": "Macchina libera e pronta al funzionamento", - "40003.0": "Posizione di dosaggio impegnata", - "40003.1": "Bidone con ricetta terminata od annullata da rimuovere da posizione di dosaggio", - "40003.2": "Ricetta in preparazione", - "40003.3": "Lavaggio valvole in corso", - "40003.4": "Avvio caricamento nuova ricetta in corso", - "40007_0": "Nessuno", - "40007_1": "Singola ricetta", - "40007_2": "Coda (modo non ancora avviato)", - "40007_3": "Coda (modo avviato)", - "40007_4": "Correzione" - } -} \ No newline at end of file diff --git a/IOB-WIN-NEXT/IOB-WIN-NEXT.csproj b/IOB-WIN-NEXT/IOB-WIN-NEXT.csproj index 51e92df0..f86b039d 100644 --- a/IOB-WIN-NEXT/IOB-WIN-NEXT.csproj +++ b/IOB-WIN-NEXT/IOB-WIN-NEXT.csproj @@ -337,9 +337,6 @@ - - PreserveNewest - PreserveNewest diff --git a/IOB-WIN-NEXT/IobSqlServLantek.cs b/IOB-WIN-NEXT/IobSqlServLantek.cs index de60e250..b9fbd41e 100644 --- a/IOB-WIN-NEXT/IobSqlServLantek.cs +++ b/IOB-WIN-NEXT/IobSqlServLantek.cs @@ -6,8 +6,11 @@ using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Diagnostics; +using System.IO; using System.Linq; using System.Net.NetworkInformation; +using System.Security.AccessControl; +using System.Web.UI; using static IOB_UT_NEXT.CustomObj; namespace IOB_WIN_NEXT @@ -16,10 +19,19 @@ namespace IOB_WIN_NEXT /// Adapter specializzato per LANTEK e le chiamate tramite DB per i dati /// - PODL (ordini MES --> MACCHINA) /// - ProdLog (da FasiDaLantek) + /// - LOGFile macchina diretto... /// public class IobSqlServLantek : IobGeneric { + #region Protected Fields + + protected int vetoReadDbSec = 3; + + protected int VetoSyncDbSec = 20; + + #endregion Protected Fields + #region Public Constructors /// @@ -37,6 +49,13 @@ namespace IOB_WIN_NEXT string VetoReadSec = getOptPar("VetoReadSec"); string VetoSyncSec = getOptPar("VetoSyncSec"); + setupSpecialParams(); + if (pathList.ContainsKey("path-remBase")) + { + logDirPath = pathList["path-remBase"]; + } + getRemoteLog(); + string connSyncState = $"data source={SyncStateServ};initial catalog={SyncStateDb};persist security info=True;user id={SyncStateUser};password={SyncStatePwd};MultipleActiveResultSets=True;App=IOB-WIN-NEXT"; // gestione command timeout da https://erikej.github.io/sqlclient/2020/10/26/sqlclient-commandtimeout-preview.html @@ -61,6 +80,23 @@ namespace IOB_WIN_NEXT #endregion Public Constructors + #region Protected Properties + + protected DbController dbProxy { get; set; } = null; + + /// + /// Stato di sync delle tab gestite + /// + protected List elencoSyncState { get; set; } = new List(); + + #endregion Protected Properties + + #region Private Properties + + private string logDirPath { get; set; } = "\\\\ecs900\\Logs"; + + #endregion Private Properties + #region Public Methods /// @@ -244,6 +280,7 @@ namespace IOB_WIN_NEXT // recupero syncState elencoSyncState = dbProxy.SyncStateGetAll(); // verifico SignLog e processo + bool acquireLog = getRemoteLog(); bool sentSignLog = processSignLogTable(adesso); // verifico ProdData e processo bool sentProdData = processProdDataTable(adesso); @@ -336,25 +373,6 @@ namespace IOB_WIN_NEXT #endregion Public Methods - #region Protected Fields - - protected int vetoReadDbSec = 3; - - protected int VetoSyncDbSec = 20; - - #endregion Protected Fields - - #region Protected Properties - - protected DbController dbProxy { get; set; } = null; - - /// - /// Stato di sync delle tab gestite - /// - protected List elencoSyncState { get; set; } = new List(); - - #endregion Protected Properties - #region Private Methods /// @@ -426,6 +444,46 @@ namespace IOB_WIN_NEXT } } + /// + /// Recupera file log da analizzare + /// + /// + private bool getRemoteLog() + { + bool answ = false; + if (Directory.Exists(logDirPath)) + { + string filePath = Path.Combine(logDirPath, $"Report-{DateTime.Today.Day}.txt"); + bool hasDaily = File.Exists(filePath); + // cerco file quotidiano... + if (!hasDaily) + { + var fileList = Directory.GetFiles(logDirPath, "Report-*.txt"); + DateTime lastMod = DateTime.Today.AddYears(-1); + foreach (var cFile in fileList) + { + var tempFile = Path.Combine(logDirPath, cFile); + var lwTime = File.GetLastWriteTime(tempFile); + if (lwTime >= lastMod) + { + lastMod = lwTime; + filePath = tempFile; + } + } + } + // leggo file + string rawVal = File.ReadAllText(Path.Combine(logDirPath, filePath)); + if (!string.IsNullOrEmpty(rawVal)) + { + // salvo in redis + string redKey = redisMan.redHash($"IOB:CurrData:{cIobConf.codIOB}:LogFile:Act"); + redisMan.setRSV(redKey, rawVal); + answ = true; + } + } + return answ; + } + /// /// Esegue processing + invio dati tab SignLog /// @@ -596,8 +654,27 @@ namespace IOB_WIN_NEXT // verifica se ci siano dati da trasmettere (sui valori LastIdx) if (currSignLogRead.LastIdx > currSignLogSent.LastIdx) { - // recupero i dati dal DB... - var data2send = dbProxy.MachSigLogGetNew(currSignLogSent.LastIdx); + // init oggetto x processing + Dictionary sigLogFromFile = new Dictionary(); + // recupero i dati dai logs files, attuale e nuovo... + string redKeyAct = redisMan.redHash($"IOB:CurrData:{cIobConf.codIOB}:LogFile:Act"); + string redKeyLast = redisMan.redHash($"IOB:CurrData:{cIobConf.codIOB}:LogFile:Last"); + string fileAct = redisMan.getRSV(redKeyAct); + string fileLast = redisMan.getRSV(redKeyLast); + // confronto con i dati dell'ultimo LOG FILE processato + int lenghtAct = fileAct.Length; + int lenghtLast = fileLast.Length; + if (lenghtAct > 0 && lenghtAct > lenghtLast) + { + // prendo SOLAMENTE le righe nuove + + // processo le righe nuove trasformandole in un elenco data/codice evento + + // salvo in last il valore di act... + redisMan.setRSV(redKeyLast, fileAct); + } + + List data2send = dbProxy.MachSigLogGetNew(currSignLogSent.LastIdx); // se ho dati preparo invio if (data2send != null && data2send.Count > 0) { diff --git a/IOB-WIN-NEXT/IobSqlServPama.cs b/IOB-WIN-NEXT/IobSqlServPama.cs index be23873a..ea43cc80 100644 --- a/IOB-WIN-NEXT/IobSqlServPama.cs +++ b/IOB-WIN-NEXT/IobSqlServPama.cs @@ -366,7 +366,7 @@ namespace IOB_WIN_NEXT sw.Start(); elencoSyncState = dbProxy.SyncStateDoExportAll(); sw.Stop(); - DateTime adesso= DateTime.Now; + DateTime adesso = DateTime.Now; lastReadPLC = adesso; lgInfo($"DB: esecuzione task dbProxy.SyncStateDoExportAll() in {sw.ElapsedMilliseconds} ms"); @@ -436,7 +436,7 @@ namespace IOB_WIN_NEXT bool fatto = false; string tabNameIn = "FluxLog"; string tabNameOut = "FluxLogToMes"; - // cerco info sui SignLog (ToMes e letti) + // cerco info sui FluxLog (ToMes e letti) var currFluxLogRead = elencoSyncState.FirstOrDefault(x => x.TableName == tabNameIn); // se nullo inizializzo if (currFluxLogRead == null) @@ -617,7 +617,7 @@ namespace IOB_WIN_NEXT if (currSignLogRead.LastIdx > currSignLogSent.LastIdx) { // recupero i dati dal DB... - var data2send = dbProxy.MachSigLogGetNew(currSignLogSent.LastIdx); + List data2send = dbProxy.MachSigLogGetNew(currSignLogSent.LastIdx); // se ho dati preparo invio if (data2send != null && data2send.Count > 0) {