diff --git a/Thermo.Active.Config/Config/moduleBlockConfig.xml b/Thermo.Active.Config/Config/moduleBlockConfig.xml index ef3095f8..c76f9bca 100644 --- a/Thermo.Active.Config/Config/moduleBlockConfig.xml +++ b/Thermo.Active.Config/Config/moduleBlockConfig.xml @@ -2,10 +2,7 @@ 1 - - DiscesaCZ ENG - DiscesaCZ ITA - + MOVEMENT
HEATING
-1 @@ -15,10 +12,7 @@
2 - - MembDiscesaZ ENG - MembDiscesaZ ITA - + MOVEMENT
HEATING
-1 @@ -28,10 +22,7 @@
3 - - MembZ ENG - MembZ ITA - + MOVEMENT
HEATING
-1 @@ -41,10 +32,7 @@
4 - - Mod_MembSalitaZ ENG - Mod_MembSalitaZ ITA - + MOVEMENT
HEATING
-1 @@ -54,10 +42,7 @@
6 - - Mod_RiscaldoInf ENG - Mod_RiscaldoInf ITA - + HEATING
HEATING
-1 @@ -67,10 +52,7 @@
7 - - Mod_RiscaldoSup ENG - Mod_RiscaldoSup ITA - + HEATING
HEATING
0 @@ -80,10 +62,7 @@
8 - - Mod_PirometroRisc ENG - Mod_PirometroRisc ITA - + HEATING
HEATING
80 @@ -93,10 +72,7 @@
13 - - Mod_Imbutitura ENG - Mod_Imbutitura ITA - + DRAWING
FORMING
99 @@ -106,10 +82,7 @@
16 - - Mod_Raffreddamento ENG - Mod_Raffreddamento ITA - + COOLING
FORMING
-1 @@ -119,10 +92,7 @@
17 - - Mod_PirometroRaffr ENG - Mod_PirometroRaffr ITA - + COOLING
FORMING
139 @@ -132,10 +102,7 @@
19 - - Mod_Vuoto ENG - Mod_Vuoto ITA - + VACUUM
FORMING
-1 @@ -145,10 +112,7 @@
21 - - Mod_VuotoDiretto ENG - Mod_VuotoDiretto ITA - + VACUUM
FORMING
-1 @@ -158,10 +122,7 @@
36 - - Mod_EstrazioneZ ENG - Mod_EstrazioneZ ITA - + EXTRACTION
EXTRACTION
-1 @@ -171,10 +132,7 @@
42 - - Mod_SalitaCZ ENG - Mod_SalitaCZ ITA - + MOVEMENT
EXTRACTION
-1 diff --git a/Thermo.Active.Config/Config/moduleBlockConfigValidator.xsd b/Thermo.Active.Config/Config/moduleBlockConfigValidator.xsd index 220ba2fb..71fcea52 100644 --- a/Thermo.Active.Config/Config/moduleBlockConfigValidator.xsd +++ b/Thermo.Active.Config/Config/moduleBlockConfigValidator.xsd @@ -8,14 +8,7 @@ - - - - - - - - + diff --git a/Thermo.Active.Config/ServerConfig.cs b/Thermo.Active.Config/ServerConfig.cs index ca673d75..089ef523 100644 --- a/Thermo.Active.Config/ServerConfig.cs +++ b/Thermo.Active.Config/ServerConfig.cs @@ -62,7 +62,6 @@ namespace Thermo.Active.Config public static List RiskChannelConfig; public static List RiskBoardConfig; - public static LiveData RecipeLiveData = new LiveData(); } } \ No newline at end of file diff --git a/Thermo.Active.Config/ServerConfigController.cs b/Thermo.Active.Config/ServerConfigController.cs index 7b5efcb9..3d7afa51 100644 --- a/Thermo.Active.Config/ServerConfigController.cs +++ b/Thermo.Active.Config/ServerConfigController.cs @@ -57,28 +57,6 @@ namespace Thermo.Active.Config ExceptionManager.ManageError(ERROR_LEVEL.FATAL, message, true); } } - public static void ReadLastRecipe() - { - try - { - ReadLiveData(); - } - catch (XmlException ex) - { - ExceptionManager.ManageError(ERROR_LEVEL.FATAL, - "Error while reading file: " + ex.SourceUri + - "\n Error: " + ex.Message, - true - ); - } - catch (Exception ex) - { - var message = ex.Message; - if (ex.InnerException != null) - message += "\n" + ex.InnerException.Message; - ExceptionManager.ManageError(ERROR_LEVEL.FATAL, message, true); - } - } private static XDocument GetXmlHandlerWithValidator(string configSchemaFilePath, string configFilePath, bool isFullPath = false) { @@ -633,9 +611,10 @@ namespace Thermo.Active.Config .Select(x => new ModBlockConfigModel() { Id = Convert.ToInt16(x.Element("id").Value), - LocalizedLabels = x.Element("localizedLabels").Elements().ToDictionary( - y => y.Attribute("langKey").Value, y => y.Value - ), + Label = x.Element("label").Value, + //LocalizedLabels = x.Element("localizedLabels").Elements().ToDictionary( + // y => y.Attribute("langKey").Value, y => y.Value + // ), Type = GetTActMB_Type(x.Element("type").Value), Section = GetTActMB_Section(x.Element("section").Value), IdParam = Convert.ToInt16(x.Element("idParam").Value), @@ -846,180 +825,6 @@ namespace Thermo.Active.Config .Select(x => x.Value) .ToList(); } - /// - /// Try to load live data from json persistence file - /// - public static bool ReadLiveData() - { - bool answ = false; - if (File.Exists(LIVE_RECIPE_PATH)) - { - // load all text data - var rawData = File.ReadAllText(LIVE_RECIPE_PATH); - try - { - // deserialize to object - RecipeLiveData = JsonConvert.DeserializeObject(rawData); - } - catch - { } - answ = true; - } - else - { - // reload from template... - var rawData = File.ReadAllText(RECIPE_TEMPLATE_PATH); - try - { - // deserialize to object - RecipeLiveData = JsonConvert.DeserializeObject(rawData); - } - catch - { } - // salva current - SaveRecipeCurrent(); - answ = true; - } - // rendo se fatto - return answ; - } - /// - /// Try to load selected recipe to live data (memory and json persistence file) - /// - public static bool LoadRecipe(string filePath) - { - bool answ = false; - - // check file extension - string fileName = Path.GetFileName(filePath); - if (!fileName.EndsWith(".json")) - { - fileName += ".json"; - filePath += ".json"; - } - - // check filePath... - if (!filePath.Contains(RECIPE_DIRECTORY) && filePath != RECIPE_TEMPLATE_PATH) - { - // aggiungo base path! - filePath = RECIPE_DIRECTORY + filePath; - } - if (File.Exists(filePath)) - { - answ = true; - - // load all text data - var rawData = File.ReadAllText(filePath); - try - { - // deserialize to object - RecipeLiveData = JsonConvert.DeserializeObject(rawData); - } - catch - { } - // update current live data! - SaveRecipeCurrent(); - } - // rendo se fatto - return answ; - } - /// - /// Try to load template recipe - /// - public static bool LoadTemplate() - { - bool answ = false; - // check filePath... - if (File.Exists(RECIPE_TEMPLATE_PATH)) - { - answ = true; - - // load all text data - var rawData = File.ReadAllText(RECIPE_TEMPLATE_PATH); - try - { - // deserialize to object - RecipeLiveData = JsonConvert.DeserializeObject(rawData); - // update NAME - RecipeLiveData.RecipeName = $"{DateTime.Now:yyyyMMss_HHmmss}.json"; - } - catch - { } - // update current live data! - SaveRecipeCurrent(); - } - // rendo se fatto - return answ; - } - /// - /// Try to write live data to json persistence file - /// - public static bool SaveRecipeCurrent() - { - bool answ = false; - try - { - answ = true; - // serialize - string rawData = JsonConvert.SerializeObject(RecipeLiveData); - // save live! - var dir = Path.GetDirectoryName(LIVE_RECIPE_PATH); - if (!Directory.Exists(dir)) - { - Directory.CreateDirectory(dir); - } - File.WriteAllText(LIVE_RECIPE_PATH, rawData); - } - catch - { } - // rendo se fatto - return answ; - } - /// - /// Try to save live recipe as NEW template - /// - public static bool SaveRecipeTemplate() - { - - RecipeLiveData.RecipeName = "template.json"; - return SaveRecipe(RECIPE_TEMPLATE_PATH); - } - /// - /// Try to save live recipe to selected filePath - /// - public static bool SaveRecipe(string filePath) - { - bool answ = false; - try - { - answ = true; - string fileName = Path.GetFileName(filePath); - if (!fileName.EndsWith(".json")) - { - fileName += ".json"; - filePath += ".json"; - } - // fix name! - RecipeLiveData.RecipeName = fileName; - // serialize - string rawData = JsonConvert.SerializeObject(RecipeLiveData); - // save live! - File.WriteAllText(LIVE_RECIPE_PATH, rawData); - // check filePath... - if (!filePath.Contains(RECIPE_DIRECTORY) && filePath != RECIPE_TEMPLATE_PATH) - { - // aggiungo base path! - filePath = RECIPE_DIRECTORY + filePath; - } - // save! - File.WriteAllText(filePath, rawData); - } - catch - { } - // rendo se fatto - return answ; - } - public static string CalculateHash(string filename) { using (var sha = SHA1.Create()) diff --git a/Thermo.Active.Config/Thermo.Active.Config.csproj b/Thermo.Active.Config/Thermo.Active.Config.csproj index bfee6bae..84b24ca5 100644 --- a/Thermo.Active.Config/Thermo.Active.Config.csproj +++ b/Thermo.Active.Config/Thermo.Active.Config.csproj @@ -55,7 +55,6 @@ Designer PreserveNewest - diff --git a/Thermo.Active.Model/ConfigModels/ModBlockConfigModel.cs b/Thermo.Active.Model/ConfigModels/ModBlockConfigModel.cs index da75b24b..7f47779f 100644 --- a/Thermo.Active.Model/ConfigModels/ModBlockConfigModel.cs +++ b/Thermo.Active.Model/ConfigModels/ModBlockConfigModel.cs @@ -6,7 +6,7 @@ namespace Thermo.Active.Model.ConfigModels public class ModBlockConfigModel { public int Id; - public Dictionary LocalizedLabels { get; set; } + public string Label { get; set; } public TACT_MBLOCK_TYPE Type { get; set; } public TACT_MBLOCK_SECTION Section { get; set; } public int IdParam { get; set; } diff --git a/Thermo.Active.Model/DTOModels/ThModules/DTOModuleConfigModel.cs b/Thermo.Active.Model/DTOModels/ThModules/DTOModuleConfigModel.cs index abc0278c..7664def6 100644 --- a/Thermo.Active.Model/DTOModels/ThModules/DTOModuleConfigModel.cs +++ b/Thermo.Active.Model/DTOModels/ThModules/DTOModuleConfigModel.cs @@ -6,7 +6,7 @@ public string Label; public BlockType Type; public BlockSection Section; - public int IdMainParam = -1; // -1 = non visibile + public int IdMainParam = -1; // -1 = non visibile la parte a DX public bool DelayVisible; public int VisualPriority; } diff --git a/Thermo.Active.Model/DTOModels/ThModules/DTOModulesBlock.cs b/Thermo.Active.Model/DTOModels/ThModules/DTOModulesBlock.cs index c03051a4..e63cd958 100644 --- a/Thermo.Active.Model/DTOModels/ThModules/DTOModulesBlock.cs +++ b/Thermo.Active.Model/DTOModels/ThModules/DTOModulesBlock.cs @@ -7,7 +7,7 @@ namespace Thermo.Active.Model.DTOModels.ThModules public class DTOModulesBlock { public int Id { get; set; } = 0; - public string LocalizedLabel { get; set; } = ""; + public string Label { 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; @@ -30,7 +30,7 @@ namespace Thermo.Active.Model.DTOModels.ThModules if (Id != item.Id) return false; - if (LocalizedLabel != item.LocalizedLabel) + if (Label != item.Label) return false; if (Type != item.Type) return false; diff --git a/Thermo.Active.Model/DTOModels/ThRecipe/DTORecipeOverview.cs b/Thermo.Active.Model/DTOModels/ThRecipe/DTORecipeOverview.cs index 1e21678e..43872445 100644 --- a/Thermo.Active.Model/DTOModels/ThRecipe/DTORecipeOverview.cs +++ b/Thermo.Active.Model/DTOModels/ThRecipe/DTORecipeOverview.cs @@ -11,4 +11,20 @@ namespace Thermo.Active.Model.DTOModels.ThRecipe ChangedOk, HasError } + + [JsonConverter(typeof(StringEnumConverter))] + public enum RecipeSection + { + General = 1, + Positions, + Cycle, + Heats, + Pyrometer, + Drawing, + UpperPlate, + Cooling, + Vacuum, + Extraction, + Options + } } diff --git a/Thermo.Active.Config/LiveData.cs b/Thermo.Active.Model/DTOModels/ThRecipe/LiveData.cs similarity index 75% rename from Thermo.Active.Config/LiveData.cs rename to Thermo.Active.Model/DTOModels/ThRecipe/LiveData.cs index ea8d785f..3cef6db1 100644 --- a/Thermo.Active.Config/LiveData.cs +++ b/Thermo.Active.Model/DTOModels/ThRecipe/LiveData.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace Thermo.Active.Config +namespace Thermo.Active.Model.DTOModels.ThRecipe { /// /// Live data for Thermo Active @@ -19,6 +19,11 @@ namespace Thermo.Active.Config /// Dictionary of all channels and relative setpoints /// public Dictionary ChannelSetpoints; - + /// + /// Recipe Overview + /// + public Dictionary RecipeOverview; } + + } diff --git a/Thermo.Active.Model/Thermo.Active.Model.csproj b/Thermo.Active.Model/Thermo.Active.Model.csproj index 1d04ca14..169d38a2 100644 --- a/Thermo.Active.Model/Thermo.Active.Model.csproj +++ b/Thermo.Active.Model/Thermo.Active.Model.csproj @@ -108,6 +108,7 @@ + diff --git a/Thermo.Active.NC/NcAdapter.cs b/Thermo.Active.NC/NcAdapter.cs index e50428c4..2b812a25 100644 --- a/Thermo.Active.NC/NcAdapter.cs +++ b/Thermo.Active.NC/NcAdapter.cs @@ -23,10 +23,12 @@ namespace Thermo.Active.NC { public class NcAdapter : IDisposable { - + /// + /// NC object + /// public NcThermo numericalControl; /// - /// Lock per connessione PLC + /// Lock semaphore for PLC connection step /// private readonly static object connectLock = new object(); @@ -279,12 +281,12 @@ namespace Thermo.Active.NC public CmsError ManageConfRequest() { CmsError libraryError = NO_ERROR; - if (RecipeLiveData != null) + if (NcFileAdapter.RecipeLiveData != null) { // controllo SE HO richieste di configurazione if (ThermoReqConfWarmerStr) { - if (RecipeLiveData.ChannelSetpoints != null) + if (NcFileAdapter.RecipeLiveData.ChannelSetpoints != null) { // se si in questo caso scrivo configurazione... WriteRecipeWarmConfig(); @@ -294,7 +296,7 @@ namespace Thermo.Active.NC } if (ThermoReqConfRecipeStr) { - if (RecipeLiveData.RecipeParameters != null) + if (NcFileAdapter.RecipeLiveData.RecipeParameters != null) { // copy data to PLC libraryError = ReadFullRecipe(out Dictionary prevRecipe); @@ -302,7 +304,7 @@ namespace Thermo.Active.NC return libraryError; // save parameters to PLC!!! Dictionary updtRecipe = new Dictionary(); - foreach (var item in RecipeLiveData.RecipeParameters) + foreach (var item in NcFileAdapter.RecipeLiveData.RecipeParameters) { if (prevRecipe.ContainsKey(item.Key)) { @@ -1886,12 +1888,13 @@ namespace Thermo.Active.NC /// /// Oggetto overview ricetta corrente HMI /// - public CmsError GetRecipeOverview(out Dictionary currOverview) + public CmsError GetRecipeOverview(out Dictionary currOverview) { CmsError libraryError = NO_ERROR; - currOverview = new Dictionary(); + // overview di base: ultima salvata... + currOverview = new Dictionary(); - // leggo la ricetta! + // leggo la ricetta dal PLC! var currRecipe = new Dictionary(); libraryError = ReadFullRecipe(out currRecipe); if (libraryError.IsError()) @@ -1913,15 +1916,31 @@ namespace Thermo.Active.NC RecipeCatStatus currStatus = RecipeCatStatus.Unchanged; - // percorro conf ricetta... + // da conf ricetta --> se ci sono li leggo da li... + if (NcFileAdapter.RecipeLiveData.RecipeOverview != null) + { + currOverview = NcFileAdapter.RecipeLiveData.RecipeOverview; + } + + bool changed = false; foreach (var item in recipeConfig) { - currStatus = RecipeCatStatus.Unchanged; - // cerco SE ci sia già uno status... - if (currOverview.ContainsKey(item.Category)) + if (!currOverview.ContainsKey(getRecipeSection(item.Category))) { - currStatus = currOverview[item.Category]; + currOverview.Add(getRecipeSection(item.Category), RecipeCatStatus.Unchanged); + changed = true; } + } + // se cambiato --> salvo in live data... + if (changed) + { + NcFileAdapter.RecipeLiveData.RecipeOverview = currOverview; + } + + // ORA percorro conf ricetta x cercare eventuali ERRORI...... + foreach (var item in recipeConfig) + { + currStatus = currOverview[getRecipeSection(item.Category)]; // se lo stato è errore --> esco... if (currStatus == RecipeCatStatus.HasError) @@ -1934,35 +1953,25 @@ namespace Thermo.Active.NC // se in errore --> registro... if (currRecipe[item.Label].Status.HasError) { - currStatus = RecipeCatStatus.HasError; + currOverview[getRecipeSection(item.Category)] = RecipeCatStatus.HasError; } - // FARE verificare il significato di questo changed (se è da file o da HMI/PLC) - else if (currRecipe[item.Label].SetpointHMI != currRecipe[item.Label].SetpointPLC) - { - currStatus = RecipeCatStatus.ChangedOk; - } - else - { - currStatus = RecipeCatStatus.Unchanged; - } - } - - // ora verifico overview finale: se non c'è aggiungo - if (!currOverview.ContainsKey(item.Category)) - { - currOverview.Add(item.Category, currStatus); - } - else - { - // se il valore è maggiore --> aggiorno - currOverview[item.Category] = (int)currStatus > (int)currOverview[item.Category] ? currStatus : currOverview[item.Category]; } } // restituisco cod errore se trovato return libraryError; } + /// + /// Conversione stringa --> enum + /// + /// + /// + protected RecipeSection getRecipeSection(string strVal) + { + RecipeSection answ = (RecipeSection)Enum.Parse(typeof(RecipeSection), strVal, true); + return answ; + } /// /// Legge tutti i parametri della ricetta /// @@ -2003,7 +2012,7 @@ namespace Thermo.Active.NC currVal = new DTOModulesBlock() { Id = item.Id, - LocalizedLabel = item.LocalizedLabels["it"], // FIXME TODO check come gestire traduzione!!! + Label = item.Label, Type = item.Type, Section = item.Section, IdParam = item.IdParam, diff --git a/Thermo.Active.NC/NcFileAdapter.cs b/Thermo.Active.NC/NcFileAdapter.cs index 513b9de8..d7c59272 100644 --- a/Thermo.Active.NC/NcFileAdapter.cs +++ b/Thermo.Active.NC/NcFileAdapter.cs @@ -11,11 +11,20 @@ using static CMS_CORE_Library.Models.DataStructures; using static Thermo.Active.Config.ServerConfig; using static Thermo.Active.Database.Controllers.QueueController; using static Thermo.Active.Model.Constants; +using Newtonsoft.Json; +using System.Xml; +using Thermo.Active.Model.DTOModels.ThRecipe; namespace Thermo.Active.NC { public class NcFileAdapter : NcAdapter { + + /// + /// Recipe Live data + /// + public static LiveData RecipeLiveData = new LiveData(); + /// /// Read file from local devices ad give back string content /// @@ -582,5 +591,240 @@ namespace Thermo.Active.NC return numericalControl.FILES_WCleanUploadFolder(); } + + #region recipe file persistence + + /// + /// Upsert recipe overview status + /// + /// + /// + public static void upsRecipeOverview(RecipeSection section, RecipeCatStatus status) + { + if (RecipeLiveData.RecipeOverview.ContainsKey(section)) + { + RecipeLiveData.RecipeOverview[section] = status; + } + else + { + RecipeLiveData.RecipeOverview.Add(section, status); + } + } + + public static void ReadLastRecipe() + { + try + { + ReadLiveData(); + } + catch (XmlException ex) + { + ExceptionManager.ManageError(ERROR_LEVEL.FATAL, + "Error while reading file: " + ex.SourceUri + + "\n Error: " + ex.Message, + true + ); + } + catch (Exception ex) + { + var message = ex.Message; + if (ex.InnerException != null) + message += "\n" + ex.InnerException.Message; + ExceptionManager.ManageError(ERROR_LEVEL.FATAL, message, true); + } + } + /// + /// Try to load live data from json persistence file + /// + public static bool ReadLiveData() + { + bool answ = false; + if (File.Exists(LIVE_RECIPE_PATH)) + { + // load all text data + var rawData = File.ReadAllText(LIVE_RECIPE_PATH); + try + { + // deserialize to object + RecipeLiveData = JsonConvert.DeserializeObject(rawData); + } + catch + { } + answ = true; + } + else + { + // reload from template... + var rawData = File.ReadAllText(RECIPE_TEMPLATE_PATH); + try + { + // deserialize to object + RecipeLiveData = JsonConvert.DeserializeObject(rawData); + // from template --> reset (if present) overview data... + foreach (var item in RecipeLiveData.RecipeOverview) + { + RecipeLiveData.RecipeOverview[item.Key] = RecipeCatStatus.Unchanged; + } + } + catch + { } + // salva current + SaveRecipeCurrent(); + answ = true; + } + // rendo se fatto + return answ; + } + /// + /// Try to load selected recipe to live data (memory and json persistence file) + /// + public static bool LoadRecipe(string filePath) + { + bool answ = false; + + // check file extension + string fileName = Path.GetFileName(filePath); + if (!fileName.EndsWith(".json")) + { + fileName += ".json"; + filePath += ".json"; + } + + // check filePath... + if (!filePath.Contains(RECIPE_DIRECTORY) && filePath != RECIPE_TEMPLATE_PATH) + { + // aggiungo base path! + filePath = RECIPE_DIRECTORY + filePath; + } + if (File.Exists(filePath)) + { + answ = true; + + // load all text data + var rawData = File.ReadAllText(filePath); + try + { + // deserialize to object + RecipeLiveData = JsonConvert.DeserializeObject(rawData); + } + catch + { } + // update current live data! + SaveRecipeCurrent(); + } + // rendo se fatto + return answ; + } + /// + /// Try to load template recipe + /// + public static bool LoadTemplate() + { + bool answ = false; + // check filePath... + if (File.Exists(RECIPE_TEMPLATE_PATH)) + { + answ = true; + + // load all text data + var rawData = File.ReadAllText(RECIPE_TEMPLATE_PATH); + try + { + // deserialize to object + RecipeLiveData = JsonConvert.DeserializeObject(rawData); + // from template --> reset (if present) overview data... + if (RecipeLiveData.RecipeOverview != null) + { + foreach (var item in RecipeLiveData.RecipeOverview) + { + RecipeLiveData.RecipeOverview[item.Key] = RecipeCatStatus.Unchanged; + } + } + // update NAME + RecipeLiveData.RecipeName = $"{DateTime.Now:yyyyMMss_HHmmss}.json"; + } + catch + { } + // update current live data! + SaveRecipeCurrent(); + } + // rendo se fatto + return answ; + } + /// + /// Try to write live data to json persistence file + /// + public static bool SaveRecipeCurrent() + { + bool answ = false; + try + { + answ = true; + // serialize + string rawData = JsonConvert.SerializeObject(RecipeLiveData); + // save live! + var dir = Path.GetDirectoryName(LIVE_RECIPE_PATH); + if (!Directory.Exists(dir)) + { + Directory.CreateDirectory(dir); + } + File.WriteAllText(LIVE_RECIPE_PATH, rawData); + } + catch + { } + // rendo se fatto + return answ; + } + /// + /// Try to save live recipe as NEW template + /// + public static bool SaveRecipeTemplate() + { + // duplicate data... + LiveData data2save = RecipeLiveData; + // template --> reset overview data... + data2save.RecipeOverview = new Dictionary(); + return SaveRecipe(RECIPE_TEMPLATE_PATH, data2save); + } + /// + /// Try to save live recipe to selected filePath + /// + public static bool SaveRecipe(string filePath, LiveData currRecipe) + { + bool answ = false; + try + { + answ = true; + string fileName = Path.GetFileName(filePath); + if (!fileName.EndsWith(".json")) + { + fileName += ".json"; + filePath += ".json"; + } + // fix name! + currRecipe.RecipeName = fileName; + // serialize + string rawData = JsonConvert.SerializeObject(currRecipe); + // save live! + File.WriteAllText(LIVE_RECIPE_PATH, rawData); + // check filePath... + if (!filePath.Contains(RECIPE_DIRECTORY) && filePath != RECIPE_TEMPLATE_PATH) + { + // aggiungo base path! + filePath = RECIPE_DIRECTORY + filePath; + } + // save! + File.WriteAllText(filePath, rawData); + } + catch + { } + // rendo se fatto + return answ; + } + + + #endregion + + } } diff --git a/Thermo.Active.NC/Thermo.Active.NC.csproj b/Thermo.Active.NC/Thermo.Active.NC.csproj index 58647d15..cf63ac30 100644 --- a/Thermo.Active.NC/Thermo.Active.NC.csproj +++ b/Thermo.Active.NC/Thermo.Active.NC.csproj @@ -33,6 +33,9 @@ + + ..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll + @@ -64,6 +67,7 @@ Always + diff --git a/Thermo.Active.NC/packages.config b/Thermo.Active.NC/packages.config new file mode 100644 index 00000000..7c080311 --- /dev/null +++ b/Thermo.Active.NC/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Thermo.Active/Controllers/WebApi/RecipeController.cs b/Thermo.Active/Controllers/WebApi/RecipeController.cs index 7d9a7126..2e65778f 100644 --- a/Thermo.Active/Controllers/WebApi/RecipeController.cs +++ b/Thermo.Active/Controllers/WebApi/RecipeController.cs @@ -30,7 +30,7 @@ namespace Thermo.Active.Controllers.WebApi ThermoActiveLogger.LogError($"ncAdapter Not connected! | GetOverview | {libraryError.exception}"); } - libraryError = ncAdapter.GetRecipeOverview(out Dictionary currOverview); + libraryError = ncAdapter.GetRecipeOverview(out Dictionary currOverview); if (libraryError.IsError()) { ThermoActiveLogger.LogError($"GetRecipeOverview error | {libraryError.exception}"); @@ -65,7 +65,7 @@ namespace Thermo.Active.Controllers.WebApi { if (parametersList != null) { - if (RecipeLiveData != null) + if (NcFileAdapter.RecipeLiveData != null) { // Try connection CmsError libraryError = ncAdapter.Connect(); @@ -123,11 +123,12 @@ namespace Thermo.Active.Controllers.WebApi /// /// Confirm recipe modification (parameters: HMI --> PLC) /// + /// section confirmed (string as in overview) /// [Route("confirm"), HttpPut] - public IHttpActionResult ConfirmEdit() + public IHttpActionResult ConfirmEdit(RecipeSection section) { - if (RecipeLiveData != null) + if (NcFileAdapter.RecipeLiveData != null) { // Try connection CmsError libraryError = ncAdapter.Connect(); @@ -145,6 +146,19 @@ namespace Thermo.Active.Controllers.WebApi return BadRequest(libraryError.localizationKey); } + // SE HO una section != null/empty --> salvo come modificata... + if (section != null) + { + try + { + NcFileAdapter.upsRecipeOverview(section, RecipeCatStatus.ChangedOk); + } + catch (Exception exc) + { + ThermoActiveLogger.LogError($"Error on set recipe overview | section: {section}{Environment.NewLine}{exc}"); + } + } + // recupero i dati LIVE dei parametri HMI della ricetta... libraryError = ncAdapter.ReadFullRecipe(out Dictionary currRecipe); if (libraryError.IsError()) @@ -179,7 +193,7 @@ namespace Thermo.Active.Controllers.WebApi [Route("cancel"), HttpPut] public IHttpActionResult CancelEdit() { - if (RecipeLiveData != null) + if (NcFileAdapter.RecipeLiveData != null) { // Try connection CmsError libraryError = ncAdapter.Connect(); @@ -234,7 +248,7 @@ namespace Thermo.Active.Controllers.WebApi { // chiamo metodo di lettura... - bool fatto = ServerConfigController.LoadRecipe(newName); + bool fatto = NcFileAdapter.LoadRecipe(newName); if (!fatto) { ThermoActiveLogger.LogError($"LoadRecipe error"); @@ -260,7 +274,7 @@ namespace Thermo.Active.Controllers.WebApi public IHttpActionResult NewRecipe() { // chiamo metodo di lettura... - bool fatto = ServerConfigController.LoadTemplate(); + bool fatto = NcFileAdapter.LoadTemplate(); if (!fatto) { @@ -324,9 +338,9 @@ namespace Thermo.Active.Controllers.WebApi } // ora salvo ANCHE i dati live... - RecipeLiveData.RecipeParameters = currParams; + NcFileAdapter.RecipeLiveData.RecipeParameters = currParams; // e salvo su disco - ServerConfigController.SaveRecipe(newName); + NcFileAdapter.SaveRecipe(newName, NcFileAdapter.RecipeLiveData); // ritorno solo fatto! return Ok(); @@ -363,7 +377,7 @@ namespace Thermo.Active.Controllers.WebApi } // ora salvo nei dati live... - RecipeLiveData.RecipeParameters = currParams; + NcFileAdapter.RecipeLiveData.RecipeParameters = currParams; // carico i dati dei riscaldi... var currChSet = new Dictionary(); @@ -371,11 +385,11 @@ namespace Thermo.Active.Controllers.WebApi { currChSet.Add(item.Key, item.Value.SetpointHMI); } - RecipeLiveData.ChannelSetpoints = currChSet; + NcFileAdapter.RecipeLiveData.ChannelSetpoints = currChSet; // e salvo su disco - ServerConfigController.SaveRecipeTemplate(); + NcFileAdapter.SaveRecipeTemplate(); // ritorno solo fatto! return Ok(); @@ -391,16 +405,19 @@ namespace Thermo.Active.Controllers.WebApi try { // ora salvo ANCHE i dati live... - RecipeLiveData.RecipeParameters = currParams; + NcFileAdapter.RecipeLiveData.RecipeParameters = currParams; // e salvo su disco - ServerConfigController.SaveRecipeCurrent(); + NcFileAdapter.SaveRecipeCurrent(); } catch (Exception exc) { ThermoActiveLogger.LogError($"Recipe | SaveCurrentRecipeParams exception | {exc}"); } } - + /// + /// write current recipe to PLC + /// + /// public static CmsError WriteCurrentRecipeToPlc() { CmsError checkError = NO_ERROR; @@ -424,7 +441,7 @@ namespace Thermo.Active.Controllers.WebApi // save parameters to PLC!!! Dictionary updtRecipe = new Dictionary(); - foreach (var item in RecipeLiveData.RecipeParameters) + foreach (var item in NcFileAdapter.RecipeLiveData.RecipeParameters) { if (prevRecipe.ContainsKey(item.Key)) { @@ -452,7 +469,7 @@ namespace Thermo.Active.Controllers.WebApi // process ch load setup... Dictionary newRisk = new Dictionary(); - foreach (var item in RecipeLiveData.ChannelSetpoints) + foreach (var item in NcFileAdapter.RecipeLiveData.ChannelSetpoints) { newRisk.Add(item.Key, item.Value); } diff --git a/Thermo.Active/Controllers/WebApi/WarmersController.cs b/Thermo.Active/Controllers/WebApi/WarmersController.cs index 309faebf..f864cf38 100644 --- a/Thermo.Active/Controllers/WebApi/WarmersController.cs +++ b/Thermo.Active/Controllers/WebApi/WarmersController.cs @@ -233,9 +233,9 @@ namespace Thermo.Active.Controllers.WebApi try { // ora salvo ANCHE i dati live... - RecipeLiveData.ChannelSetpoints = chSetpoints; + NcFileAdapter.RecipeLiveData.ChannelSetpoints = chSetpoints; // e salvo su disco - ServerConfigController.SaveRecipeCurrent(); + NcFileAdapter.SaveRecipeCurrent(); } catch (Exception exc) { diff --git a/Thermo.Active/Properties/AssemblyInfo.cs b/Thermo.Active/Properties/AssemblyInfo.cs index 7002e76e..5e80ead3 100644 --- a/Thermo.Active/Properties/AssemblyInfo.cs +++ b/Thermo.Active/Properties/AssemblyInfo.cs @@ -30,4 +30,4 @@ using System.Runtime.InteropServices; // // You can specify all the values or you can default the Revision and Build Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("0.9.9")] +[assembly: AssemblyVersion("0.9.10")] diff --git a/Thermo.Active/program.cs b/Thermo.Active/program.cs index ceb0a981..ecb0b188 100644 --- a/Thermo.Active/program.cs +++ b/Thermo.Active/program.cs @@ -85,7 +85,7 @@ namespace Thermo.Active opt.Urls.Add("http://" + ServerStartupConfig.ServerAddress.ToString() + ":" + ServerStartupConfig.ServerPort.ToString()); // read and save last CURRENT RECIPE data... - ServerConfigController.ReadLastRecipe(); + NcFileAdapter.ReadLastRecipe(); RecipeController.WriteCurrentRecipeToPlc(); //starts threads