102 lines
3.5 KiB
C#
102 lines
3.5 KiB
C#
using CMS_CORE_Library.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
using System.Security.Claims;
|
|
using System.Threading.Tasks;
|
|
using System.Web;
|
|
using System.Web.Http;
|
|
using System.Windows.Media.Animation;
|
|
using TeamDev.SDK.MVVM;
|
|
using Thermo.Active.Config;
|
|
using Thermo.Active.Database.Controllers;
|
|
using Thermo.Active.Model.DTOModels;
|
|
using Thermo.Active.Model.DTOModels.ThIO;
|
|
using Thermo.Active.Model.DTOModels.ThRecipe;
|
|
using Thermo.Active.Model.DTOModels.ThWarmers;
|
|
using Thermo.Active.NC;
|
|
using Thermo.Active.Utils;
|
|
using static CMS_CORE_Library.Models.DataStructures;
|
|
using static Thermo.Active.Config.ServerConfig;
|
|
using static Thermo.Active.Model.Constants;
|
|
|
|
namespace Thermo.Active.Controllers.WebApi
|
|
{
|
|
[RoutePrefix("api/underthehood")]
|
|
public class UnderTheHoodController : ApiController
|
|
{
|
|
/// <summary>
|
|
/// Oggetto adapter condiviso da WebAPI
|
|
/// </summary>
|
|
protected static NcAdapter ncAdapter = new NcAdapter();
|
|
|
|
[Route("cyclelog"), HttpGet]
|
|
public IHttpActionResult GetCycleLog()
|
|
{
|
|
// // Try connection
|
|
CmsError libraryError = ncAdapter.Connect();
|
|
if (libraryError.IsError())
|
|
{
|
|
ThermoActiveLogger.LogError($"ncAdapter Not connected! | GetCycleLog | {libraryError.exception}");
|
|
}
|
|
|
|
libraryError = ncAdapter.GetCycleLog(out Dictionary<DateTime, int> machineLog);
|
|
if (libraryError.IsError())
|
|
{
|
|
ThermoActiveLogger.LogError($"GetCycleLog error | {libraryError.exception}");
|
|
return BadRequest(libraryError.localizationKey);
|
|
}
|
|
|
|
return Ok(machineLog);
|
|
}
|
|
|
|
[Route("channels_io"), HttpGet]
|
|
public IHttpActionResult GetChannelsIO()
|
|
{
|
|
// Try connection
|
|
CmsError libraryError = ncAdapter.Connect();
|
|
if (libraryError.IsError())
|
|
{
|
|
ThermoActiveLogger.LogError($"NC Not connected! | GetChannelsIO | {libraryError.exception}");
|
|
return BadRequest(libraryError.localizationKey);
|
|
}
|
|
|
|
// leggo dati gauges
|
|
libraryError = ncAdapter.ReadFullIO(out DTOChannelsIO ChannelsIO);
|
|
if (libraryError.IsError())
|
|
{
|
|
ThermoActiveLogger.LogError($"GetChannelsIO error | {libraryError.exception}");
|
|
return BadRequest(libraryError.localizationKey);
|
|
}
|
|
|
|
// ritorno!
|
|
return Ok(ChannelsIO);
|
|
}
|
|
[Route("channels_io_val"), HttpGet]
|
|
public IHttpActionResult GetChannelsIoVal()
|
|
{
|
|
// Try connection
|
|
CmsError libraryError = ncAdapter.Connect();
|
|
if (libraryError.IsError())
|
|
{
|
|
ThermoActiveLogger.LogError($"NC Not connected! | GetChannelsIoVal | {libraryError.exception}");
|
|
return BadRequest(libraryError.localizationKey);
|
|
}
|
|
|
|
// leggo dati gauges
|
|
libraryError = ncAdapter.ReadValIO(out DTOChannelsIOVal ChannelsIOVal);
|
|
if (libraryError.IsError())
|
|
{
|
|
ThermoActiveLogger.LogError($"GetChannelsIoVal error | {libraryError.exception}");
|
|
return BadRequest(libraryError.localizationKey);
|
|
}
|
|
|
|
// ritorno!
|
|
return Ok(ChannelsIOVal);
|
|
}
|
|
}
|
|
} |