From 4ea2cebfeb2cf29bf96e1f85aa8e725650751b36 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Wed, 24 Jun 2020 19:14:59 +0200 Subject: [PATCH] Draft for new overview calculation (to be checked) --- Thermo.Active.NC/NcAdapter.cs | 39 ++++++++++++++++--- Thermo.Active.NC/NcFileAdapter.cs | 16 ++++++++ .../Controllers/WebApi/RecipeController.cs | 14 ++++++- 3 files changed, 63 insertions(+), 6 deletions(-) diff --git a/Thermo.Active.NC/NcAdapter.cs b/Thermo.Active.NC/NcAdapter.cs index ba2e6f68..8ba155a0 100644 --- a/Thermo.Active.NC/NcAdapter.cs +++ b/Thermo.Active.NC/NcAdapter.cs @@ -1891,6 +1891,7 @@ namespace Thermo.Active.NC public CmsError GetRecipeOverview(out Dictionary currOverview) { CmsError libraryError = NO_ERROR; + // overview di base: ultima salvata... currOverview = new Dictionary(); // leggo la ricetta! @@ -1915,15 +1916,36 @@ namespace Thermo.Active.NC RecipeCatStatus currStatus = RecipeCatStatus.Unchanged; - // percorro conf ricetta... + // da conf ricetta --> verifico dati LIVE ricetta e se mancassero imposto unchanged.. + currOverview = NcFileAdapter.RecipeLiveData.RecipeOverview; + bool changed = false; foreach (var item in recipeConfig) { + if (!currOverview.ContainsKey(item.Category)) + { + currOverview.Add(item.Category, RecipeCatStatus.Unchanged); + changed = true; + } + } + // se cambiato --> salvo! + if (changed) + { + NcFileAdapter.RecipeLiveData.RecipeOverview = currOverview; + } + + // ORA percorro conf ricetta x cercare eventuali ERRORI...... + foreach (var item in recipeConfig) + { +#if false currStatus = RecipeCatStatus.Unchanged; // cerco SE ci sia già uno status... if (currOverview.ContainsKey(item.Category)) { currStatus = currOverview[item.Category]; - } + } +#endif + + currStatus = currOverview[item.Category]; // se lo stato è errore --> esco... if (currStatus == RecipeCatStatus.HasError) @@ -1936,8 +1958,12 @@ namespace Thermo.Active.NC // se in errore --> registro... if (currRecipe[item.Label].Status.HasError) { - currStatus = RecipeCatStatus.HasError; +#if false + currStatus = RecipeCatStatus.HasError; +#endif + currOverview[item.Category] = RecipeCatStatus.HasError; } +#if false // FARE verificare il significato di questo changed (se è da file o da HMI/PLC) else if (currRecipe[item.Label].SetpointHMI != currRecipe[item.Label].SetpointPLC) { @@ -1946,9 +1972,11 @@ namespace Thermo.Active.NC else { currStatus = RecipeCatStatus.Unchanged; - } + } +#endif } +#if false // ora verifico overview finale: se non c'è aggiungo if (!currOverview.ContainsKey(item.Category)) { @@ -1958,7 +1986,8 @@ namespace Thermo.Active.NC { // se il valore è maggiore --> aggiorno currOverview[item.Category] = (int)currStatus > (int)currOverview[item.Category] ? currStatus : currOverview[item.Category]; - } + } +#endif } // restituisco cod errore se trovato diff --git a/Thermo.Active.NC/NcFileAdapter.cs b/Thermo.Active.NC/NcFileAdapter.cs index 3474cba1..62de6cc8 100644 --- a/Thermo.Active.NC/NcFileAdapter.cs +++ b/Thermo.Active.NC/NcFileAdapter.cs @@ -594,6 +594,22 @@ namespace Thermo.Active.NC #region recipe file persistence + /// + /// Upsert recipe overview status + /// + /// + /// + public static void upsRecipeOverview(string section, RecipeCatStatus status) + { + if (RecipeLiveData.RecipeOverview.ContainsKey(section)) + { + RecipeLiveData.RecipeOverview[section] = status; + } + else + { + RecipeLiveData.RecipeOverview.Add(section, status); + } + } public static void ReadLastRecipe() { diff --git a/Thermo.Active/Controllers/WebApi/RecipeController.cs b/Thermo.Active/Controllers/WebApi/RecipeController.cs index c5081cea..226c8809 100644 --- a/Thermo.Active/Controllers/WebApi/RecipeController.cs +++ b/Thermo.Active/Controllers/WebApi/RecipeController.cs @@ -61,7 +61,7 @@ namespace Thermo.Active.Controllers.WebApi } [Route("update"), HttpPut] - public IHttpActionResult WriteParameters(Dictionary parametersList) + public IHttpActionResult WriteParameters(Dictionary parametersList, string section) { if (parametersList != null) { @@ -104,6 +104,18 @@ namespace Thermo.Active.Controllers.WebApi // scrivo sul PLC ncAdapter.WriteRecipeParams(updtRecipe); + // SE HO una section != null/empty --> salvo come modificata... + if (!string.IsNullOrEmpty(section)) + { + try + { + NcFileAdapter.upsRecipeOverview(section, RecipeCatStatus.ChangedOk); + } + catch (Exception exc) + { + ThermoActiveLogger.LogError($"Error on set recipe overview | section: {section}{Environment.NewLine}{exc}"); + } + } // ritorno solo fatto! return Ok(); }