diff --git a/Thermo.Active.Model/DTOModels/Recipe/DTOModulesBlock.cs b/Thermo.Active.Model/DTOModels/Recipe/DTOModulesBlock.cs index 33aca349..91b74aa4 100644 --- a/Thermo.Active.Model/DTOModels/Recipe/DTOModulesBlock.cs +++ b/Thermo.Active.Model/DTOModels/Recipe/DTOModulesBlock.cs @@ -3,18 +3,28 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using static Thermo.Active.Model.Constants; namespace Thermo.Active.Model.DTOModels.Recipe { public class DTOModulesBlock { public int Id { get; set; } = 0; - public double SetpointHMI { get; set; } = 0; - public double SetpointPLC { get; set; } = 0; - //public RPRange Range { get; set; } - //public RPStatus Status { get; set; } - public string UnitMeasure { get; set; } - public double ValueAct { get; set; } + public string LocalizedLabel { get; set; } = ""; + public TACT_MBLOCK_TYPE Type { get; set; } = TACT_MBLOCK_TYPE.ND; + public TACT_MBLOCK_SECTION Section { get; set; } = TACT_MBLOCK_SECTION.ND; + public int IdParam { get; set; } = 0; + public bool ShowDelay { get; set; } = false; + public int Priority { get; set; } = 0; + public int ActualDelay { get; set; } = 0; + public int ActualDuration { get; set; } = 0; + public int EstimatedDelay { get; set; } = 0; + public int EstimatedDuration { get; set; } = 0; + public List PrecedingId { get; set; } = new List(); + public bool Visible { get; set; } = false; + public bool Running { get; set; } = false; + public bool HasError { get; set; } = false; + public override bool Equals(object obj) { @@ -23,17 +33,33 @@ namespace Thermo.Active.Model.DTOModels.Recipe if (Id!= item.Id) return false; - if (SetpointHMI != item.SetpointHMI) + if (LocalizedLabel != item.LocalizedLabel) return false; - if (SetpointPLC != item.SetpointPLC) + if (Type != item.Type) return false; - //if (!Range.Equals(item.Range)) - // return false; - //if (!Status.Equals(item.Status)) - // return false; - if (UnitMeasure != item.UnitMeasure) + if (Section != item.Section) return false; - if (ValueAct != item.ValueAct) + if (IdParam != item.IdParam) + return false; + if (ShowDelay != item.ShowDelay) + return false; + if (Priority != item.Priority) + return false; + if (ActualDelay != item.ActualDelay) + return false; + if (ActualDuration != item.ActualDuration) + return false; + if (EstimatedDelay != item.EstimatedDelay) + return false; + if (EstimatedDuration != item.EstimatedDuration) + return false; + if (PrecedingId != item.PrecedingId) + return false; + if (Visible != item.Visible) + return false; + if (Running != item.Running) + return false; + if (HasError != item.HasError) return false; return true; diff --git a/Thermo.Active.NC/NcAdapter.cs b/Thermo.Active.NC/NcAdapter.cs index 328d6d05..ac139137 100644 --- a/Thermo.Active.NC/NcAdapter.cs +++ b/Thermo.Active.NC/NcAdapter.cs @@ -2042,22 +2042,62 @@ namespace Thermo.Active.NC CmsError cmsError = NO_ERROR; currModules = new Dictionary(); - // FIXME TODO -#if false - DTORecipeParam currParam = new DTORecipeParam(); - RPRange currRange = new RPRange(); - RPStatus currStatus = new RPStatus(); - // gestione errore - cmsError = ReadRecipeData(false, true, out currModules); + cmsError = ReadModBlock(out currModules); if (cmsError.IsError()) - return cmsError; -#endif + return cmsError; // restituisco cod errore se trovato return cmsError; } + public CmsError ReadModBlock(out Dictionary currModules) + { + + CmsError cmsError = NO_ERROR; + currModules = new Dictionary(); + DTOModulesBlock currVal = new DTOModulesBlock(); + + // read and return warmers data + if (NcConfig.NcVendor == NC_VENDOR.S7NET) + { + Dictionary currModBlock = new Dictionary(); + cmsError = numericalControl.PLC_RModulesBlockList(false, ref currModBlock); + + foreach (var item in ModBlockConfig) + { + try + { + ThermoModels.ModuleBlock currModule = currModBlock[item.Id]; + currVal = new DTOModulesBlock() + { + Id = item.Id, + LocalizedLabel = item.LocalizedLabels["ITA"], // FIXME TODO check come gestire traduzione!!! + Type = item.Type, + Section = item.Section, + IdParam = item.IdParam, + ShowDelay = item.ShowDelay, + Priority = item.Priority, + ActualDelay = currModule.ActualDelay, + ActualDuration= currModule.ActualDuration, + EstimatedDelay = currModule.EstimatedDelay, + EstimatedDuration = currModule.EstimatedDuration, + PrecedingId = currModule.PrecedingId, + Visible = currModule.Visible, + Running = currModule.Running, + HasError = currModule.HasError + }; + currModules.Add(item.Id, currVal); + } + catch(Exception exc) + { + // FIXME TODO... + } + } + } + return cmsError; + } + /// /// GEt all warmers data by channel /// @@ -2157,15 +2197,15 @@ namespace Thermo.Active.NC protected double getDimRatio(DTORecipeParam singlePar) { double ratio = 1; - if (singlePar!=null) + if (singlePar != null) { - try - { - if (singlePar.Range.Max > 0) - ratio = singlePar.SetpointPLC / singlePar.Range.Max; - } - catch - { } + try + { + if (singlePar.Range.Max > 0) + ratio = singlePar.SetpointPLC / singlePar.Range.Max; + } + catch + { } } return ratio; } diff --git a/Thermo.Active.Utils/ExceptionManager.cs b/Thermo.Active.Utils/ExceptionManager.cs index 1e5e18ba..ae04a34a 100644 --- a/Thermo.Active.Utils/ExceptionManager.cs +++ b/Thermo.Active.Utils/ExceptionManager.cs @@ -6,7 +6,7 @@ using System.Windows.Forms; using Thermo.Active.Model; using TeamDev.SDK.MVVM; using static Thermo.Active.Model.Constants; -using static Thermo.Active.Utils.StepLogger; +using static Thermo.Active.Utils.ThermoActiveLogger; namespace Thermo.Active.Utils { diff --git a/Thermo.Active.Utils/Thermo.Active.Utils.csproj b/Thermo.Active.Utils/Thermo.Active.Utils.csproj index 84d52738..9dfdcc83 100644 --- a/Thermo.Active.Utils/Thermo.Active.Utils.csproj +++ b/Thermo.Active.Utils/Thermo.Active.Utils.csproj @@ -69,7 +69,7 @@ - + diff --git a/Thermo.Active.Utils/StepLogger.cs b/Thermo.Active.Utils/ThermoActiveLogger.cs similarity index 97% rename from Thermo.Active.Utils/StepLogger.cs rename to Thermo.Active.Utils/ThermoActiveLogger.cs index 1fdf2c04..58980e37 100644 --- a/Thermo.Active.Utils/StepLogger.cs +++ b/Thermo.Active.Utils/ThermoActiveLogger.cs @@ -4,7 +4,7 @@ using static Thermo.Active.Model.Constants; namespace Thermo.Active.Utils { - public static class StepLogger + public static class ThermoActiveLogger { private static Logger Log = LogManager.GetCurrentClassLogger(); diff --git a/Thermo.Active/Controllers/WebApi/ModulesController.cs b/Thermo.Active/Controllers/WebApi/ModulesController.cs index 035927cc..22927ded 100644 --- a/Thermo.Active/Controllers/WebApi/ModulesController.cs +++ b/Thermo.Active/Controllers/WebApi/ModulesController.cs @@ -13,6 +13,7 @@ using static CMS_CORE_Library.Models.DataStructures; using static Thermo.Active.Config.ServerConfig; using static Thermo.Active.Model.Constants; using Thermo.Active.Model.DTOModels.Recipe; +using Thermo.Active.Utils; namespace Thermo.Active.Controllers.WebApi { @@ -27,11 +28,17 @@ namespace Thermo.Active.Controllers.WebApi // Try connection CmsError libraryError = ncAdapter.Connect(); if (libraryError.errorCode != 0) - return NotFound(); + { + ThermoActiveLogger.LogError($"NC Not connected! | GetCurrentModules | {libraryError.exception}"); + return InternalServerError(); + } CmsError cmsError = ncAdapter.ReadModulesBlock(out Dictionary currModules); if (cmsError.IsError()) + { + ThermoActiveLogger.LogError($"GetRecipeOverview error | {cmsError.exception}"); return BadRequest(cmsError.localizationKey); + } return Ok(currModules); } diff --git a/Thermo.Active/Controllers/WebApi/RecipeController.cs b/Thermo.Active/Controllers/WebApi/RecipeController.cs index eca92022..c77b079e 100644 --- a/Thermo.Active/Controllers/WebApi/RecipeController.cs +++ b/Thermo.Active/Controllers/WebApi/RecipeController.cs @@ -14,6 +14,7 @@ using static Thermo.Active.Config.ServerConfig; using static Thermo.Active.Model.Constants; using Thermo.Active.Model.DTOModels.Recipe; using Thermo.Active.Config; +using Thermo.Active.Utils; namespace Thermo.Active.Controllers.WebApi { @@ -28,11 +29,17 @@ namespace Thermo.Active.Controllers.WebApi // Try connection CmsError libraryError = ncAdapter.Connect(); if (libraryError.errorCode != 0) - return NotFound(); + { + ThermoActiveLogger.LogError($"NC Not connected! | GetOverview | {libraryError.exception}"); + return InternalServerError(); + } CmsError cmsError = ncAdapter.GetRecipeOverview(out Dictionary currOverview); if (cmsError.IsError()) + { + ThermoActiveLogger.LogError($"GetRecipeOverview error | {cmsError.exception}"); return BadRequest(cmsError.localizationKey); + } return Ok(currOverview); } @@ -45,11 +52,17 @@ namespace Thermo.Active.Controllers.WebApi // Try connection CmsError libraryError = ncAdapter.Connect(); if (libraryError.errorCode != 0) - return NotFound(); + { + ThermoActiveLogger.LogError($"NC Not connected! | GetCurrentParameters | {libraryError.exception}"); + return InternalServerError(); + } CmsError cmsError = ncAdapter.ReadFullRecipe(out Dictionary currRecipe); if (cmsError.IsError()) + { + ThermoActiveLogger.LogError($"GetRecipeOverview error | {cmsError.exception}"); return BadRequest(cmsError.localizationKey); + } return Ok(currRecipe); } @@ -67,15 +80,20 @@ namespace Thermo.Active.Controllers.WebApi // Try connection CmsError libraryError = ncAdapter.Connect(); if (libraryError.errorCode != 0) - return NotFound(); + { + ThermoActiveLogger.LogError($"NC Not connected! | WriteParameters | {libraryError.exception}"); + return InternalServerError(); + } // read recipe! CmsError cmsError = ncAdapter.ReadFullRecipe(out Dictionary prevRecipe); if (cmsError.IsError()) + { + ThermoActiveLogger.LogError($"GetRecipeOverview error | {cmsError.exception}"); return BadRequest(cmsError.localizationKey); + } Dictionary updtRecipe = new Dictionary(); - foreach (var item in parametersList) { if (prevRecipe.ContainsKey(item.Key)) @@ -88,6 +106,7 @@ namespace Thermo.Active.Controllers.WebApi } else { + ThermoActiveLogger.LogError($"WriteParameters error | key not found: {item.Key}"); return NotFound(); } } @@ -102,12 +121,14 @@ namespace Thermo.Active.Controllers.WebApi else { // non pronto! + ThermoActiveLogger.LogError($"RecipeLiveData null | WriteParameters"); return InternalServerError(); } } else { - return NotFound(); + ThermoActiveLogger.LogError($"RecipeLiveData null | Empty Parameters"); + return BadRequest(); } } @@ -125,17 +146,26 @@ namespace Thermo.Active.Controllers.WebApi // Try connection CmsError libraryError = ncAdapter.Connect(); if (libraryError.errorCode != 0) - return NotFound(); + { + ThermoActiveLogger.LogError($"NC Not connected! | Recipe ConfirmEdit | {libraryError.exception}"); + return InternalServerError(); + } // scrivo sul PLC il comando conferma! CmsError cmsError = ncAdapter.ConfirmRecipeData(true); if (cmsError.IsError()) + { + ThermoActiveLogger.LogError($"ConfirmEdit error | {cmsError.exception}"); return BadRequest(cmsError.localizationKey); + } // recupero i dati LIVE dei parametri HMI della ricetta... cmsError = ncAdapter.ReadFullRecipe(out Dictionary currRecipe); if (cmsError.IsError()) + { + ThermoActiveLogger.LogError($"ConfirmEdit error | {cmsError.exception}"); return BadRequest(cmsError.localizationKey); + } // rileggo la ricetta var currParams = new Dictionary(); @@ -144,7 +174,7 @@ namespace Thermo.Active.Controllers.WebApi currParams.Add(item.Key, item.Value.SetpointHMI); } - saveCurrentRecipeParams(currParams); + SaveCurrentRecipeParams(currParams); // ritorno solo fatto! return Ok(); @@ -153,6 +183,7 @@ namespace Thermo.Active.Controllers.WebApi else { // non pronto! + ThermoActiveLogger.LogError($"RecipeLiveData null | Empty"); return InternalServerError(); } } @@ -171,17 +202,26 @@ namespace Thermo.Active.Controllers.WebApi // Try connection CmsError libraryError = ncAdapter.Connect(); if (libraryError.errorCode != 0) - return NotFound(); + { + ThermoActiveLogger.LogError($"NC Not connected! | Recipe CancelEdit | {libraryError.exception}"); + return InternalServerError(); + } // scrivo sul PLC il comando annula! CmsError cmsError = ncAdapter.ConfirmRecipeData(false); if (cmsError.IsError()) + { + ThermoActiveLogger.LogError($"ConfirmEdit error | {cmsError.exception}"); return BadRequest(cmsError.localizationKey); + } // recupero i dati LIVE dei parametri HMI della ricetta... cmsError = ncAdapter.ReadFullRecipe(out Dictionary currRecipe); if (cmsError.IsError()) + { + ThermoActiveLogger.LogError($"ConfirmEdit error | {cmsError.exception}"); return BadRequest(cmsError.localizationKey); + } var currParams = new Dictionary(); foreach (var item in currRecipe) @@ -190,7 +230,7 @@ namespace Thermo.Active.Controllers.WebApi } // ora salvo ANCHE i dati live... - saveCurrentRecipeParams(currParams); + SaveCurrentRecipeParams(currParams); // ritorno solo fatto! return Ok(); @@ -199,6 +239,7 @@ namespace Thermo.Active.Controllers.WebApi else { // non pronto! + ThermoActiveLogger.LogError($"RecipeLiveData null | Empty"); return InternalServerError(); } } @@ -215,18 +256,26 @@ namespace Thermo.Active.Controllers.WebApi // Try connection CmsError libraryError = ncAdapter.Connect(); if (libraryError.errorCode != 0) - return NotFound(); + { + ThermoActiveLogger.LogError($"NC Not connected! | Load | {libraryError.exception}"); + return InternalServerError(); + } // chiamo metodo di lettura... //CmsError cmsError = ServerConfigController.LoadRecipe(newName); bool fatto = ServerConfigController.LoadRecipe(newName); if (!fatto) + { + ThermoActiveLogger.LogError($"LoadRecipe error"); return NotFound(); + } - - CmsError cmsError = writeCurrentRecipeToPlc(); + CmsError cmsError = WriteCurrentRecipeToPlc(); if (cmsError.IsError()) + { + ThermoActiveLogger.LogError($"ConfirmEdit error | {cmsError.exception}"); return BadRequest(cmsError.localizationKey); + } // ritorno solo fatto! return Ok(); @@ -246,11 +295,17 @@ namespace Thermo.Active.Controllers.WebApi bool fatto = ServerConfigController.LoadTemplate(); if (!fatto) + { + ThermoActiveLogger.LogError($"LoadRecipe error"); return NotFound(); + } - CmsError cmsError = writeCurrentRecipeToPlc(); + CmsError cmsError = WriteCurrentRecipeToPlc(); if (cmsError.IsError()) + { + ThermoActiveLogger.LogError($"ConfirmEdit error | {cmsError.exception}"); return BadRequest(cmsError.localizationKey); + } } // ritorno solo fatto! @@ -279,7 +334,7 @@ namespace Thermo.Active.Controllers.WebApi } // ora salvo ANCHE i dati live... - saveCurrentRecipeParams(currParams); + SaveCurrentRecipeParams(currParams); // ritorno solo fatto! return Ok(); @@ -297,7 +352,10 @@ namespace Thermo.Active.Controllers.WebApi // recupero i dati LIVE dei parametri HMI della ricetta... CmsError cmsError = ncAdapter.ReadFullRecipe(out Dictionary currRecipe); if (cmsError.IsError()) + { + ThermoActiveLogger.LogError($"SaveAs error | {cmsError.exception}"); return BadRequest(cmsError.localizationKey); + } var currParams = new Dictionary(); foreach (var item in currRecipe) @@ -326,13 +384,19 @@ namespace Thermo.Active.Controllers.WebApi // recupero i dati LIVE dei parametri HMI della ricetta... CmsError cmsError = ncAdapter.ReadFullRecipe(out Dictionary currRecipe); if (cmsError.IsError()) + { + ThermoActiveLogger.LogError($"SaveTemplate error | {cmsError.exception}"); return BadRequest(cmsError.localizationKey); + } // recupero i dati LIVE dei carichi load dei cahnnels di riscaldo... cmsError = ncAdapter.ReadWarmers(out Dictionary currWarmers); if (cmsError.IsError()) + { + ThermoActiveLogger.LogError($"ReadWarmers error | {cmsError.exception}"); return BadRequest(cmsError.localizationKey); + } // uso i valopri HMI... var currParams = new Dictionary(); @@ -366,7 +430,7 @@ namespace Thermo.Active.Controllers.WebApi /// Do actual recipe parameters FileSave /// /// - private static void saveCurrentRecipeParams(Dictionary currParams) + private static void SaveCurrentRecipeParams(Dictionary currParams) { try { @@ -375,11 +439,13 @@ namespace Thermo.Active.Controllers.WebApi // e salvo su disco ServerConfigController.SaveRecipeCurrent(); } - catch - { } + catch(Exception exc) + { + ThermoActiveLogger.LogError($"Recipe | SaveCurrentRecipeParams exception | {exc}"); + } } - protected static CmsError writeCurrentRecipeToPlc() + protected static CmsError WriteCurrentRecipeToPlc() { CmsError checkError = NO_ERROR; @@ -388,13 +454,19 @@ namespace Thermo.Active.Controllers.WebApi // Try connection CmsError libraryError = ncAdapter.Connect(); if (libraryError.errorCode != 0) + { + ThermoActiveLogger.LogError($"NC Not connected! | Load | {libraryError.exception}"); return libraryError; + } // copy data to PLC checkError = ncAdapter.ReadFullRecipe(out Dictionary prevRecipe); if (checkError.IsError()) + { + ThermoActiveLogger.LogError($"WriteCurrentRecipeToPlc | ReadFullRecipe error | {checkError.exception}"); return checkError; + } // save parameters to PLC!!! Dictionary updtRecipe = new Dictionary(); @@ -410,12 +482,18 @@ namespace Thermo.Active.Controllers.WebApi } else { + ThermoActiveLogger.LogError($"prevRecipe not found | key: {item.Key}"); return NOT_FOUND_ERROR; } } // write to PLC checkError = ncAdapter.WriteRecipeParams(updtRecipe); + if (checkError.IsError()) + { + ThermoActiveLogger.LogError($"WriteCurrentRecipeToPlc | WriteRecipeParams error | {checkError.exception}"); + return checkError; + } // process ch load setup... @@ -427,11 +505,19 @@ namespace Thermo.Active.Controllers.WebApi // write to PLC checkError = ncAdapter.WriteRecipeWarmChSetpHMI(newRisk); + if (checkError.IsError()) + { + ThermoActiveLogger.LogError($"WriteCurrentRecipeToPlc | WriteRecipeWarmChSetpHMI error | {checkError.exception}"); + return checkError; + } // enable recipe! scrivo sul PLC il comando conferma! CmsError cmsError = ncAdapter.ConfirmRecipeData(true); if (cmsError.IsError()) + { + ThermoActiveLogger.LogError($"ReadWarmers error | {cmsError.exception}"); return checkError; + } } return checkError; } diff --git a/Thermo.Active/Controllers/WebApi/UserController.cs b/Thermo.Active/Controllers/WebApi/UserController.cs index 679baaad..e6d263de 100644 --- a/Thermo.Active/Controllers/WebApi/UserController.cs +++ b/Thermo.Active/Controllers/WebApi/UserController.cs @@ -42,7 +42,7 @@ namespace Thermo.Active.Controllers.WebApi var context = GlobalHost.ConnectionManager.GetHubContext(); context.Clients.All.logout(new { id = userId.Value }); - StepLogger.LogMessage("Logout: " + userId.Value + "Date:" + DateTime.Now, ERROR_LEVEL.INFO); + ThermoActiveLogger.LogMessage("Logout: " + userId.Value + "Date:" + DateTime.Now, ERROR_LEVEL.INFO); return Ok(); } diff --git a/Thermo.Active/Controllers/WebApi/WarmersController.cs b/Thermo.Active/Controllers/WebApi/WarmersController.cs index 8294ed1e..cad3695c 100644 --- a/Thermo.Active/Controllers/WebApi/WarmersController.cs +++ b/Thermo.Active/Controllers/WebApi/WarmersController.cs @@ -14,6 +14,7 @@ using static Thermo.Active.Config.ServerConfig; using static Thermo.Active.Model.Constants; using Thermo.Active.Model.DTOModels.Recipe; using Thermo.Active.Config; +using Thermo.Active.Utils; namespace Thermo.Active.Controllers.WebApi { @@ -28,11 +29,17 @@ namespace Thermo.Active.Controllers.WebApi // Try connection CmsError libraryError = ncAdapter.Connect(); if (libraryError.errorCode != 0) - return NotFound(); + { + ThermoActiveLogger.LogError($"NC Not connected! | GetCurrentWarmersChannels | {libraryError.exception}"); + return InternalServerError(); + } CmsError cmsError = ncAdapter.ReadWarmers(out Dictionary currWarmers); if (cmsError.IsError()) + { + ThermoActiveLogger.LogError($"GetRecipeOverview error | {cmsError.exception}"); return BadRequest(cmsError.localizationKey); + } return Ok(currWarmers); } @@ -45,11 +52,17 @@ namespace Thermo.Active.Controllers.WebApi // Try connection CmsError libraryError = ncAdapter.Connect(); if (libraryError.errorCode != 0) - return NotFound(); + { + ThermoActiveLogger.LogError($"NC Not connected! | GetCurrentWarmersResistances | {libraryError.exception}"); + return InternalServerError(); + } CmsError cmsError = ncAdapter.GetWarmersResistances(out Dictionary currWarmers); if (cmsError.IsError()) + { + ThermoActiveLogger.LogError($"GetCurrentWarmersResistances error | {cmsError.exception}"); return BadRequest(cmsError.localizationKey); + } return Ok(currWarmers); } @@ -63,12 +76,18 @@ namespace Thermo.Active.Controllers.WebApi // Try connection CmsError libraryError = ncAdapter.Connect(); if (libraryError.errorCode != 0) - return NotFound(); + { + ThermoActiveLogger.LogError($"NC Not connected! | GetCurrentAreaPerc | {libraryError.exception}"); + return InternalServerError(); + } // recupera aree % X / Y - CmsError cmsError = ncAdapter.GetWarmMaterialArea(out Dictionary currAreaPerc); + CmsError cmsError = ncAdapter.GetWarmMaterialArea(out Dictionary currAreaPerc); if (cmsError.IsError()) + { + ThermoActiveLogger.LogError($"GetCurrentAreaPerc error | {cmsError.exception}"); return BadRequest(cmsError.localizationKey); + } return Ok(currAreaPerc); } @@ -86,10 +105,17 @@ namespace Thermo.Active.Controllers.WebApi // Try connection CmsError libraryError = ncAdapter.Connect(); if (libraryError.errorCode != 0) - return NotFound(); - + { + ThermoActiveLogger.LogError($"NC Not connected! | WriteSetpoints | {libraryError.exception}"); + return InternalServerError(); + } // scrivo sul PLC - ncAdapter.WriteRecipeWarmChSetpHMI(channelsLoad); + CmsError cmsError = ncAdapter.WriteRecipeWarmChSetpHMI(channelsLoad); + if (cmsError.IsError()) + { + ThermoActiveLogger.LogError($"WriteSetpoints error | {cmsError.exception}"); + return BadRequest(cmsError.localizationKey); + } // ritorno solo fatto! return Ok(); @@ -113,17 +139,26 @@ namespace Thermo.Active.Controllers.WebApi // Try connection CmsError libraryError = ncAdapter.Connect(); if (libraryError.errorCode != 0) - return NotFound(); + { + ThermoActiveLogger.LogError($"NC Not connected! | Warmers ConfirmEdit | {libraryError.exception}"); + return InternalServerError(); + } // scrivo sul PLC il comando conferma! CmsError cmsError = ncAdapter.ConfirmRecipeData(true); if (cmsError.IsError()) + { + ThermoActiveLogger.LogError($"Warmers ConfirmEdit error | ConfirmRecipeData | {cmsError.exception}"); return BadRequest(cmsError.localizationKey); + } // recupero i dati LIVE dei parametri HMI dei riscaldi... cmsError = ncAdapter.ReadWarmers(out Dictionary currWarmers); if (cmsError.IsError()) + { + ThermoActiveLogger.LogError($"Warmers ConfirmEdit error | ReadWarmers | {cmsError.exception}"); return BadRequest(cmsError.localizationKey); + } // rileggo la ricetta var currParams = new Dictionary(); @@ -151,17 +186,26 @@ namespace Thermo.Active.Controllers.WebApi // Try connection CmsError libraryError = ncAdapter.Connect(); if (libraryError.errorCode != 0) - return NotFound(); + { + ThermoActiveLogger.LogError($"NC Not connected! | Recipe CancelEdit | {libraryError.exception}"); + return InternalServerError(); + } // scrivo sul PLC il comando annula! CmsError cmsError = ncAdapter.ConfirmRecipeData(false); if (cmsError.IsError()) + { + ThermoActiveLogger.LogError($"Warmers CancelEdit error | ConfirmRecipeData | {cmsError.exception}"); return BadRequest(cmsError.localizationKey); + } // recupero i dati LIVE dei parametri HMI dei riscaldi... cmsError = ncAdapter.ReadWarmers(out Dictionary currWarmers); if (cmsError.IsError()) + { + ThermoActiveLogger.LogError($"Warmers ConfirmEdit error | ReadWarmers | {cmsError.exception}"); return BadRequest(cmsError.localizationKey); + } // rileggo la ricetta var currParams = new Dictionary(); @@ -187,10 +231,18 @@ namespace Thermo.Active.Controllers.WebApi // Try connection CmsError libraryError = ncAdapter.Connect(); if (libraryError.errorCode != 0) - return NotFound(); + { + ThermoActiveLogger.LogError($"NC Not connected! | SetConfig | {libraryError.exception}"); + return InternalServerError(); + } // scrivo sul PLC - ncAdapter.WriteRecipeWarmConfig(); + CmsError cmsError = ncAdapter.WriteRecipeWarmConfig(); + if (cmsError.IsError()) + { + ThermoActiveLogger.LogError($"Warmers SetConfig error | WriteRecipeWarmConfig | {cmsError.exception}"); + return BadRequest(cmsError.localizationKey); + } // ritorno solo fatto! return Ok(); @@ -204,10 +256,17 @@ namespace Thermo.Active.Controllers.WebApi /// private static void saveCurrentRecipeWarmers(Dictionary chSetpoints) { - // ora salvo ANCHE i dati live... - RecipeLiveData.ChannelSetpoints = chSetpoints; - // e salvo su disco - ServerConfigController.SaveRecipeCurrent(); + try + { + // ora salvo ANCHE i dati live... + RecipeLiveData.ChannelSetpoints = chSetpoints; + // e salvo su disco + ServerConfigController.SaveRecipeCurrent(); + } + catch (Exception exc) + { + ThermoActiveLogger.LogError($"Warmers | SaveCurrentRecipeParams exception | {exc}"); + } } } } \ No newline at end of file diff --git a/Thermo.Active/program.cs b/Thermo.Active/program.cs index 58b8827f..b8a3d6ff 100644 --- a/Thermo.Active/program.cs +++ b/Thermo.Active/program.cs @@ -16,7 +16,7 @@ using System.Windows.Forms; using TeamDev.SDK.MVVM; using static Thermo.Active.Config.ServerConfig; using static Thermo.Active.Model.Constants; -using static Thermo.Active.Utils.StepLogger; +using static Thermo.Active.Utils.ThermoActiveLogger; using static Thermo.Active.Utils.ExceptionManager; namespace Thermo.Active