From 17cf09243da9a48eff21914ca31a25824f9416cd Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Mon, 21 Oct 2019 19:28:02 +0200 Subject: [PATCH] Bozza update x gestione rispsote da REDIS --- AppData/ComLib.cs | 155 ++++++++++++++++-- NKC_WF/Images/test - Copia (2).svg | 25 --- NKC_WF/NKC_WF.csproj | 1 - .../WebUserControls/cmp_batchDetail.ascx.cs | 2 +- .../cmp_offOrderDetail.ascx.cs | 23 ++- 5 files changed, 149 insertions(+), 57 deletions(-) delete mode 100644 NKC_WF/Images/test - Copia (2).svg diff --git a/AppData/ComLib.cs b/AppData/ComLib.cs index 16a3b66..796685a 100644 --- a/AppData/ComLib.cs +++ b/AppData/ComLib.cs @@ -1,4 +1,5 @@ using Newtonsoft.Json; +using Newtonsoft.Json.Converters; using SteamWare; using System; using System.Collections.Generic; @@ -25,13 +26,30 @@ namespace AppData protected static string redOutPath = "NKC:SERV:BREQ"; protected static string redMsgCount = "NKC:SERV:BREQ:MCount"; protected static string redMsgList = "NKC:SERV:BREQ:MList"; - protected static string redMLCurrStack = "NKC:SERV:TAKT:CurrStack"; + protected static string redNestAnsw = "NKC:NEST:BANSW"; + #endregion #region definizione classi impiegate con PROD + /// + /// Tipologia di macchina + /// + public enum mType + { + Multiax = 0, + Offline + } + /// + /// TIpologia di ordine + /// + public enum oType + { + BatchRequest = 0, + OfflineOrder + } /// /// Stati degli oggetti TAKT e Stack @@ -401,19 +419,6 @@ namespace AppData public int Qty { get; set; } } - /// - /// Classe gestione richeiste di processing per il NESTING - /// - public class Ordine - { - public string OrdCod { get; set; } - public string DestPlant { get; set; } - public string DataMatrix { get; set; } - public string ExtCode { get; set; } - public string Model { get; set; } - public int Qty { get; set; } - public List Items { get; set; } - } public class Batch { /// @@ -429,9 +434,15 @@ namespace AppData /// public int procType { get; set; } /// - /// Elenco degli ordini + /// Codice della amcchina x cui si effettua richeista /// - public List Orders { get; set; } + [JsonConverter(typeof(StringEnumConverter))] + public mType machineType { get; set; } + /// + /// Tipo di ordine richeisto + /// + [JsonConverter(typeof(StringEnumConverter))] + public oType orderType { get; set; } } /// /// Salva su redis l'oggetto dei materiali serializzato @@ -468,6 +479,15 @@ namespace AppData // ritorno return answ; } + /// + /// Restituisce elenco KVP delle buste ancora "pending" (quando processate le elimina da elenco...) + /// + /// + public static KeyValuePair[] getEnvList() + { + KeyValuePair[] answ = memLayer.ML.redGetHash(redMsgList); + return answ; + } /// /// Invia una richiesta di esecuzione di Nesting x un Batch @@ -517,7 +537,9 @@ namespace AppData { BatchId = BatchID, maxTime = mTime, - procType = pType + procType = pType, + machineType = mType.Multiax, + orderType = oType.BatchRequest }; // serializzo redVal = JsonConvert.SerializeObject(currBatch); @@ -538,6 +560,105 @@ namespace AppData return answ; } + /// + /// Invia una richiesta di esecuzione di CAM x un ordine offline + /// + /// OfflineOrder di cui si chiede processing + /// note opzionali + /// + public static bool sendOfflineOrderReq(int OffOrderID, string note) + { + bool answ = false; + // per prima cosa mi serve una "nuova busta" per inviare i messaggi + string nextEnv = getNextEnv(OffOrderID, note); + // preparo il contenuto della busta ed invio i messaggi... + try + { + int mTime = 5; + int pType = 1; + // serializzo ordini come ARRAY VUOTO + string redVal = "[]"; + // salvo + string redKey = $"{redOutPath}:{nextEnv}:ORDERS"; + // scrivo su REDIS + memLayer.ML.setRSV(redKey, redVal); + // ora ITEMS + var tblItm = DataLayer.man.taIL.getByOfflineOrder(OffOrderID); + // serializzo + redVal = JsonConvert.SerializeObject(tblItm); + // salvo + redKey = $"{redOutPath}:{nextEnv}:ITEMS"; + // scrivo su REDIS + memLayer.ML.setRSV(redKey, redVal); + // ora versione gerarchica + var currBatch = new Batch() + { + BatchId = OffOrderID, + maxTime = mTime, + procType = pType, + machineType = mType.Offline, + orderType = oType.OfflineOrder + }; + // serializzo + redVal = JsonConvert.SerializeObject(currBatch); + // salvo + redKey = $"{redOutPath}:{nextEnv}:DATA"; + // scrivo su REDIS + memLayer.ML.setRSV(redKey, redVal); + + // invio notifica che c'è una busta da processare + redKey = $"{redOutPath}:CURR"; + // scrivo su REDIS + memLayer.ML.setRSV(redKey, nextEnv); + answ = true; + } + catch (Exception exc) + { + logger.lg.scriviLog($"Eccezione in sendOfflineOrderReq:{Environment.NewLine}{exc}"); + } + // restituisco ok + return answ; + } + + /// + /// Verifica lo stato di una richiesta di esecuzione + /// + /// OfflineOrder di cui si chiede processing + /// note opzionali + /// + public static bool checkOfflineOrderReq(int OffOrderID) + { + bool answ = false; + string typeSearch = "OffOrdCalculation"; + string keyEnv = ""; + // recupero lista dei vari task APERTI... + KeyValuePair[] comAperte = getEnvList(); + // processo x cercare ordine... + foreach (var item in comAperte) + { + // cerco dove sia quello richiesto + if (item.Value.Contains(typeSearch)) + { + // controllo SE sia quello richiesto + if (item.Value == $"{OffOrderID}|{typeSearch}") + { + keyEnv = item.Key; + break; + } + } + } + // controllo e se c'è risposta --> update DB + string rawAnsw = memLayer.ML.getRSV($"{redNestAnsw}:FULL:{keyEnv}"); + if (rawAnsw != "") + { + // cerco risposta coem stack --> disegno... + + answ = true; + } + // restituisco ok + return answ; + } + #endregion #region metodi helper di conversione diff --git a/NKC_WF/Images/test - Copia (2).svg b/NKC_WF/Images/test - Copia (2).svg deleted file mode 100644 index b7456f9..0000000 --- a/NKC_WF/Images/test - Copia (2).svg +++ /dev/null @@ -1,25 +0,0 @@ - - - - - IT000002 - - - - - - IT000002 - - - IT000003 - - - - - - - - - - - diff --git a/NKC_WF/NKC_WF.csproj b/NKC_WF/NKC_WF.csproj index 0acd1e2..90776da 100644 --- a/NKC_WF/NKC_WF.csproj +++ b/NKC_WF/NKC_WF.csproj @@ -208,7 +208,6 @@ - diff --git a/NKC_WF/WebUserControls/cmp_batchDetail.ascx.cs b/NKC_WF/WebUserControls/cmp_batchDetail.ascx.cs index ee8bdeb..c6c1907 100644 --- a/NKC_WF/WebUserControls/cmp_batchDetail.ascx.cs +++ b/NKC_WF/WebUserControls/cmp_batchDetail.ascx.cs @@ -82,7 +82,7 @@ namespace NKC_WF.WebUserControls protected void lbtSendEstim_Click(object sender, EventArgs e) { - // invia a redis a a richiesta... + // invia a redis una richiesta... ComLib.sendMaterials(); ComLib.sendBatchReq(BatchId, "Estimation"); diff --git a/NKC_WF/WebUserControls/cmp_offOrderDetail.ascx.cs b/NKC_WF/WebUserControls/cmp_offOrderDetail.ascx.cs index b3b51c5..c9ea10e 100644 --- a/NKC_WF/WebUserControls/cmp_offOrderDetail.ascx.cs +++ b/NKC_WF/WebUserControls/cmp_offOrderDetail.ascx.cs @@ -54,19 +54,16 @@ namespace NKC_WF.WebUserControls protected void lbtMakeCnc_Click(object sender, EventArgs e) { bool allOk = true; - /* ************************************************ - * cerco su redis la richiesta corrente: - * - se NON C'E' ricreo richiesta - * - se c'è senza risposta --> non faccio nulla - * - se c'è e ho risposta --> update DB (status + file) - * *************************************************/ - - // !!!FIXME!!! mandare su redis richiesta CREAZIONE CNC - - // ...x ora registro richiesta di CNC COME GIA' FATTA - //DataLayer.man.taOffOL. - - + // invio tramite redis... + try + { + // ...inizio dai materiali + ComLib.sendMaterials(); + // invio VERA richeista come OFFLINE ORDER... + allOk = ComLib.sendOfflineOrderReq(OffOrdId, "OffOrdCalculation"); + } + catch (Exception exc) + { } if (allOk) {