using CMS_CORE_Library.Models;
using Thermo.Active.Model.DTOModels;
using Thermo.Active.NC;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web.Http;
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.Config;
using Thermo.Active.Utils;
namespace Thermo.Active.Controllers.WebApi
{
[RoutePrefix("api/prod")]
public class ProdController : ApiController
{
///
/// Request mode SETUP
///
///
[Route("mode/manual"), HttpPut]
public IHttpActionResult RequestManual()
{
using (NcAdapter ncAdapter = new NcAdapter())
{
// Try connection
CmsError libraryError = ncAdapter.Connect();
if (libraryError.errorCode != 0)
{
ThermoActiveLogger.LogError($"NC Not connected! | RequestManual | {libraryError.exception}");
return InternalServerError();
}
// scrivo sul PLC il comando strobe richiesta AUTO!
CmsError cmsError = ncAdapter.StrobeMode(Model.DTOModels.ThermoProd.Mode.MANUAL);
if (cmsError.IsError())
{
ThermoActiveLogger.LogError($"RequestManual error | {cmsError.exception}");
return BadRequest(cmsError.localizationKey);
}
// ritorno solo fatto!
return Ok();
}
}
///
/// Request mode AUTO
///
///
[Route("mode/auto"), HttpPut]
public IHttpActionResult RequestAuto()
{
using (NcAdapter ncAdapter = new NcAdapter())
{
// Try connection
CmsError libraryError = ncAdapter.Connect();
if (libraryError.errorCode != 0)
{
ThermoActiveLogger.LogError($"NC Not connected! | RequestAuto | {libraryError.exception}");
return InternalServerError();
}
// scrivo sul PLC il comando strobe richiesta AUTO!
CmsError cmsError = ncAdapter.StrobeMode(Model.DTOModels.ThermoProd.Mode.AUTO);
if (cmsError.IsError())
{
ThermoActiveLogger.LogError($"RequestAuto error | {cmsError.exception}");
return BadRequest(cmsError.localizationKey);
}
// ritorno solo fatto!
return Ok();
}
}
///
/// Request mode SETUP
///
///
[Route("mode/setup"), HttpPut]
public IHttpActionResult RequestSetup()
{
using (NcAdapter ncAdapter = new NcAdapter())
{
// Try connection
CmsError libraryError = ncAdapter.Connect();
if (libraryError.errorCode != 0)
{
ThermoActiveLogger.LogError($"NC Not connected! | RequestSetup | {libraryError.exception}");
return InternalServerError();
}
// scrivo sul PLC il comando strobe richiesta AUTO!
CmsError cmsError = ncAdapter.StrobeMode(Model.DTOModels.ThermoProd.Mode.SETUP);
if (cmsError.IsError())
{
ThermoActiveLogger.LogError($"RequestSetup error | {cmsError.exception}");
return BadRequest(cmsError.localizationKey);
}
// ritorno solo fatto!
return Ok();
}
}
}
}