Merge branch 'develop'

This commit is contained in:
Samuele E. Locatelli
2020-01-21 17:33:05 +01:00
4 changed files with 150 additions and 175 deletions
+140 -19
View File
@@ -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
/// <summary>
/// Calcola area REDIS per postsaizone Unload
/// Calcola area REDIS per FOGLIO in fase di scarico
/// </summary>
/// <param name="codPost"></param>
/// <param name="SheetID"></param>
/// <returns></returns>
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;
}
/// <summary>
/// Svuota elenco pezzi nella postazione di unload
/// </summary>
/// <param name="SheetID"></param>
/// <returns></returns>
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,27 +1464,135 @@ namespace AppData
return answ;
}
/// <summary>
/// Fa setup postsazione scarico (lettura da DB dell'elenco pezzi con relativo stato)
///
/// </summary>
/// <param name="sheetID"></param>
/// <returns></returns>
public bool setupPostUnload(string codPost = "01")
public static string getCurrentCss(int sheetID)
{
bool answ = false;
try
{
// svuoto...
resetPostUnload(codPost);
// ri-carico da DB
// 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);
// salvo su area REDIS
answ = true;
// elenco items da foglio!!!
var tabItems = DataLayer.man.taIL.getBySheet(sheetID);
List<string> itemsAll = new List<string>();
List<string> itemsDepo = new List<string>();
List<string> itemsCart = new List<string>();
List<string> itemsBin = new List<string>();
List<string> itemsSecOp = new List<string>();
//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);
}
}
}
catch
{ }
// 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<string> selArray = JsonConvert.DeserializeObject<List<string>>(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;
}
/// <summary>
/// Processa elenco items e salva in redis valori x css, elenchi, ...
/// </summary>
/// <param name="currCss">CSS corrente</param>
/// <param name="redKeyBase">HASH abse x area REDIS</param>
/// <param name="varName">nome variabile x elenco items</param>
/// <param name="itemList">Elenco items specifici</param>
/// <param name="dataCacheTTL">TTL della cache x salvataggio valori</param>
/// <returns></returns>
public static string saveItemData(string currCss, string redKeyBase, string varName, List<string> 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
+6 -148
View File
@@ -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,12 @@ namespace NKC_WF.Controllers
/// <param name="answ"></param>
/// <param name="_sheetID"></param>
/// <returns></returns>
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;
// dati foglio corrente
int sheetID = 0;
int.TryParse(_sheetID, out sheetID);
// recupero da REDIS!
string redKey = $"{ComLib.machineUnloadArea(_sheetID)}:Css";
string redKeyBase = $"{ComLib.machineUnloadArea(_sheetID)}";
string redKey = $"{ComLib.machineUnloadArea(sheetID)}:Css";
// se vuoto scrivo VUOTO...
if (!memLayer.ML.redKeyPresent(redKey))
{
@@ -64,144 +55,11 @@ namespace NKC_WF.Controllers
if (answ == "")
// se vuoto lo calcolo...
{
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<string> itemsAll = new List<string>();
List<string> itemsDepo = new List<string>();
List<string> itemsCart = new List<string>();
List<string> itemsBin = new List<string>();
List<string> itemsSel = new List<string>();
List<string> itemsPProc = new List<string>();
//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 != "")
{
itemsPProc.Add(item.ItemDtmx);
}
}
}
// FIX BIN
answ = saveItemData(answ, redKeyBase, "ItemsBin", itemsBin, dataCacheTTL);
// FIX CART
answ = saveItemData(answ, redKeyBase, "ItemsCart", itemsCart, dataCacheTTL);
// FIX Scaricati
answ = saveItemData(answ, redKeyBase, "ItemsDepo", itemsDepo, dataCacheTTL);
// FIX SEC-OP
answ = saveItemData(answ, redKeyBase, "ItemsSecOp", itemsPProc, dataCacheTTL);
// FIXED SEL da array oggetti selezionati...
string rawData = memLayer.ML.getRSV($"{redKeyBase}:ItemsSel");
if (!string.IsNullOrEmpty(rawData))
{
string replaceVal = "";
// deserializzo
List<string> selArray = JsonConvert.DeserializeObject<List<string>>(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);
answ = ComLib.getCurrentCss(sheetID);
}
// restituisco css
return answ;
}
private static int List<T>(T rawData)
{
throw new NotImplementedException();
}
/// <summary>
/// Processa elenco items e salva in redis valori x css, elenchi, ...
/// </summary>
/// <param name="currCss">CSS corrente</param>
/// <param name="redKeyBase">HASH abse x area REDIS</param>
/// <param name="varName">nome variabile x elenco items</param>
/// <param name="itemList">Elenco items specifici</param>
/// <param name="dataCacheTTL">TTL della cache x salvataggio valori</param>
/// <returns></returns>
private static string saveItemData(string currCss, string redKeyBase, string varName, List<string> 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/<controller>
public void Post([FromBody]string value)
{
}
// PUT api/<controller>/5
public void Put(int id, [FromBody]string value)
{
}
// DELETE api/<controller>/5
public void Delete(int id)
{
}
}
}
+3 -7
View File
@@ -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;
}
/// <summary>
@@ -27,7 +23,7 @@ namespace NKC_WF.Controllers
/// </summary>
/// <param name="SheetID"></param>
/// <returns></returns>
private static int getRevBySheet(string SheetID)
private static int getRevBySheet(int SheetID)
{
int answ;
// recupero da REDIS!
+1 -1
View File
@@ -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...