Completato test import ricette in sync

This commit is contained in:
Samuele Locatelli
2023-04-13 10:34:14 +02:00
parent 7010548337
commit 48ffbb6de1
6 changed files with 105 additions and 62 deletions
+2 -2
View File
@@ -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",
+3 -3
View File
@@ -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-<Variant>": "<Variant>{{PODL}}",
+3 -1
View File
@@ -679,7 +679,9 @@
<None Include="DATA\CONF\GT547.ini" />
<None Include="DATA\CONF\4000.ini" />
<None Include="DATA\CONF\SIMUL_04.ini" />
<None Include="DATA\CONF\SIMUL_03.ini" />
<None Include="DATA\CONF\SIMUL_03.ini">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="DATA\CONF\L014.ini" />
<None Include="DATA\CONF\L017.ini" />
<None Include="DATA\CONF\MAIN.ini">
+95 -54
View File
@@ -109,6 +109,10 @@ namespace IOB_WIN_NEXT
/// Indicazione VETO check status IOB x evitare loop troppo stretti...
/// </summary>
public DateTime dtVetoCheckIOB = DateTime.Now.AddDays(-1);
/// <summary>
/// Indicazione VETO check sync ricette x evitare loop troppo stretti...
/// </summary>
public DateTime dtVetoCheckSyncRecipe = DateTime.Now.AddHours(-1);
/// <summary>
/// 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;
}
/// <summary>
/// Sync archivio ricette (Macchina <--> MES)
/// </summary>
/// <returns></returns>
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
/// <summary>
/// Acquisisce eventuali nuove ricette
/// </summary>
/// <param name="recipeArchPath">Percorso archivio ricette XML</param>
/// <returns></returns>
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<string, string> 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<string, string> 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($"<RecName>{namePart[0]}</RecName>", $"<RecName>{newNum}</RecName>");
// 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($"<RecName>{recNum}</RecName>", $"<RecName>{newNum}</RecName>");
// 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;
}
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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