update load/save call from WebApi
This commit is contained in:
@@ -841,6 +841,13 @@ namespace Thermo.Active.Config
|
||||
{
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
// check filePath...
|
||||
if (!filePath.Contains(RECIPE_DIRECTORY))
|
||||
{
|
||||
// aggiungo base path!
|
||||
filePath = RECIPE_DIRECTORY + filePath;
|
||||
}
|
||||
|
||||
// load all text data
|
||||
var rawData = File.ReadAllText(filePath);
|
||||
try
|
||||
@@ -865,6 +872,12 @@ namespace Thermo.Active.Config
|
||||
string rawData = JsonConvert.SerializeObject(RecipeLiveData);
|
||||
// save live!
|
||||
File.WriteAllText(LIVE_RECIPE_PATH, rawData);
|
||||
// check filePath...
|
||||
if (!filePath.Contains(RECIPE_DIRECTORY))
|
||||
{
|
||||
// aggiungo base path!
|
||||
filePath = RECIPE_DIRECTORY + filePath;
|
||||
}
|
||||
// save!
|
||||
File.WriteAllText(filePath, rawData);
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ namespace Thermo.Active.Controllers.WebApi
|
||||
/// Confirm recipe modification (parameters: HMI --> PLC)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Route("Confirm"), HttpPut]
|
||||
[Route("confirm"), HttpPut]
|
||||
public IHttpActionResult ConfirmEdit()
|
||||
{
|
||||
using (NcAdapter ncAdapter = new NcAdapter())
|
||||
@@ -110,11 +110,17 @@ namespace Thermo.Active.Controllers.WebApi
|
||||
if (libraryError.errorCode != 0)
|
||||
return NotFound();
|
||||
|
||||
// recupero i dati LIVE dei parametri HMI della ricetta...
|
||||
CmsError cmsError = ncAdapter.ReadFullRecipe(out Dictionary<string, DTORecipeParam> currRecipe);
|
||||
// scrivo sul PLC il comando conferma!
|
||||
CmsError cmsError = ncAdapter.ConfirmRecipeData(true);
|
||||
if (cmsError.IsError())
|
||||
return BadRequest(cmsError.localizationKey);
|
||||
|
||||
// recupero i dati LIVE dei parametri HMI della ricetta...
|
||||
cmsError = ncAdapter.ReadFullRecipe(out Dictionary<string, DTORecipeParam> currRecipe);
|
||||
if (cmsError.IsError())
|
||||
return BadRequest(cmsError.localizationKey);
|
||||
|
||||
// rileggo la ricetta
|
||||
var currParams = new Dictionary<string, double>();
|
||||
foreach (var item in currRecipe)
|
||||
{
|
||||
@@ -126,11 +132,6 @@ namespace Thermo.Active.Controllers.WebApi
|
||||
// e salvo su disco
|
||||
ServerConfigController.WriteLiveData();
|
||||
|
||||
// scrivo sul PLC il comando conferma!
|
||||
cmsError = ncAdapter.ConfirmRecipeData(true);
|
||||
if (cmsError.IsError())
|
||||
return BadRequest(cmsError.localizationKey);
|
||||
|
||||
// ritorno solo fatto!
|
||||
return Ok();
|
||||
}
|
||||
@@ -140,7 +141,7 @@ namespace Thermo.Active.Controllers.WebApi
|
||||
/// Cancel recipe modification (parameters: PLC --> HMI)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Route("Cancel"), HttpPut]
|
||||
[Route("cancel"), HttpPut]
|
||||
public IHttpActionResult CancelEdit()
|
||||
{
|
||||
using (NcAdapter ncAdapter = new NcAdapter())
|
||||
@@ -150,6 +151,45 @@ namespace Thermo.Active.Controllers.WebApi
|
||||
if (libraryError.errorCode != 0)
|
||||
return NotFound();
|
||||
|
||||
// scrivo sul PLC il comando annula!
|
||||
CmsError cmsError = ncAdapter.ConfirmRecipeData(false);
|
||||
if (cmsError.IsError())
|
||||
return BadRequest(cmsError.localizationKey);
|
||||
|
||||
// recupero i dati LIVE dei parametri HMI della ricetta...
|
||||
cmsError = ncAdapter.ReadFullRecipe(out Dictionary<string, DTORecipeParam> currRecipe);
|
||||
if (cmsError.IsError())
|
||||
return BadRequest(cmsError.localizationKey);
|
||||
|
||||
var currParams = new Dictionary<string, double>();
|
||||
foreach (var item in currRecipe)
|
||||
{
|
||||
currParams.Add(item.Key, item.Value.SetpointPLC);
|
||||
}
|
||||
|
||||
// ora salvo ANCHE i dati live...
|
||||
RecipeLiveData.RecipeParameters = currParams;
|
||||
// e salvo su disco
|
||||
ServerConfigController.WriteLiveData();
|
||||
|
||||
// ritorno solo fatto!
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Save current recipe from PLC to default
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Route("save"), HttpPut]
|
||||
public IHttpActionResult Save()
|
||||
{
|
||||
using (NcFileAdapter ncAdapter = new NcFileAdapter())
|
||||
{
|
||||
// Try connection
|
||||
CmsError libraryError = ncAdapter.Connect();
|
||||
if (libraryError.errorCode != 0)
|
||||
return NotFound();
|
||||
|
||||
// recupero i dati LIVE dei parametri HMI della ricetta...
|
||||
CmsError cmsError = ncAdapter.ReadFullRecipe(out Dictionary<string, DTORecipeParam> currRecipe);
|
||||
@@ -167,37 +207,6 @@ namespace Thermo.Active.Controllers.WebApi
|
||||
// e salvo su disco
|
||||
ServerConfigController.WriteLiveData();
|
||||
|
||||
// scrivo sul PLC il comando annula!
|
||||
cmsError = ncAdapter.ConfirmRecipeData(false);
|
||||
if (cmsError.IsError())
|
||||
return BadRequest(cmsError.localizationKey);
|
||||
|
||||
// ritorno solo fatto!
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Save current recipe from PLC to default
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Route("Save"), HttpPut]
|
||||
public IHttpActionResult Save()
|
||||
{
|
||||
using (NcFileAdapter ncAdapter = new NcFileAdapter())
|
||||
{
|
||||
// Try connection
|
||||
CmsError libraryError = ncAdapter.Connect();
|
||||
if (libraryError.errorCode != 0)
|
||||
return NotFound();
|
||||
|
||||
// serialize current recipe as JSon
|
||||
|
||||
//// scrivo sul PLC il comando annula!
|
||||
//CmsError cmsError = ncAdapter.ConfirmRecipeData(false);
|
||||
//if (cmsError.IsError())
|
||||
// return BadRequest(cmsError.localizationKey);
|
||||
|
||||
// ritorno solo fatto!
|
||||
return Ok();
|
||||
}
|
||||
@@ -207,7 +216,7 @@ namespace Thermo.Active.Controllers.WebApi
|
||||
/// Save current recipe from PLC with new name
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Route("SaveAs"), HttpPut]
|
||||
[Route("saveAs"), HttpPut]
|
||||
public IHttpActionResult SaveAs(string newName)
|
||||
{
|
||||
using (NcFileAdapter ncAdapter = new NcFileAdapter())
|
||||
@@ -217,11 +226,22 @@ namespace Thermo.Active.Controllers.WebApi
|
||||
if (libraryError.errorCode != 0)
|
||||
return NotFound();
|
||||
|
||||
// scrivo sul PLC il comando annula!
|
||||
CmsError cmsError = ncAdapter.ConfirmRecipeData(false);
|
||||
// recupero i dati LIVE dei parametri HMI della ricetta...
|
||||
CmsError cmsError = ncAdapter.ReadFullRecipe(out Dictionary<string, DTORecipeParam> currRecipe);
|
||||
if (cmsError.IsError())
|
||||
return BadRequest(cmsError.localizationKey);
|
||||
|
||||
var currParams = new Dictionary<string, double>();
|
||||
foreach (var item in currRecipe)
|
||||
{
|
||||
currParams.Add(item.Key, item.Value.SetpointPLC);
|
||||
}
|
||||
|
||||
// ora salvo ANCHE i dati live...
|
||||
RecipeLiveData.RecipeParameters = currParams;
|
||||
// e salvo su disco
|
||||
ServerConfigController.SaveRecipe(newName);
|
||||
|
||||
// ritorno solo fatto!
|
||||
return Ok();
|
||||
}
|
||||
@@ -230,7 +250,7 @@ namespace Thermo.Active.Controllers.WebApi
|
||||
/// load recipe from file and send to PLC
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Route("Load"), HttpPut]
|
||||
[Route("load"), HttpPut]
|
||||
public IHttpActionResult Load(string newName)
|
||||
{
|
||||
using (NcFileAdapter ncAdapter = new NcFileAdapter())
|
||||
@@ -240,10 +260,8 @@ namespace Thermo.Active.Controllers.WebApi
|
||||
if (libraryError.errorCode != 0)
|
||||
return NotFound();
|
||||
|
||||
// scrivo sul PLC il comando annula!
|
||||
CmsError cmsError = ncAdapter.ConfirmRecipeData(false);
|
||||
if (cmsError.IsError())
|
||||
return BadRequest(cmsError.localizationKey);
|
||||
// chiamo metodo di lettura...
|
||||
ServerConfigController.LoadRecipe(newName);
|
||||
|
||||
// ritorno solo fatto!
|
||||
return Ok();
|
||||
|
||||
Reference in New Issue
Block a user