From def62190cc1829d84b749b42ffd394aa22000665 Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Tue, 21 Jan 2020 17:07:44 +0100 Subject: [PATCH 1/2] Spostati in ComLib metodi helper css --- AppData/ComLib.cs | 156 ++++++++++++++++++-- NKC_WF/Controllers/getMUCssController.cs | 86 +++-------- NKC_WF/Controllers/getMUCssRevController.cs | 10 +- NKC_WF/WebUserControls/cmp_menuTop.ascx.cs | 2 +- 4 files changed, 169 insertions(+), 85 deletions(-) diff --git a/AppData/ComLib.cs b/AppData/ComLib.cs index eb7fda2..938c678 100644 --- a/AppData/ComLib.cs +++ b/AppData/ComLib.cs @@ -5,6 +5,8 @@ using NKC_SDK; using SteamWare; using System; using System.Collections.Generic; +using System.IO; +using System.Web; namespace AppData { @@ -1425,25 +1427,36 @@ namespace AppData #region metodi x UNLOAD /// - /// Calcola area REDIS per postsaizone Unload + /// Calcola area REDIS per FOGLIO in fase di scarico /// - /// + /// /// - public static string machineUnloadArea(string codPost) + public static string machineUnloadArea(int SheetID) { - return memLayer.ML.redHash($"MachineUnload:{codPost}"); + // se 0 --> tutto l'albero, sennĂ² solo area corrente... + string answ = ""; + if (SheetID > 0) + { + answ = memLayer.ML.redHash($"MachineUnload:{SheetID}"); + } + else + { + answ = memLayer.ML.redHash($"MachineUnload"); + } + return answ; } /// /// Svuota elenco pezzi nella postazione di unload /// + /// /// - public bool resetPostUnload(string codPost = "01") + public bool resetPostUnload(int SheetID = 0) { bool answ = false; try { - memLayer.ML.redFlushKey(machineUnloadArea(codPost)); + memLayer.ML.redFlushKey(machineUnloadArea(SheetID)); answ = true; } catch @@ -1451,16 +1464,17 @@ namespace AppData return answ; } /// - /// Fa setup postsazione scarico (lettura da DB dell'elenco pezzi con relativo stato) + /// Fa setup postazione scarico (lettura da DB dell'elenco pezzi con relativo stato) /// + /// /// - public bool setupPostUnload(string codPost = "01") + public bool setupPostUnload(int SheetID = 0) { bool answ = false; try { // svuoto... - resetPostUnload(codPost); + resetPostUnload(SheetID); // ri-carico da DB // salvo su area REDIS @@ -1471,7 +1485,131 @@ namespace AppData return answ; } + public static string getCurrentCss(int sheetID) + { + // recupero da REDIS! + string redKey = $"{ComLib.machineUnloadArea(sheetID)}:Css"; + string redKeyBase = $"{ComLib.machineUnloadArea(sheetID)}"; + // TTL standard + int dataCacheTTL = memLayer.ML.cdvi("cssCacheTTL"); + dataCacheTTL = dataCacheTTL <= 0 ? 60 : dataCacheTTL; + // files + string filename = HttpContext.Current.Server.MapPath("~/Content/SheetColor.css"); + string answ = File.ReadAllText(filename); + // elenco items da foglio!!! + var tabItems = DataLayer.man.taIL.getBySheet(sheetID); + List itemsAll = new List(); + List itemsDepo = new List(); + List itemsCart = new List(); + List itemsBin = new List(); + List itemsSecOp = new List(); + + //se ho items... + if (tabItems.Count > 0) + { + // ciclo! + foreach (var item in tabItems) + { + // aggiungoncomunque a lista generale... + itemsAll.Add(item.ItemDtmx); + // controllo SE sia stato depositato... check null su campo data + if (!item.IsOnCartDateNull()) + { + itemsDepo.Add(item.ItemDtmx); + } + else if (item.ProcessesReq.Contains("PaintFlag")) + { + itemsBin.Add(item.ItemDtmx); + } + else + { + itemsCart.Add(item.ItemDtmx); + } + // controllo ANCHE postprocessing + if (item.PostProcList != "") + { + itemsSecOp.Add(item.ItemDtmx); + } + } + } + + + // FIX BIN + answ = ComLib.saveItemData(answ, redKeyBase, "ItemsBin", itemsBin, dataCacheTTL); + + // FIX CART + answ = ComLib.saveItemData(answ, redKeyBase, "ItemsCart", itemsCart, dataCacheTTL); + + // FIX Scaricati + answ = ComLib.saveItemData(answ, redKeyBase, "ItemsDepo", itemsDepo, dataCacheTTL); + + // FIX SEC-OP + answ = ComLib.saveItemData(answ, redKeyBase, "ItemsSecOp", itemsSecOp, dataCacheTTL); + + // FIXED SEL da array oggetti selezionati... + string rawData = memLayer.ML.getRSV($"{redKeyBase}:ItemsSel"); + if (!string.IsNullOrEmpty(rawData)) + { + string replaceVal = ""; + // deserializzo + List selArray = JsonConvert.DeserializeObject>(rawData); + + // ciclo x cercare x ogni chiave (sessione utente) + foreach (var item in selArray) + { + replaceVal += $"#{item},"; + } + if (replaceVal.Length > 1) + { + replaceVal = replaceVal.Remove(replaceVal.Length - 1); + } + // FIX CSS! + answ = answ.Replace("#ItemsSel", replaceVal); + replaceVal = ""; + } + + // INFINE serializzo e salvo tutti gli items trovati... + string serVal = JsonConvert.SerializeObject(itemsAll); + memLayer.ML.setRSV($"{redKeyBase}:ItemsAll", serVal, dataCacheTTL); + + // salvo redis css! + memLayer.ML.setRSV(redKey, answ, dataCacheTTL); + + return answ; + } + + /// + /// Processa elenco items e salva in redis valori x css, elenchi, ... + /// + /// CSS corrente + /// HASH abse x area REDIS + /// nome variabile x elenco items + /// Elenco items specifici + /// TTL della cache x salvataggio valori + /// + public static string saveItemData(string currCss, string redKeyBase, string varName, List itemList, int dataCacheTTL) + { + string replaceVal = ""; + if (itemList.Count > 0) + { + foreach (var item in itemList) + { + replaceVal += $"#{item},"; + } + if (replaceVal.Length > 1) + { + replaceVal = replaceVal.Remove(replaceVal.Length - 1); + } + // FIX CSS! + currCss = currCss.Replace($"#{varName}", replaceVal); + replaceVal = ""; + //serializzo e salvo + string serVal = JsonConvert.SerializeObject(itemList); + memLayer.ML.setRSV($"{redKeyBase}:{varName}", serVal, dataCacheTTL); + } + return currCss; + } #endregion diff --git a/NKC_WF/Controllers/getMUCssController.cs b/NKC_WF/Controllers/getMUCssController.cs index c014ef3..0046a4b 100644 --- a/NKC_WF/Controllers/getMUCssController.cs +++ b/NKC_WF/Controllers/getMUCssController.cs @@ -17,8 +17,7 @@ namespace NKC_WF.Controllers // GET api/getMUCssController public HttpResponseMessage Get() { - string SheetID = "0"; - string answ = getCssByPost(SheetID); + string answ = getCssByPost(0); return new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(answ, Encoding.UTF8, "text/css") @@ -28,8 +27,7 @@ namespace NKC_WF.Controllers // GET api/getMUCssController/5 public HttpResponseMessage Get(int id) { - string SheetID = id.ToString(); - string answ = getCssByPost(SheetID); + string answ = getCssByPost(id); return new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(answ, Encoding.UTF8, "text/css") @@ -41,19 +39,21 @@ namespace NKC_WF.Controllers /// /// /// - private static string getCssByPost(string _sheetID) + private static string getCssByPost(int sheetID) { // var base string answ = ""; // TTL standard int dataCacheTTL = memLayer.ML.cdvi("cssCacheTTL"); dataCacheTTL = dataCacheTTL <= 0 ? 60 : dataCacheTTL; +#if false // dati foglio corrente int sheetID = 0; - int.TryParse(_sheetID, out sheetID); + int.TryParse(_sheetID, out sheetID); +#endif // recupero da REDIS! - string redKey = $"{ComLib.machineUnloadArea(_sheetID)}:Css"; - string redKeyBase = $"{ComLib.machineUnloadArea(_sheetID)}"; + string redKey = $"{ComLib.machineUnloadArea(sheetID)}:Css"; + string redKeyBase = $"{ComLib.machineUnloadArea(sheetID)}"; // se vuoto scrivo VUOTO... if (!memLayer.ML.redKeyPresent(redKey)) { @@ -64,6 +64,8 @@ namespace NKC_WF.Controllers if (answ == "") // se vuoto lo calcolo... { + answ = ComLib.getCurrentCss(sheetID); +#if false string filename = HttpContext.Current.Server.MapPath("~/Content/SheetColor.css"); answ = File.ReadAllText(filename); @@ -73,8 +75,7 @@ namespace NKC_WF.Controllers List itemsDepo = new List(); List itemsCart = new List(); List itemsBin = new List(); - List itemsSel = new List(); - List itemsPProc = new List(); + List itemsSecOp = new List(); //se ho items... if (tabItems.Count > 0) @@ -100,23 +101,23 @@ namespace NKC_WF.Controllers // controllo ANCHE postprocessing if (item.PostProcList != "") { - itemsPProc.Add(item.ItemDtmx); + itemsSecOp.Add(item.ItemDtmx); } } } // FIX BIN - answ = saveItemData(answ, redKeyBase, "ItemsBin", itemsBin, dataCacheTTL); + answ = ComLib.saveItemData(answ, redKeyBase, "ItemsBin", itemsBin, dataCacheTTL); // FIX CART - answ = saveItemData(answ, redKeyBase, "ItemsCart", itemsCart, dataCacheTTL); + answ = ComLib.saveItemData(answ, redKeyBase, "ItemsCart", itemsCart, dataCacheTTL); // FIX Scaricati - answ = saveItemData(answ, redKeyBase, "ItemsDepo", itemsDepo, dataCacheTTL); + answ = ComLib.saveItemData(answ, redKeyBase, "ItemsDepo", itemsDepo, dataCacheTTL); // FIX SEC-OP - answ = saveItemData(answ, redKeyBase, "ItemsSecOp", itemsPProc, dataCacheTTL); + answ = ComLib.saveItemData(answ, redKeyBase, "ItemsSecOp", itemsSecOp, dataCacheTTL); // FIXED SEL da array oggetti selezionati... string rawData = memLayer.ML.getRSV($"{redKeyBase}:ItemsSel"); @@ -145,63 +146,12 @@ namespace NKC_WF.Controllers memLayer.ML.setRSV($"{redKeyBase}:ItemsAll", serVal, dataCacheTTL); // salvo redis css! - memLayer.ML.setRSV(redKey, answ, dataCacheTTL); + memLayer.ML.setRSV(redKey, answ, dataCacheTTL); +#endif } return answ; } - private static int List(T rawData) - { - throw new NotImplementedException(); - } - - /// - /// Processa elenco items e salva in redis valori x css, elenchi, ... - /// - /// CSS corrente - /// HASH abse x area REDIS - /// nome variabile x elenco items - /// Elenco items specifici - /// TTL della cache x salvataggio valori - /// - private static string saveItemData(string currCss, string redKeyBase, string varName, List itemList, int dataCacheTTL) - { - string replaceVal = ""; - if (itemList.Count > 0) - { - foreach (var item in itemList) - { - replaceVal += $"#{item},"; - } - if (replaceVal.Length > 1) - { - replaceVal = replaceVal.Remove(replaceVal.Length - 1); - } - // FIX CSS! - currCss = currCss.Replace($"#{varName}", replaceVal); - replaceVal = ""; - //serializzo e salvo - string serVal = JsonConvert.SerializeObject(itemList); - memLayer.ML.setRSV($"{redKeyBase}:{varName}", serVal, dataCacheTTL); - } - return currCss; - } - - - // POST api/ - public void Post([FromBody]string value) - { - } - - // PUT api//5 - public void Put(int id, [FromBody]string value) - { - } - - // DELETE api//5 - public void Delete(int id) - { - } } } \ No newline at end of file diff --git a/NKC_WF/Controllers/getMUCssRevController.cs b/NKC_WF/Controllers/getMUCssRevController.cs index 6febac7..ae508f7 100644 --- a/NKC_WF/Controllers/getMUCssRevController.cs +++ b/NKC_WF/Controllers/getMUCssRevController.cs @@ -9,17 +9,13 @@ namespace NKC_WF.Controllers // GET api/getMUCssRev public int Get() { - int answ = 0; - string SheetID = "0"; - answ = getRevBySheet(SheetID); + int answ = getRevBySheet(0); return answ; } // GET api/getMUCssRev/5 public int Get(int id) { - int answ = 0; - string SheetID = id.ToString(); - answ = getRevBySheet(SheetID); + int answ = getRevBySheet(id); return answ; } /// @@ -27,7 +23,7 @@ namespace NKC_WF.Controllers /// /// /// - private static int getRevBySheet(string SheetID) + private static int getRevBySheet(int SheetID) { int answ; // recupero da REDIS! diff --git a/NKC_WF/WebUserControls/cmp_menuTop.ascx.cs b/NKC_WF/WebUserControls/cmp_menuTop.ascx.cs index 0ec3276..31e2e10 100644 --- a/NKC_WF/WebUserControls/cmp_menuTop.ascx.cs +++ b/NKC_WF/WebUserControls/cmp_menuTop.ascx.cs @@ -110,7 +110,7 @@ namespace NKC_WF.WebUserControls if (doFullReset) { // reset REDIS x css - ComLib.man.resetPostUnload(""); + ComLib.man.resetPostUnload(); // aggiorno vocabolario DataWrap.DW.resetVocabolario(); // reset dati in cache x DbConfig... From 9e318fa44b1bc325a484e638de04d1da921a1beb Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Tue, 21 Jan 2020 17:32:45 +0100 Subject: [PATCH 2/2] completo refactor in comLib x css x gestire insert selezione --- AppData/ComLib.cs | 21 +----- NKC_WF/Controllers/getMUCssController.cs | 94 +----------------------- 2 files changed, 3 insertions(+), 112 deletions(-) diff --git a/AppData/ComLib.cs b/AppData/ComLib.cs index 938c678..409bd96 100644 --- a/AppData/ComLib.cs +++ b/AppData/ComLib.cs @@ -1464,27 +1464,10 @@ namespace AppData return answ; } /// - /// Fa setup postazione scarico (lettura da DB dell'elenco pezzi con relativo stato) + /// /// - /// + /// /// - public bool setupPostUnload(int SheetID = 0) - { - bool answ = false; - try - { - // svuoto... - resetPostUnload(SheetID); - // ri-carico da DB - - // salvo su area REDIS - answ = true; - } - catch - { } - return answ; - } - public static string getCurrentCss(int sheetID) { // recupero da REDIS! diff --git a/NKC_WF/Controllers/getMUCssController.cs b/NKC_WF/Controllers/getMUCssController.cs index 0046a4b..75bb7f4 100644 --- a/NKC_WF/Controllers/getMUCssController.cs +++ b/NKC_WF/Controllers/getMUCssController.cs @@ -43,17 +43,8 @@ namespace NKC_WF.Controllers { // var base string answ = ""; - // TTL standard - int dataCacheTTL = memLayer.ML.cdvi("cssCacheTTL"); - dataCacheTTL = dataCacheTTL <= 0 ? 60 : dataCacheTTL; -#if false - // dati foglio corrente - int sheetID = 0; - int.TryParse(_sheetID, out sheetID); -#endif // recupero da REDIS! string redKey = $"{ComLib.machineUnloadArea(sheetID)}:Css"; - string redKeyBase = $"{ComLib.machineUnloadArea(sheetID)}"; // se vuoto scrivo VUOTO... if (!memLayer.ML.redKeyPresent(redKey)) { @@ -65,91 +56,8 @@ namespace NKC_WF.Controllers // se vuoto lo calcolo... { answ = ComLib.getCurrentCss(sheetID); -#if false - string filename = HttpContext.Current.Server.MapPath("~/Content/SheetColor.css"); - answ = File.ReadAllText(filename); - - // elenco items da foglio!!! - var tabItems = DataLayer.man.taIL.getBySheet(sheetID); - List itemsAll = new List(); - List itemsDepo = new List(); - List itemsCart = new List(); - List itemsBin = new List(); - List itemsSecOp = new List(); - - //se ho items... - if (tabItems.Count > 0) - { - // ciclo! - foreach (var item in tabItems) - { - // aggiungoncomunque a lista generale... - itemsAll.Add(item.ItemDtmx); - // controllo SE sia stato depositato... check null su campo data - if (!item.IsOnCartDateNull()) - { - itemsDepo.Add(item.ItemDtmx); - } - else if (item.ProcessesReq.Contains("PaintFlag")) - { - itemsBin.Add(item.ItemDtmx); - } - else - { - itemsCart.Add(item.ItemDtmx); - } - // controllo ANCHE postprocessing - if (item.PostProcList != "") - { - itemsSecOp.Add(item.ItemDtmx); - } - } - } - - - // FIX BIN - answ = ComLib.saveItemData(answ, redKeyBase, "ItemsBin", itemsBin, dataCacheTTL); - - // FIX CART - answ = ComLib.saveItemData(answ, redKeyBase, "ItemsCart", itemsCart, dataCacheTTL); - - // FIX Scaricati - answ = ComLib.saveItemData(answ, redKeyBase, "ItemsDepo", itemsDepo, dataCacheTTL); - - // FIX SEC-OP - answ = ComLib.saveItemData(answ, redKeyBase, "ItemsSecOp", itemsSecOp, dataCacheTTL); - - // FIXED SEL da array oggetti selezionati... - string rawData = memLayer.ML.getRSV($"{redKeyBase}:ItemsSel"); - if (!string.IsNullOrEmpty(rawData)) - { - string replaceVal = ""; - // deserializzo - List selArray = JsonConvert.DeserializeObject>(rawData); - - // ciclo x cercare x ogni chiave (sessione utente) - foreach (var item in selArray) - { - replaceVal += $"#{item},"; - } - if (replaceVal.Length > 1) - { - replaceVal = replaceVal.Remove(replaceVal.Length - 1); - } - // FIX CSS! - answ = answ.Replace("#ItemsSel", replaceVal); - replaceVal = ""; - } - - // INFINE serializzo e salvo tutti gli items trovati... - string serVal = JsonConvert.SerializeObject(itemsAll); - memLayer.ML.setRSV($"{redKeyBase}:ItemsAll", serVal, dataCacheTTL); - - // salvo redis css! - memLayer.ML.setRSV(redKey, answ, dataCacheTTL); -#endif } - + // restituisco css return answ; }