From 76fc82705e51f697c265a6dba86f800ab3a91c34 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Mon, 7 Oct 2024 20:06:07 +0200 Subject: [PATCH] FTP: - inizio gestione ODL (da provare con cambio su tablet) - fluxlog delle azioni creazione DIR su FTP --- IOB-UT-NEXT/FtpActConf.cs | 1 - IOB-WIN-NEXT/Iob/Generic.cs | 2 +- IOB-WIN-NEXT/IobNet/Ftp.cs | 229 ++++++++++++++++--------- IOB-WIN-NEXT/IobOpc/OpcUaMBHCimolai.cs | 2 +- 4 files changed, 152 insertions(+), 82 deletions(-) diff --git a/IOB-UT-NEXT/FtpActConf.cs b/IOB-UT-NEXT/FtpActConf.cs index 4efecd24..0a0e2243 100644 --- a/IOB-UT-NEXT/FtpActConf.cs +++ b/IOB-UT-NEXT/FtpActConf.cs @@ -43,7 +43,6 @@ namespace IOB_UT_NEXT /// public bool SkipCert { get; set; } = true; - /// /// Tempo di attesa in SEC standard prima della prossima ri-esecuzione /// diff --git a/IOB-WIN-NEXT/Iob/Generic.cs b/IOB-WIN-NEXT/Iob/Generic.cs index 412df9f0..3fcdb83e 100644 --- a/IOB-WIN-NEXT/Iob/Generic.cs +++ b/IOB-WIN-NEXT/Iob/Generic.cs @@ -2893,7 +2893,7 @@ namespace IOB_WIN_NEXT.Iob Dictionary taskDone = new Dictionary(); // recupero elenco delle cose da fare string resp = getTask2exe(); - if (!string.IsNullOrEmpty(resp)) + if (!string.IsNullOrEmpty(resp) && resp.Length > 2) { try { diff --git a/IOB-WIN-NEXT/IobNet/Ftp.cs b/IOB-WIN-NEXT/IobNet/Ftp.cs index 2668ae9b..c79dfb9e 100644 --- a/IOB-WIN-NEXT/IobNet/Ftp.cs +++ b/IOB-WIN-NEXT/IobNet/Ftp.cs @@ -11,6 +11,7 @@ using System.Linq; using System.Net.NetworkInformation; using System.Text; using System.Threading.Tasks; +using static System.Windows.Forms.VisualStyles.VisualStyleElement; namespace IOB_WIN_NEXT.IobNet { @@ -56,8 +57,33 @@ namespace IOB_WIN_NEXT.IobNet if (!string.IsNullOrEmpty(ftpConfFile)) { loadFtpConfFile(ftpConfFile); + // mi calcolo ed imposto la remoteBaseDir... + string actKey = "RemoteDir"; + if (currFtpTaskList != null && currFtpTaskList.ListTask.Count > 0) + { + // prendo i task + foreach (var fTask in currFtpTaskList.ListTask) + { + if (string.IsNullOrEmpty(RemoteBaseDir)) + { + foreach (var fAct in fTask.StepsList) + { + // cerco nei parametri... + if (fAct.ParamList.ContainsKey(actKey)) + { + RemoteBaseDir = fAct.ParamList[actKey]; + break; + } + } + } + } + } } } + /// + /// Directpry remota di abse + /// + private string RemoteBaseDir { get; set; } = ""; #endregion Public Constructors @@ -69,94 +95,133 @@ namespace IOB_WIN_NEXT.IobNet /// public override Dictionary executeTasks(Dictionary task2exe) { - // il compito della richiesta è SEMPRE scrivere folder dell'ODL corrente SE NON LA TROVASSE - - // uso metodo base x salvare esito scrittura - var writeResult = base.executeTasks(task2exe); - -#if false /*--------------------------------------------------------------------------- - * va creata una folder x ogni ODL (una volta LANCIATO da tablet) APERTO - * - nella folder scriviamo un file con articolo, qta, commessa - * - la folder sarà usata x salvare OGNI file necessario e di rilevazione - *---------------------------------------------------------------------------*/ + * va creata una folder x ogni ODL (una volta LANCIATO da tablet) APERTO + * - nella folder scriviamo un file con articolo, qta, commessa + * - la folder sarà usata x salvare OGNI file necessario e di rilevazione + * - per farlo si creeano degli ActionStep specifici e vengono poi richiamati... + *---------------------------------------------------------------------------*/ - // aggiungo comportamento custom: se ho impostato nome ricetta (programma) --> imposto - // richiesta caricamento se ho richiesto reset o fine lavoro --> imposto azzeramento - // esco restituendo risutlato scrittura iniziali - if (task2exe != null) + // Verificare il protocollo: dovrebbe togliere SOLO i task eseguiti... + Dictionary taskDone = new Dictionary(); + ActionConfig currAct = new ActionConfig(); + var currActParam = new Dictionary(); + string actKey = "RemoteDir"; + string newDir = ""; + bool taskOk = false; + string taskVal = ""; + // cerco task specifici: se ho startSetup --> imposto bit DBB701.DBB0.4 + foreach (var item in task2exe) { - // controllo se memMap != null... - if (memMap != null) + taskOk = false; + taskVal = ""; + // converto richiesta in enum... + taskType tName = taskType.nihil; + Enum.TryParse(item.Key, out tName); + // controllo sulla KEY... + switch (tName) { - bool taskOk = false; - string taskVal = ""; - // cerco task specifici x OMP - foreach (var item in task2exe) - { - taskOk = false; - taskVal = ""; - // converto richiesta in enum... - taskType tName = taskType.nihil; - Enum.TryParse(item.Key, out tName); - // controllo sulla KEY... - switch (tName) + case taskType.setComm: + /*------------------------------------------------------------------ + * La commessa è la cartella DI BASE per poter poi procedere con acquisizione dati... + * - step 1: check folder + * - step 2: creazione folder + ------------------------------------------------------------------*/ + // compongo remDir dai 2 parametri... + newDir = $"{RemoteBaseDir}/{item.Value}"; + currActParam.Add(actKey, newDir); + currAct = new ActionConfig() { -#if false - case taskType.setProg: - // recupero dati da memMap... - if (memMap != null && memMap.mMapWrite != null) - { - if (memMap.mMapWrite.ContainsKey(item.Key)) - { - dataConf currMem = memMap.mMapWrite[item.Key]; - string addr = currMem.memAddr; - taskVal = $"SET task: {item.Key} --> {item.Value} | mem: {currMem.memAddr} - {currMem.size} byte"; - // salvo il nuovo valore nella memoria... così prox invio lo trasmetterà - memMap.mMapWrite[item.Key].value = item.Value; - } - else - { - taskVal = $"NO DATA MEM, SET task: {item.Key} --> {item.Value}"; - } - } - else - { - taskVal = $"NO MemMap found, SET task: {item.Key} --> {item.Value}"; - } - // salvo in currProd.. - saveProdData(new KeyValuePair(item.Key, item.Value)); - - break; - - case taskType.startSetup: - setFineLotto(); - break; - - case taskType.stopSetup: - setInizioProd(); - break; - - case taskType.syncDbData: - processDataSync(); - break; -#endif - - default: - taskVal = $"taskReq: {tName} | key: {item.Key} | val: {item.Value} | SKIPPED | NO EXEC"; - lgInfo($"Chiamata senza processing: taskOk: {taskOk} | taskVal: {taskVal}"); - break; + Id = "01", + Description = "Verifica esistenza directory", + Action = ActType.CheckDir, + ParamList = currActParam + }; + //eseguo step... + bool dirOk = doStep(currAct); + // se la cartella mancasse + if (!dirOk) + { + // nuovo act x crearla! + currAct = new ActionConfig() + { + Id = "02", + Description = "Creazione directory", + Action = ActType.CreateDir, + ParamList = currActParam + }; + //eseguo step... + dirOk = doStep(currAct); + if (dirOk) + { + taskVal = $"DIR Created: {item.Key} --> {item.Value}"; + } } - } + else + { + taskVal = $"DIR Already Exists: {item.Key} --> {item.Value}"; + } + // salvo in currProd.. + saveProdData(new KeyValuePair(item.Key, item.Value)); + break; + + case taskType.setArt: + /*------------------------------------------------------------------ + * Articolo è un file nella cartella commessa di info accessorie... + * - step 1: check info folder presente in prod data + * - step 2: creazione file info con articolo e commessa + ------------------------------------------------------------------*/ +#if false + // compongo remDir dai 2 parametri... + newDir = $"{remDir}/{item.Value}"; + currParam.Add(actKey, newDir); + currAct = new ActionConfig() + { + Id = "01", + Description = "Verifica esistenza directory", + Action = ActType.CheckDir, + ParamList = currParam + }; + //eseguo step... + bool dirOk = doStep(currAct); + // se la cartella mancasse + if (!dirOk) + { + // nuovo act x crearla! + currAct = new ActionConfig() + { + Id = "02", + Description = "Creazione directory", + Action = ActType.CreateDir, + ParamList = currParam + }; + //eseguo step... + dirOk = doStep(currAct); + if (dirOk) + { + taskVal = $"DIR Created: {item.Key} --> {item.Value}"; + } + } + else + { + taskVal = $"DIR Already Exists: {item.Key} --> {item.Value}"; + } + // salvo in currProd.. + saveProdData(new KeyValuePair(item.Key, item.Value)); +#endif + break; + default: + taskVal = $"taskReq: {tName} | key: {item.Key} | val: {item.Value} | SKIPPED | NO EXEC"; + lgInfo($"Chiamata senza processing: taskOk: {taskOk} | taskVal: {taskVal}"); + break; } - else + // aggiungo task SE svolto! + if (!string.IsNullOrEmpty(taskVal)) { - lgError($"Attenzione! memMap è nullo, non posso eseguire task2exe!"); + taskDone.Add(item.Key, taskVal); } } -#endif - - return writeResult; + return taskDone; } /// @@ -253,9 +318,15 @@ namespace IOB_WIN_NEXT.IobNet { B_input = 0; } + + // aggiungo NON emergenza... + B_input += (1 << 7); + +#if false // annullo lettura bit signal IN pre/post x evitare invio automatico... B_output = B_input; - B_previous = B_input; + B_previous = B_input; +#endif } catch { diff --git a/IOB-WIN-NEXT/IobOpc/OpcUaMBHCimolai.cs b/IOB-WIN-NEXT/IobOpc/OpcUaMBHCimolai.cs index e4252b5a..17cf75ca 100644 --- a/IOB-WIN-NEXT/IobOpc/OpcUaMBHCimolai.cs +++ b/IOB-WIN-NEXT/IobOpc/OpcUaMBHCimolai.cs @@ -78,7 +78,7 @@ namespace IOB_WIN_NEXT.IobOpc // aggiungo comportamento custom: se ho impostato nome ricetta (programma) --> imposto // richiesta caricamento se ho richiesto reset o fine lavoro --> imposto azzeramento - // esco restituendo risutlato scrittura iniziali + // esco restituendo risultato scrittura iniziali if (task2exe != null) { // controllo se memMap != null...