updated ModBLock controllers for new datamodel

This commit is contained in:
Samuele Locatelli
2020-06-25 09:58:10 +02:00
parent 4ea2cebfeb
commit e7e2601a8d
10 changed files with 106 additions and 140 deletions
@@ -2,10 +2,7 @@
<modules>
<block>
<id>1</id>
<localizedLabels>
<lang langKey="en">DiscesaCZ ENG</lang>
<lang langKey="it">DiscesaCZ ITA</lang>
</localizedLabels>
<label>MB_DiscesaCZ</label>
<type>MOVEMENT</type>
<section>HEATING</section>
<idParam>-1</idParam>
@@ -15,10 +12,7 @@
</block>
<block>
<id>2</id>
<localizedLabels>
<lang langKey="en">MembDiscesaZ ENG</lang>
<lang langKey="it">MembDiscesaZ ITA</lang>
</localizedLabels>
<label>MB_MembDiscesaZ</label>
<type>MOVEMENT</type>
<section>HEATING</section>
<idParam>-1</idParam>
@@ -28,10 +22,7 @@
</block>
<block>
<id>3</id>
<localizedLabels>
<lang langKey="en">MembZ ENG</lang>
<lang langKey="it">MembZ ITA</lang>
</localizedLabels>
<label>MB_MembZ</label>
<type>MOVEMENT</type>
<section>HEATING</section>
<idParam>-1</idParam>
@@ -41,10 +32,7 @@
</block>
<block>
<id>4</id>
<localizedLabels>
<lang langKey="en">Mod_MembSalitaZ ENG</lang>
<lang langKey="it">Mod_MembSalitaZ ITA</lang>
</localizedLabels>
<label>MB_Mod_MembSalitaZ</label>
<type>MOVEMENT</type>
<section>HEATING</section>
<idParam>-1</idParam>
@@ -54,10 +42,7 @@
</block>
<block>
<id>6</id>
<localizedLabels>
<lang langKey="en">Mod_RiscaldoInf ENG</lang>
<lang langKey="it">Mod_RiscaldoInf ITA</lang>
</localizedLabels>
<label>MB_Mod_RiscaldoInf</label>
<type>HEATING</type>
<section>HEATING</section>
<idParam>-1</idParam>
@@ -67,10 +52,7 @@
</block>
<block>
<id>7</id>
<localizedLabels>
<lang langKey="en">Mod_RiscaldoSup ENG</lang>
<lang langKey="it">Mod_RiscaldoSup ITA</lang>
</localizedLabels>
<label>MB_Mod_RiscaldoSup</label>
<type>HEATING</type>
<section>HEATING</section>
<idParam>0</idParam>
@@ -80,10 +62,7 @@
</block>
<block>
<id>8</id>
<localizedLabels>
<lang langKey="en">Mod_PirometroRisc ENG</lang>
<lang langKey="it">Mod_PirometroRisc ITA</lang>
</localizedLabels>
<label>MB_Mod_PirometroRisc</label>
<type>HEATING</type>
<section>HEATING</section>
<idParam>80</idParam>
@@ -93,10 +72,7 @@
</block>
<block>
<id>13</id>
<localizedLabels>
<lang langKey="en">Mod_Imbutitura ENG</lang>
<lang langKey="it">Mod_Imbutitura ITA</lang>
</localizedLabels>
<label>MB_Mod_Imbutitura</label>
<type>DRAWING</type>
<section>FORMING</section>
<idParam>99</idParam>
@@ -106,10 +82,7 @@
</block>
<block>
<id>16</id>
<localizedLabels>
<lang langKey="en">Mod_Raffreddamento ENG</lang>
<lang langKey="it">Mod_Raffreddamento ITA</lang>
</localizedLabels>
<label>MB_Mod_Raffreddamento</label>
<type>COOLING</type>
<section>FORMING</section>
<idParam>-1</idParam>
@@ -119,10 +92,7 @@
</block>
<block>
<id>17</id>
<localizedLabels>
<lang langKey="en">Mod_PirometroRaffr ENG</lang>
<lang langKey="it">Mod_PirometroRaffr ITA</lang>
</localizedLabels>
<label>MB_Mod_PirometroRaffr</label>
<type>COOLING</type>
<section>FORMING</section>
<idParam>139</idParam>
@@ -132,10 +102,7 @@
</block>
<block>
<id>19</id>
<localizedLabels>
<lang langKey="en">Mod_Vuoto ENG</lang>
<lang langKey="it">Mod_Vuoto ITA</lang>
</localizedLabels>
<label>MB_Mod_Vuoto</label>
<type>VACUUM</type>
<section>FORMING</section>
<idParam>-1</idParam>
@@ -145,10 +112,7 @@
</block>
<block>
<id>21</id>
<localizedLabels>
<lang langKey="en">Mod_VuotoDiretto ENG</lang>
<lang langKey="it">Mod_VuotoDiretto ITA</lang>
</localizedLabels>
<label>MB_Mod_VuotoDiretto</label>
<type>VACUUM</type>
<section>FORMING</section>
<idParam>-1</idParam>
@@ -158,10 +122,7 @@
</block>
<block>
<id>36</id>
<localizedLabels>
<lang langKey="en">Mod_EstrazioneZ ENG</lang>
<lang langKey="it">Mod_EstrazioneZ ITA</lang>
</localizedLabels>
<label>MB_Mod_EstrazioneZ</label>
<type>EXTRACTION</type>
<section>EXTRACTION</section>
<idParam>-1</idParam>
@@ -171,10 +132,7 @@
</block>
<block>
<id>42</id>
<localizedLabels>
<lang langKey="en">Mod_SalitaCZ ENG</lang>
<lang langKey="it">Mod_SalitaCZ ITA</lang>
</localizedLabels>
<label>MB_Mod_SalitaCZ</label>
<type>MOVEMENT</type>
<section>EXTRACTION</section>
<idParam>-1</idParam>
@@ -8,14 +8,7 @@
<xs:complexType>
<xs:all>
<xs:element name="id" type="xs:int"/>
<xs:element name="localizedLabels">
<xs:complexType>
<xs:sequence>
<xs:element name="lang" type="langType" minOccurs="0" maxOccurs="unbounded">
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="label" type="xs:string" />
<xs:element name="type" type="mblockType" />
<xs:element name="section" type="mblockSection" />
<xs:element name="idParam" type="xs:int" />
@@ -611,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),
@@ -6,7 +6,7 @@ namespace Thermo.Active.Model.ConfigModels
public class ModBlockConfigModel
{
public int Id;
public Dictionary<string, string> 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; }
@@ -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;
@@ -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
}
}
@@ -22,6 +22,8 @@ namespace Thermo.Active.Model.DTOModels.ThRecipe
/// <summary>
/// Recipe Overview
/// </summary>
public Dictionary<string, RecipeCatStatus> RecipeOverview;
public Dictionary<RecipeSection, RecipeCatStatus> RecipeOverview;
}
}
+24 -46
View File
@@ -1888,13 +1888,13 @@ namespace Thermo.Active.NC
/// </summary>
/// <param name="currOverview">Oggetto overview ricetta corrente HMI</param>
/// <returns></returns>
public CmsError GetRecipeOverview(out Dictionary<string, RecipeCatStatus> currOverview)
public CmsError GetRecipeOverview(out Dictionary<RecipeSection, RecipeCatStatus> currOverview)
{
CmsError libraryError = NO_ERROR;
// overview di base: ultima salvata...
currOverview = new Dictionary<string, RecipeCatStatus>();
currOverview = new Dictionary<RecipeSection, RecipeCatStatus>();
// leggo la ricetta!
// leggo la ricetta dal PLC!
var currRecipe = new Dictionary<string, DTORecipeParam>();
libraryError = ReadFullRecipe(out currRecipe);
if (libraryError.IsError())
@@ -1917,17 +1917,21 @@ namespace Thermo.Active.NC
RecipeCatStatus currStatus = RecipeCatStatus.Unchanged;
// da conf ricetta --> verifico dati LIVE ricetta e se mancassero imposto unchanged..
currOverview = NcFileAdapter.RecipeLiveData.RecipeOverview;
if (NcFileAdapter.RecipeLiveData.RecipeOverview != null)
{
currOverview = NcFileAdapter.RecipeLiveData.RecipeOverview;
}
bool changed = false;
foreach (var item in recipeConfig)
{
if (!currOverview.ContainsKey(item.Category))
if (!currOverview.ContainsKey(getRecipeSection(item.Category)))
{
currOverview.Add(item.Category, RecipeCatStatus.Unchanged);
currOverview.Add(getRecipeSection(item.Category), RecipeCatStatus.Unchanged);
changed = true;
}
}
// se cambiato --> salvo!
// se cambiato --> salvo in live data...
if (changed)
{
NcFileAdapter.RecipeLiveData.RecipeOverview = currOverview;
@@ -1936,16 +1940,7 @@ namespace Thermo.Active.NC
// 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];
currStatus = currOverview[getRecipeSection(item.Category)];
// se lo stato è errore --> esco...
if (currStatus == RecipeCatStatus.HasError)
@@ -1958,42 +1953,25 @@ namespace Thermo.Active.NC
// se in errore --> registro...
if (currRecipe[item.Label].Status.HasError)
{
#if false
currStatus = RecipeCatStatus.HasError;
#endif
currOverview[item.Category] = RecipeCatStatus.HasError;
currOverview[getRecipeSection(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)
{
currStatus = RecipeCatStatus.ChangedOk;
}
else
{
currStatus = RecipeCatStatus.Unchanged;
}
#endif
}
#if false
// 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];
}
#endif
}
// restituisco cod errore se trovato
return libraryError;
}
/// <summary>
/// Conversione stringa --> enum
/// </summary>
/// <param name="strVal"></param>
/// <returns></returns>
protected RecipeSection getRecipeSection(string strVal)
{
RecipeSection answ = (RecipeSection)Enum.Parse(typeof(RecipeSection), strVal, true);
return answ;
}
/// <summary>
/// Legge tutti i parametri della ricetta
/// </summary>
@@ -2034,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,
+19 -6
View File
@@ -599,7 +599,7 @@ namespace Thermo.Active.NC
/// </summary>
/// <param name="section"></param>
/// <param name="status"></param>
public static void upsRecipeOverview(string section, RecipeCatStatus status)
public static void upsRecipeOverview(RecipeSection section, RecipeCatStatus status)
{
if (RecipeLiveData.RecipeOverview.ContainsKey(section))
{
@@ -660,6 +660,11 @@ namespace Thermo.Active.NC
{
// deserialize to object
RecipeLiveData = JsonConvert.DeserializeObject<LiveData>(rawData);
// from template --> reset (if present) overview data...
foreach (var item in RecipeLiveData.RecipeOverview)
{
RecipeLiveData.RecipeOverview[item.Key] = RecipeCatStatus.Unchanged;
}
}
catch
{ }
@@ -727,6 +732,11 @@ namespace Thermo.Active.NC
{
// deserialize to object
RecipeLiveData = JsonConvert.DeserializeObject<LiveData>(rawData);
// from template --> reset (if present) overview data...
foreach (var item in RecipeLiveData.RecipeOverview)
{
RecipeLiveData.RecipeOverview[item.Key] = RecipeCatStatus.Unchanged;
}
// update NAME
RecipeLiveData.RecipeName = $"{DateTime.Now:yyyyMMss_HHmmss}.json";
}
@@ -768,13 +778,16 @@ namespace Thermo.Active.NC
public static bool SaveRecipeTemplate()
{
RecipeLiveData.RecipeName = "template.json";
return SaveRecipe(RECIPE_TEMPLATE_PATH);
// duplicate data...
LiveData data2save = RecipeLiveData;
// template --> reset overview data...
data2save.RecipeOverview = new Dictionary<RecipeSection, RecipeCatStatus>();
return SaveRecipe(RECIPE_TEMPLATE_PATH, data2save);
}
/// <summary>
/// Try to save live recipe to selected filePath
/// </summary>
public static bool SaveRecipe(string filePath)
public static bool SaveRecipe(string filePath, LiveData currRecipe)
{
bool answ = false;
try
@@ -787,9 +800,9 @@ namespace Thermo.Active.NC
filePath += ".json";
}
// fix name!
RecipeLiveData.RecipeName = fileName;
currRecipe.RecipeName = fileName;
// serialize
string rawData = JsonConvert.SerializeObject(RecipeLiveData);
string rawData = JsonConvert.SerializeObject(currRecipe);
// save live!
File.WriteAllText(LIVE_RECIPE_PATH, rawData);
// check filePath...
@@ -30,7 +30,7 @@ namespace Thermo.Active.Controllers.WebApi
ThermoActiveLogger.LogError($"ncAdapter Not connected! | GetOverview | {libraryError.exception}");
}
libraryError = ncAdapter.GetRecipeOverview(out Dictionary<string, RecipeCatStatus> currOverview);
libraryError = ncAdapter.GetRecipeOverview(out Dictionary<RecipeSection, RecipeCatStatus> currOverview);
if (libraryError.IsError())
{
ThermoActiveLogger.LogError($"GetRecipeOverview error | {libraryError.exception}");
@@ -61,7 +61,7 @@ namespace Thermo.Active.Controllers.WebApi
}
[Route("update"), HttpPut]
public IHttpActionResult WriteParameters(Dictionary<string, double> parametersList, string section)
public IHttpActionResult WriteParameters(Dictionary<string, double> parametersList)
{
if (parametersList != null)
{
@@ -104,18 +104,6 @@ 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();
}
@@ -135,9 +123,10 @@ namespace Thermo.Active.Controllers.WebApi
/// <summary>
/// Confirm recipe modification (parameters: HMI --> PLC)
/// </summary>
/// <param name="section">section confirmed (string as in overview)</param>
/// <returns></returns>
[Route("confirm"), HttpPut]
public IHttpActionResult ConfirmEdit()
public IHttpActionResult ConfirmEdit(RecipeSection section)
{
if (NcFileAdapter.RecipeLiveData != null)
{
@@ -157,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<string, DTORecipeParam> currRecipe);
if (libraryError.IsError())
@@ -338,7 +340,7 @@ namespace Thermo.Active.Controllers.WebApi
// ora salvo ANCHE i dati live...
NcFileAdapter.RecipeLiveData.RecipeParameters = currParams;
// e salvo su disco
NcFileAdapter.SaveRecipe(newName);
NcFileAdapter.SaveRecipe(newName, NcFileAdapter.RecipeLiveData);
// ritorno solo fatto!
return Ok();
@@ -412,7 +414,10 @@ namespace Thermo.Active.Controllers.WebApi
ThermoActiveLogger.LogError($"Recipe | SaveCurrentRecipeParams exception | {exc}");
}
}
/// <summary>
/// write current recipe to PLC
/// </summary>
/// <returns></returns>
public static CmsError WriteCurrentRecipeToPlc()
{
CmsError checkError = NO_ERROR;