From 9c8ea23e9d70ffaadbb31e98e2ae44c5567b1b98 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Thu, 19 Jun 2025 12:53:57 +0200 Subject: [PATCH] Fix configurazione IOB x file log da nome file (NON IOB gestito) --- IOB-UT-NEXT/Config/IobConfTree.cs | 8 +-- IOB-WIN-FORM/AdapterForm.cs | 11 ++-- IOB-WIN-FORM/Iob/Generic.Protected.cs | 88 ++++++++++++++------------- IOB-WIN-FORM/Iob/Generic.Public.cs | 4 +- 4 files changed, 56 insertions(+), 55 deletions(-) diff --git a/IOB-UT-NEXT/Config/IobConfTree.cs b/IOB-UT-NEXT/Config/IobConfTree.cs index 7423af4b..910e39ba 100644 --- a/IOB-UT-NEXT/Config/IobConfTree.cs +++ b/IOB-UT-NEXT/Config/IobConfTree.cs @@ -1063,7 +1063,7 @@ namespace IOB_UT_NEXT.Config /// protected void lgDebug(string txt2log) { - Log.Factory.Configuration.Variables["codIOB"] = General.CodIOB; + Log.Factory.Configuration.Variables["codIOB"] = General.FilenameIOB; Log.Debug(txt2log); } @@ -1075,7 +1075,7 @@ namespace IOB_UT_NEXT.Config { if (!string.IsNullOrEmpty(txt2log)) { - Log.Factory.Configuration.Variables["codIOB"] = General.CodIOB; + Log.Factory.Configuration.Variables["codIOB"] = General.FilenameIOB; Log.Error(txt2log); } } @@ -1086,7 +1086,7 @@ namespace IOB_UT_NEXT.Config /// protected void lgInfo(string txt2log) { - Log.Factory.Configuration.Variables["codIOB"] = General.CodIOB; + Log.Factory.Configuration.Variables["codIOB"] = General.FilenameIOB; Log.Info(txt2log); } @@ -1096,7 +1096,7 @@ namespace IOB_UT_NEXT.Config /// protected void lgTrace(string txt2log) { - Log.Factory.Configuration.Variables["codIOB"] = General.CodIOB; + Log.Factory.Configuration.Variables["codIOB"] = General.FilenameIOB; Log.Trace(txt2log); } diff --git a/IOB-WIN-FORM/AdapterForm.cs b/IOB-WIN-FORM/AdapterForm.cs index 3678dc7c..eea9f70c 100644 --- a/IOB-WIN-FORM/AdapterForm.cs +++ b/IOB-WIN-FORM/AdapterForm.cs @@ -1111,7 +1111,7 @@ namespace IOB_WIN_FORM /// protected void lgDebug(string txt2log) { - lg.Factory.Configuration.Variables["codIOB"] = this.CurrIOB; + lg.Factory.Configuration.Variables["codIOB"] = this.CurrIOB;//IOBConfFull.General.FilenameIOB ??this.CurrIOB; lg.Debug(txt2log); // salvo anche in logwatcher... newDisplayData currDispData = new newDisplayData(); @@ -1127,7 +1127,7 @@ namespace IOB_WIN_FORM { if (!string.IsNullOrEmpty(txt2log)) { - lg.Factory.Configuration.Variables["codIOB"] = this.CurrIOB; + lg.Factory.Configuration.Variables["codIOB"] = this.CurrIOB;//IOBConfFull.General.FilenameIOB ??this.CurrIOB; lg.Error(txt2log); // salvo anche in logwatcher... SE non si dimostra ricorsivo... if (!txt2log.Contains("logWatcher")) @@ -1145,7 +1145,7 @@ namespace IOB_WIN_FORM /// protected void lgInfo(string txt2log) { - lg.Factory.Configuration.Variables["codIOB"] = this.CurrIOB; + lg.Factory.Configuration.Variables["codIOB"] = this.CurrIOB;//IOBConfFull.General.FilenameIOB ??this.CurrIOB; lg.Info(txt2log); // salvo anche in logwatcher... newDisplayData currDispData = new newDisplayData(); @@ -1159,7 +1159,7 @@ namespace IOB_WIN_FORM /// protected void lgTrace(string txt2log) { - lg.Factory.Configuration.Variables["codIOB"] = this.CurrIOB; + lg.Factory.Configuration.Variables["codIOB"] = this.CurrIOB;//IOBConfFull.General.FilenameIOB ??this.CurrIOB; lg.Trace(txt2log); // salvo anche in logwatcher... newDisplayData currDispData = new newDisplayData(); @@ -1774,11 +1774,10 @@ namespace IOB_WIN_FORM Dictionary setPar = new Dictionary(); setPar.Add("IP", iobObj.IOBConfFull.Device.Connect.IpAddr); setPar.Add("PORT", iobObj.IOBConfFull.Device.Connect.Port); - string note = $"{iobObj.IOBConfFull.General.CodIOB} | DT ultimo avvio: {iobObj.dtAvvioAdp}"; + string note = $"{iobObj.IOBConfFull.General.FilenameIOB} | DT ultimo avvio: {iobObj.dtAvvioAdp}"; // verifico IOB status IobWinStatus currIobStatus = new IobWinStatus() { - //CodIob = iobObj.cIobConf.filenameIOB, CodIob = iobObj.IOBConfFull.General.FilenameIOB, IobType = $"{iobObj.IOBConfFull.General.IobType}",//iobObj.cIobConf.tipoIob.ToString(), queueAlLen = alQueueLen, diff --git a/IOB-WIN-FORM/Iob/Generic.Protected.cs b/IOB-WIN-FORM/Iob/Generic.Protected.cs index 1530ef9f..300f2867 100644 --- a/IOB-WIN-FORM/Iob/Generic.Protected.cs +++ b/IOB-WIN-FORM/Iob/Generic.Protected.cs @@ -445,7 +445,7 @@ namespace IOB_WIN_FORM.Iob get { List answ = new List(); - string redKeyFLog = redisMan.redHash($"IOB:CurrData:{IOBConfFull.General.CodIOB}:LogFile:FluxLog"); + string redKeyFLog = redisMan.redHash($"IOB:CurrData:{IOBConfFull.General.FilenameIOB}:LogFile:FluxLog"); var rawData = redisMan.getRSV(redKeyFLog); if (!string.IsNullOrEmpty(rawData)) { @@ -455,7 +455,7 @@ namespace IOB_WIN_FORM.Iob } set { - string redKeyFLog = redisMan.redHash($"IOB:CurrData:{IOBConfFull.General.CodIOB}:LogFile:FluxLog"); + string redKeyFLog = redisMan.redHash($"IOB:CurrData:{IOBConfFull.General.FilenameIOB}:LogFile:FluxLog"); string fluxLogRaw = JsonConvert.SerializeObject(value); redisMan.setRSV(redKeyFLog, fluxLogRaw); } @@ -594,7 +594,7 @@ namespace IOB_WIN_FORM.Iob protected Dictionary OptVar2TranslInt { get; set; } = new Dictionary(); /// - /// Elenco dei path utili x processing + /// Elenco dei fullPath utili x processing /// protected Dictionary pathList { get; set; } = new Dictionary(); @@ -606,7 +606,7 @@ namespace IOB_WIN_FORM.Iob get { Dictionary answ = new Dictionary(); - string redKey = redisMan.redHash($"IOB:Status:{IOBConfFull.General.CodIOB}:POdlSent"); + string redKey = redisMan.redHash($"IOB:Status:{IOBConfFull.General.FilenameIOB}:POdlSent"); string rawData = redisMan.getRSV(redKey); if (!string.IsNullOrEmpty(rawData)) { @@ -625,7 +625,7 @@ namespace IOB_WIN_FORM.Iob set { string rawVal = JsonConvert.SerializeObject(value); - string redKey = redisMan.redHash($"IOB:Status:{IOBConfFull.General.CodIOB}:POdlSent"); + string redKey = redisMan.redHash($"IOB:Status:{IOBConfFull.General.FilenameIOB}:POdlSent"); redisMan.setRSV(redKey, rawVal); lgDebug($"Salvataggio status POdlSentFileArch | {value.Count} record"); } @@ -678,22 +678,22 @@ namespace IOB_WIN_FORM.Iob protected string redKeyLogfileAct { - get => redisMan.redHash($"IOB:CurrData:{IOBConfFull.General.CodIOB}:LogFile:Act"); + get => redisMan.redHash($"IOB:CurrData:{IOBConfFull.General.FilenameIOB}:LogFile:Act"); } protected string redKeyLogfileLast { - get => redisMan.redHash($"IOB:CurrData:{IOBConfFull.General.CodIOB}:LogFile:Last"); + get => redisMan.redHash($"IOB:CurrData:{IOBConfFull.General.FilenameIOB}:LogFile:Last"); } protected string redKeyProdLastArt { - get => redisMan.redHash($"IOB:CurrData:{IOBConfFull.General.CodIOB}:prodDecod:lastArtDesc"); + get => redisMan.redHash($"IOB:CurrData:{IOBConfFull.General.FilenameIOB}:prodDecod:lastArtDesc"); } protected string redKeyProdRunState { - get => redisMan.redHash($"IOB:CurrData:{IOBConfFull.General.CodIOB}:prodDecod:isRunningState"); + get => redisMan.redHash($"IOB:CurrData:{IOBConfFull.General.FilenameIOB}:prodDecod:isRunningState"); } /// @@ -701,7 +701,7 @@ namespace IOB_WIN_FORM.Iob /// protected string rKeyFluxMem { - get => redisMan.redHash($"IOB:Status:{IOBConfFull.General.CodIOB}:FluxMem"); + get => redisMan.redHash($"IOB:Status:{IOBConfFull.General.FilenameIOB}:FluxMem"); } protected Random rndGen { get; set; } = new Random(); @@ -1684,7 +1684,7 @@ namespace IOB_WIN_FORM.Iob // se inviato --> salvo stato da current... item.updStatusVal(i, (uint)(item.alarmsMask[i] & currStatus)); // salvo in redis... - string alarmHash = redisMan.redHash($"IOB:ALARM_STATUS:{IOBConfFull.General.CodIOB}:{item.memAddr}"); + string alarmHash = redisMan.redHash($"IOB:ALARM_STATUS:{IOBConfFull.General.FilenameIOB}:{item.memAddr}"); string rawAlarms = JsonConvert.SerializeObject(item.alarmsState); redisMan.setRSV(alarmHash, rawAlarms); } @@ -2358,8 +2358,8 @@ namespace IOB_WIN_FORM.Iob // test file import da conf... se hasRecipe=true --> modalità Tenditalia/FIMAT... if (hasRecipe) { - string archBasePath = Path.Combine(pathList["path-locBase"], pathList["path-03-Recv"]); - string reportBasePath = pathList["path-outReport"]; + string archBasePath = Path.Combine(pathList["fullPath-locBase"], pathList["fullPath-03-Recv"]); + string reportBasePath = pathList["fullPath-outReport"]; baseUtils.checkDir(reportBasePath); // verifico x cosa è stato richiesto attività (che esista la folder...) string folderPath = Path.Combine(archBasePath, keyReq); @@ -2416,8 +2416,8 @@ namespace IOB_WIN_FORM.Iob if (hasRecipe) { // recupera i NUOVI file e li sposta in folder locale temp - string remoPath = Path.Combine(pathList["path-locBase"], pathList["path-05-remExe"]); - string archBasePath = Path.Combine(pathList["path-locBase"], pathList["path-03-Recv"]); + string remoPath = Path.Combine(pathList["fullPath-locBase"], pathList["fullPath-05-remExe"]); + string archBasePath = Path.Combine(pathList["fullPath-locBase"], pathList["fullPath-03-Recv"]); string tempPath = Path.Combine(archBasePath, "TEMP"); baseUtils.checkDir(tempPath); bool okRetrieve = RecipeTaskDoneRetrieve(remoPath, tempPath); @@ -2589,7 +2589,7 @@ namespace IOB_WIN_FORM.Iob redHashWeek.Add(cWeek, rawWeek); } // salvo in redis... - string fullKey = redisMan.redHash($"IOB:Status:{IOBConfFull.General.CodIOB}:WeekStats"); + string fullKey = redisMan.redHash($"IOB:Status:{IOBConfFull.General.FilenameIOB}:WeekStats"); var okHashDict = redisMan.redSaveHashDict(fullKey, redHashWeek); // invio ANCHE in MP-IO l'update delle info... @@ -2618,7 +2618,7 @@ namespace IOB_WIN_FORM.Iob // verifico se ci sia la settimana indicata in elenco... string currWeek = $"{adesso:yyyy}-{week:00}"; // recupero elenco delle settimane da processare da redis/WeekStats - string fullKey = redisMan.redHash($"IOB:Status:{IOBConfFull.General.CodIOB}:WeekStats"); + string fullKey = redisMan.redHash($"IOB:Status:{IOBConfFull.General.FilenameIOB}:WeekStats"); Dictionary currStats = redisMan.redGetHashDict(fullKey); if (currStats != null && currStats.Count > 0) { @@ -2646,10 +2646,10 @@ namespace IOB_WIN_FORM.Iob DateTime asdesso = DateTime.Now; try { - string recLocalArchPath = Path.Combine(pathList["path-locBase"], pathList["path-00-Arch"]); - string recRemArchPath = pathList["path-06-remRec"]; + string recLocalArchPath = Path.Combine(pathList["fullPath-locBase"], pathList["fullPath-00-Arch"]); + string recRemArchPath = pathList["fullPath-06-remRec"]; // leggo da redis (se disponibile) elenco hast file/MD5.... - string fullKey = redisMan.redHash($"IOB:Remote:{IOBConfFull.General.CodIOB}:FileCheck"); + string fullKey = redisMan.redHash($"IOB:Remote:{IOBConfFull.General.FilenameIOB}:FileCheck"); Dictionary dictRecMd5 = redisMan.redGetHashDict(fullKey); // leggo la directory remota... var remoteList = Directory.GetFiles(recRemArchPath); @@ -2822,7 +2822,7 @@ namespace IOB_WIN_FORM.Iob } /// - /// Prepara le ricette dato path temp scaricando elenco PODL + /// Prepara le ricette dato fullPath temp scaricando elenco PODL /// /// /// Percorso temp di appoggio x preparare ricette (compreso nome macchina) @@ -2868,8 +2868,8 @@ namespace IOB_WIN_FORM.Iob string recFilePath = ""; try { - // calcolo path ricetta... - recFilePath = Path.Combine(pathList["path-locBase"], pathList["path-00-Arch"], actPodlReq.Recipe); + // calcolo fullPath ricetta... + recFilePath = Path.Combine(pathList["fullPath-locBase"], pathList["fullPath-00-Arch"], actPodlReq.Recipe); // preparo file ricetta x PODL bool fileOk = RecipePrepare(tempPath, recFilePath, actPodlReq); if (fileOk) @@ -3081,7 +3081,7 @@ namespace IOB_WIN_FORM.Iob if (IOBConfFull != null) { // creo obj dati necessari... - currDict.Add("IobName", IOBConfFull.General.CodIOB); + currDict.Add("IobName", IOBConfFull.General.FilenameIOB); currDict.Add("IobType", $"{IOBConfFull.General.IobType}"); currDict.Add("MachIp", IOBConfFull.Device.Connect.IpAddr); currDict.Add("MachPort", IOBConfFull.Device.Connect.Port); @@ -3201,7 +3201,7 @@ namespace IOB_WIN_FORM.Iob { item.setupData(); // se ho in redis una tab di allarmi precedenti la carico... - string alarmHash = redisMan.redHash($"IOB:ALARM_STATUS:{IOBConfFull.General.CodIOB}:{item.memAddr}"); + string alarmHash = redisMan.redHash($"IOB:ALARM_STATUS:{IOBConfFull.General.FilenameIOB}:{item.memAddr}"); string rawVal = redisMan.getRSV(alarmHash); if (!string.IsNullOrEmpty(rawVal)) { @@ -3484,7 +3484,7 @@ namespace IOB_WIN_FORM.Iob else { // recupero le folder specifiche x IN/OUT ricette filtrando direttamente l'area di memoria... - sCond = "path"; + sCond = "fullPath"; var dirList = memMap.OptKVP .Where(x => x.Key.StartsWith(sCond)) .ToList(); @@ -3970,7 +3970,7 @@ namespace IOB_WIN_FORM.Iob } /// - /// URL come urlCommand + aggiunta codice IOB da file (= specifico x Reboot)da cui viene inviato + /// URL come urlCommand + aggiunta codice IOB da file (= specifico x Reboot) da cui viene inviato /// protected string urlCommandIobFile(string cmqReq) { @@ -4184,7 +4184,7 @@ namespace IOB_WIN_FORM.Iob /// private string rKeyCurrProdData { - get => redisMan.redHash($"IOB:Status:{IOBConfFull.General.CodIOB}:CurrProdData"); + get => redisMan.redHash($"IOB:Status:{IOBConfFull.General.FilenameIOB}:CurrProdData"); } /// @@ -4365,18 +4365,20 @@ namespace IOB_WIN_FORM.Iob /// private void checkShrinkDir() { - // comprimo x prima cosa la folder dell'IOB corrente - string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "logs", IOBConfFull.General.CodIOB); - try + // comprimo x prima cosa la folder dell'IOB corrente... testo sia IOBConf che FilenameIOB + List path2chk = new List() { IOBConfFull.General.CodIOB, IOBConfFull.General.FilenameIOB, "MAIN" }; + string fullPath = ""; + foreach (var item in path2chk) { - baseUtils.shrinkDir(path); - // provo a comprimere anche la folder MAIN.... - path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "logs", "MAIN"); - baseUtils.shrinkDir(path); - } - catch (Exception exc) - { - lgError($"Eccezione in checkShrinkDir{Environment.NewLine}{exc}"); + fullPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "logs", item); + try + { + baseUtils.shrinkDir(fullPath); + } + catch (Exception exc) + { + lgError($"Eccezione in checkShrinkDir{Environment.NewLine}{exc}"); + } } } @@ -4636,10 +4638,10 @@ namespace IOB_WIN_FORM.Iob // se scaduto tempo da ultimo invio... e ho valori if (currWritePar.Count > 0 && (lastWriteParamsUpsert.AddMinutes(vetoSendWriteUpsert) < adesso)) { - lastWriteParamsUpsert = adesso; // invio su cloud parametri! - utils.callUrl($"{urlUpdateWriteParams}", JsonConvert.SerializeObject(currWritePar)); + var res = utils.callUrl($"{urlUpdateWriteParams}", JsonConvert.SerializeObject(currWritePar)); lgInfo($"Reinviato a server stato {updatedPar.Count} parametri WRITE"); + lastWriteParamsUpsert = adesso; } } } @@ -4745,7 +4747,7 @@ namespace IOB_WIN_FORM.Iob List ListConsDet = new List(); List ListConsSum = new List(); // file conf x conversioni... - string confSetupPath = pathList["path-confSetup"]; + string confSetupPath = pathList["fullPath-confSetup"]; ConvSetup currConf = new ConvSetup(); bool addHeader = false; int numDec = 4; @@ -4898,7 +4900,7 @@ namespace IOB_WIN_FORM.Iob /// private void RecipeRemoveWeekStatus(string keyReq) { - string fullKey = redisMan.redHash($"IOB:Status:{IOBConfFull.General.CodIOB}:WeekStats"); + string fullKey = redisMan.redHash($"IOB:Status:{IOBConfFull.General.FilenameIOB}:WeekStats"); var okHashDict = redisMan.redRemoveHashField(fullKey, keyReq); // rileggo status hash Dictionary currDict = redisMan.redGetHashDict(fullKey); diff --git a/IOB-WIN-FORM/Iob/Generic.Public.cs b/IOB-WIN-FORM/Iob/Generic.Public.cs index e21e3ec5..88ecc730 100644 --- a/IOB-WIN-FORM/Iob/Generic.Public.cs +++ b/IOB-WIN-FORM/Iob/Generic.Public.cs @@ -59,7 +59,7 @@ namespace IOB_WIN_FORM.Iob parentForm = caller; // imposto le code! - QueueIN = new DataQueue(IOBConfFull.General.CodIOB, "QueueIN", IOBConfFull.General.EnabRedisQue); + QueueIN = new DataQueue(IOBConfFull.General.FilenameIOB, "QueueIN", IOBConfFull.General.EnabRedisQue); lastConnectTry = DateTime.Now; @@ -1815,7 +1815,7 @@ namespace IOB_WIN_FORM.Iob foreach (TimeRec item in TimingData.results) { // loggo SOLO se del mio IOB corrente... - if (item.classCall == IOBConfFull.General.CodIOB) + if (item.classCall == IOBConfFull.General.FilenameIOB) { lgInfo("{4}|Chiamate {0}: effettuate {1}, tempo medio {2:N2} msec | impegno canale {3:P3}", item.codCall, item.numCall, item.avgMsec, item.totMsec.TotalSeconds / DateTime.Now.Subtract(dtAvvioAdp).TotalSeconds, IOBConfFull.General.CodIOB); globNumCall += item.numCall;