diff --git a/IOB-WIN-NEXT/DATA/CONF/SIMUL_02.json b/IOB-WIN-NEXT/DATA/CONF/SIMUL_02.json index 51f5ad88..90281f1d 100644 --- a/IOB-WIN-NEXT/DATA/CONF/SIMUL_02.json +++ b/IOB-WIN-NEXT/DATA/CONF/SIMUL_02.json @@ -106,8 +106,8 @@ "path-01-Temp": "01-Temp\\FIMAT", "path-02-Sent": "02-Inviate\\FIMAT", "path-03-Recv": "03-Ricevute\\FIMAT", - "path-04-remW": "C:\\MesData\\Remote\\Queue2", - "path-05-remR": "C:\\MesData\\Remote\\Dosed", + "path-04-remReq": "C:\\MesData\\Remote\\Queue2", + "path-05-remExe": "C:\\MesData\\Remote\\Dosed", "path-06-remRec": "C:\\MesData\\Remote\\Recipes", "path-outReport": "C:\\MesData\\Report", "path-confSetup": "C:\\MesData\\Setup\\setupConsumi.json", diff --git a/IOB-WIN-NEXT/DATA/CONF/Tend_FIMAT_01.json b/IOB-WIN-NEXT/DATA/CONF/Tend_FIMAT_01.json index 6db20881..fdf36e51 100644 --- a/IOB-WIN-NEXT/DATA/CONF/Tend_FIMAT_01.json +++ b/IOB-WIN-NEXT/DATA/CONF/Tend_FIMAT_01.json @@ -314,9 +314,9 @@ "path-01-Temp": "01-Temp\\FIMAT", "path-02-Sent": "02-Inviate\\FIMAT", "path-03-Recv": "03-Ricevute\\FIMAT", - "path-04-remW": "Y:\\", - "path-05-remR": "Z:\\", - "path-06-remR": "R:\\", + "path-04-remReq": "Y:\\", + "path-05-remExe": "Z:\\", + "path-06-remRec": "R:\\", "path-outReport": "C:\\MesData\\Report", "path-confSetup": "E:\\MesData\\Setup\\setupConsumi.json", "replace-": "{{PODL}}", diff --git a/IOB-WIN-NEXT/IOB-WIN-NEXT.csproj b/IOB-WIN-NEXT/IOB-WIN-NEXT.csproj index ee1077f8..db5ceaa1 100644 --- a/IOB-WIN-NEXT/IOB-WIN-NEXT.csproj +++ b/IOB-WIN-NEXT/IOB-WIN-NEXT.csproj @@ -679,7 +679,9 @@ - + + PreserveNewest + diff --git a/IOB-WIN-NEXT/IobGeneric.cs b/IOB-WIN-NEXT/IobGeneric.cs index 58597aa5..c949d02a 100644 --- a/IOB-WIN-NEXT/IobGeneric.cs +++ b/IOB-WIN-NEXT/IobGeneric.cs @@ -109,6 +109,10 @@ namespace IOB_WIN_NEXT /// Indicazione VETO check status IOB x evitare loop troppo stretti... /// public DateTime dtVetoCheckIOB = DateTime.Now.AddDays(-1); + /// + /// Indicazione VETO check sync ricette x evitare loop troppo stretti... + /// + public DateTime dtVetoCheckSyncRecipe = DateTime.Now.AddHours(-1); /// /// Abilitazione lettura PrgName @@ -2192,6 +2196,7 @@ namespace IOB_WIN_NEXT catch { } } + processRecipeSyncArch(); } // mostra eventuali altri dati di processo... reportDataProc(); @@ -2245,6 +2250,10 @@ namespace IOB_WIN_NEXT // effettua process ritorno ricette processRecipeFileRet(); } + else if (ciclo == gatherCycle.VLF) + { + processRecipeSyncArch(); + } // provo a riconnettere SE abilitato tryRestart... if (adpTryRestart && !connectionOk) @@ -6041,6 +6050,29 @@ namespace IOB_WIN_NEXT return answ; } + /// + /// Sync archivio ricette (Macchina <--> MES) + /// + /// + protected virtual bool processRecipeSyncArch() + { + bool answ = false; + // test file import da conf... se hasRecipe=true --> modalità Tenditalia/FIMAT... + if (hasRecipe) + { + DateTime adesso = DateTime.Now; + // verifico veto sync ricette (x non ripetere troppo spesso) + if (adesso > dtVetoCheckSyncRecipe) + { + // effettua sync eventuali NUOVI file ricette + bool okSync = RecipeDoSyncRecipe(); + // imposto veto a 1h... + dtVetoCheckSyncRecipe = adesso.AddHours(1); + } + } + return answ; + } + protected virtual bool processRecipeFileRet() { bool answ = false; @@ -6048,7 +6080,7 @@ namespace IOB_WIN_NEXT if (hasRecipe) { // recupera i NUOVI file e li sposta in folder locale temp - string remoPath = Path.Combine(pathList["path-locBase"], pathList["path-05-remR"]); + string remoPath = Path.Combine(pathList["path-locBase"], pathList["path-05-remExe"]); string archBasePath = Path.Combine(pathList["path-locBase"], pathList["path-03-Recv"]); string tempPath = Path.Combine(archBasePath, "TEMP"); baseUtils.checkDir(tempPath); @@ -6200,8 +6232,6 @@ namespace IOB_WIN_NEXT } } - // alla fine comunque effettua sync eventuali NUOVI file ricette - bool okSync = RecipeDoSyncRecipe(""); return answ; } @@ -6242,71 +6272,82 @@ namespace IOB_WIN_NEXT /// /// Acquisisce eventuali nuove ricette /// - /// Percorso archivio ricette XML /// - protected bool RecipeDoSyncRecipe(string recipeArchPath) + protected bool RecipeDoSyncRecipe() { bool answ = false; DateTime asdesso = DateTime.Now; - string recLocalArchPath = Path.Combine(pathList["path-locBase"], pathList["path-00-Arch"]); - string recRemArchPath = pathList["path-06-remR"]; - // leggo da redis (se disponibile) elenco hast file/MD5.... - string fullKey = redisMan.redHash($"IOB:Remote:{cIobConf.codIOB}:FileCheck"); - Dictionary dictRecMd5 = redisMan.redGetHashDict(fullKey); - // leggo la directory remota... - var remoteList = Directory.GetFiles(recRemArchPath); - string fileName = ""; - string newFilePath = ""; - bool doAcquire = false; - int recNum = 0; - int newNum = 0; - string currMd5; - foreach (var remoteFile in remoteList) + try { - recNum = 0; - doAcquire = false; - // verifico MD5... - currMd5 = baseUtils.GetFileMd5(remoteFile); - fileName = Path.GetFileName(remoteFile); - // verifo se c'è il file... - if (!dictRecMd5.ContainsKey(fileName)) + string recLocalArchPath = Path.Combine(pathList["path-locBase"], pathList["path-00-Arch"]); + string recRemArchPath = pathList["path-06-remRec"]; + // leggo da redis (se disponibile) elenco hast file/MD5.... + string fullKey = redisMan.redHash($"IOB:Remote:{cIobConf.codIOB}:FileCheck"); + Dictionary dictRecMd5 = redisMan.redGetHashDict(fullKey); + // leggo la directory remota... + var remoteList = Directory.GetFiles(recRemArchPath); + string fileName = ""; + string newFilePath = ""; + bool doAcquire = false; + int recNum = 0; + int newNum = 0; + string currMd5; + foreach (var remoteFile in remoteList) { - dictRecMd5.Add(fileName, currMd5); - doAcquire = true; - } - else - { - //// verifico SE sia modificato da meno di 30 gg... - //DateTime lastMod = File.GetLastWriteTime(remoteFile); - if (dictRecMd5[fileName] != currMd5) + recNum = 0; + doAcquire = false; + // verifico MD5... + currMd5 = baseUtils.GetFileMd5(remoteFile); + fileName = Path.GetFileName(remoteFile); + // verifo se c'è il file... + if (!dictRecMd5.ContainsKey(fileName)) { - dictRecMd5[fileName] = currMd5; + dictRecMd5.Add(fileName, currMd5); doAcquire = true; } - } + else + { + //// verifico SE sia modificato da meno di 30 gg... + //DateTime lastMod = File.GetLastWriteTime(remoteFile); + if (dictRecMd5[fileName] != currMd5) + { + dictRecMd5[fileName] = currMd5; + doAcquire = true; + } + } - // se devo aggiungere processo --> fix numRicetta + 10'000 - if (doAcquire) + // se devo aggiungere processo --> fix numRicetta + 10'000 + if (doAcquire) + { + answ = true; + // leggo contenuto... + string recContent = File.ReadAllText(remoteFile); + // calcolo nuovo nome + var namePart = fileName.Split('.'); + int.TryParse(namePart[0], out recNum); + newNum = recNum + 10000; + // modifico ricetta + recContent = recContent.Replace($"{namePart[0]}", $"{newNum}"); + // salvo ricetta modificata in archivio + newFilePath = Path.Combine(recLocalArchPath, $"{newNum}.xml"); + // elimino eventuale file precedente... + if (File.Exists(newFilePath)) + { + File.Delete(newFilePath); + } + File.WriteAllText(newFilePath, recContent); + } + } + // se ho importato qualcosa... + if (answ) { - answ = true; - // leggo contenuto... - string recContent = File.ReadAllText(remoteFile); - // calcolo nuovo nome - var namePart = fileName.Split('.'); - int.TryParse(namePart[0], out recNum); - newNum = recNum + 10000; - // modifico ricetta - recContent.Replace($"{recNum}", $"{newNum}"); - // salvo ricetta modificata in archivio - newFilePath = Path.Combine(recLocalArchPath, $"{newNum}.xml"); - File.WriteAllText(recContent, newFilePath); + // salvo hash dei files... + redisMan.redSaveHashDict(fullKey, dictRecMd5); } } - // se ho importato qualcosa... - if (answ) + catch (Exception exc) { - // salvo hash dei files... - redisMan.redSaveHashDict(fullKey, dictRecMd5); + lgError($"Eccezione durante RecipeDoSyncRecipe{Environment.NewLine}{exc}"); } return answ; } diff --git a/IOB-WIN-NEXT/IobModbusTCPFimat.cs b/IOB-WIN-NEXT/IobModbusTCPFimat.cs index 4cdadb7a..5fab90c7 100644 --- a/IOB-WIN-NEXT/IobModbusTCPFimat.cs +++ b/IOB-WIN-NEXT/IobModbusTCPFimat.cs @@ -193,7 +193,7 @@ namespace IOB_WIN_NEXT week = cal.GetWeekOfYear(adesso, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday); //string archPath = Path.Combine(pathList["path-locBase"], pathList["path-02-Sent"], $"{adesso:yyyy}", $"{adesso:MM}"); string archPath = Path.Combine(pathList["path-locBase"], pathList["path-02-Sent"], $"{adesso:yyyy}", $"{week:00}"); - string remoPath = Path.Combine(pathList["path-locBase"], pathList["path-04-remW"]); + string remoPath = Path.Combine(pathList["path-locBase"], pathList["path-04-remReq"]); baseUtils.checkDir(tempPath); baseUtils.checkDir(archPath); try diff --git a/IOB-WIN-NEXT/IobSimula.cs b/IOB-WIN-NEXT/IobSimula.cs index b1101aa9..766223ac 100644 --- a/IOB-WIN-NEXT/IobSimula.cs +++ b/IOB-WIN-NEXT/IobSimula.cs @@ -110,7 +110,7 @@ namespace IOB_WIN_NEXT string tempPath = Path.Combine(pathList["path-locBase"], pathList["path-01-Temp"]); //string archPath = Path.Combine(pathList["path-locBase"], pathList["path-02-Sent"], $"{adesso:yyyy}", $"{adesso:MM}"); string archPath = Path.Combine(pathList["path-locBase"], pathList["path-02-Sent"], $"{adesso:yyyy}", $"{week:00}"); - string remoPath = Path.Combine(pathList["path-locBase"], pathList["path-04-remW"]); + string remoPath = Path.Combine(pathList["path-locBase"], pathList["path-04-remReq"]); baseUtils.checkDir(tempPath); baseUtils.checkDir(archPath); // recupero elenco PODL da processare, check PODL già inviati, save locale