From e3fb3302644a3fb734d3af8aa1af97e8d7d416da Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Fri, 29 May 2020 19:17:59 +0200 Subject: [PATCH] Preliminary models added to test --- .../DTOModels/Recipe/DTOModule.cs | 71 +++++++++++++++++++ .../DTOModels/Recipe/DTOModuleConfigModel.cs | 35 +++++++++ .../Thermo.Active.Model.csproj | 2 + .../Controllers/WebApi/ModulesController.cs | 41 +++++++++++ Thermo.Active/Thermo.Active.csproj | 1 + 5 files changed, 150 insertions(+) create mode 100644 Thermo.Active.Model/DTOModels/Recipe/DTOModule.cs create mode 100644 Thermo.Active.Model/DTOModels/Recipe/DTOModuleConfigModel.cs create mode 100644 Thermo.Active/Controllers/WebApi/ModulesController.cs diff --git a/Thermo.Active.Model/DTOModels/Recipe/DTOModule.cs b/Thermo.Active.Model/DTOModels/Recipe/DTOModule.cs new file mode 100644 index 00000000..26831f6f --- /dev/null +++ b/Thermo.Active.Model/DTOModels/Recipe/DTOModule.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Thermo.Active.Model.DTOModels.Recipe +{ + public class DTOModule + { + public int Id { get; set; } = 0; + public int ActualDuration { get; set; } = 0; + public int ActualDelay { get; set; } = 0; + public int EstimDuration { get; set; } = 0; + public int EstimDelay { get; set; } = 0; + public List PrevModId { get; set; } = new List(); + public RBStatus Status { get; set; } + + public override bool Equals(object obj) + { + if (!(obj is DTOModule item)) + return false; + + if (Id!= item.Id) + return false; + if (ActualDuration != item.ActualDuration) + return false; + if (ActualDelay != item.ActualDelay) + return false; + if (PrevModId != item.PrevModId) + return false; + if (EstimDelay != item.EstimDelay) + return false; + if (!Status.Equals(item.Status)) + return false; + + return true; + } + + public override int GetHashCode() + { + return base.GetHashCode(); + } + } + + public struct RBStatus + { + public bool Visible { get; set; } + public bool Executing { get; set; } + public bool HasError { get; set; } + public override bool Equals(object obj) + { + if (!(obj is RBStatus item)) + return false; + + if (Visible != item.Visible) + return false; + if (Executing != item.Executing) + return false; + if (HasError != item.HasError) + return false; + + return true; + } + + public override int GetHashCode() + { + return base.GetHashCode(); + } + } +} diff --git a/Thermo.Active.Model/DTOModels/Recipe/DTOModuleConfigModel.cs b/Thermo.Active.Model/DTOModels/Recipe/DTOModuleConfigModel.cs new file mode 100644 index 00000000..93d3c905 --- /dev/null +++ b/Thermo.Active.Model/DTOModels/Recipe/DTOModuleConfigModel.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Thermo.Active.Model.DTOModels.Recipe +{ + public class DTOModuleConfigModel + { + public int Id; + public string Label; + public BlockType Type; + public BlockSection Section; + public int IdMainParam = -1; // -1 = non visibile + public bool DelayVisible; + public int VisualPriority; + } + + public enum BlockType + { + HEATING, + DRAWING, + MOVEMENT, + VACUUM, + COOLING, + EXTRACTION + } + public enum BlockSection + { + HEATING, + FORMING, + EXTRACTION + } +} diff --git a/Thermo.Active.Model/Thermo.Active.Model.csproj b/Thermo.Active.Model/Thermo.Active.Model.csproj index b4394495..4621c464 100644 --- a/Thermo.Active.Model/Thermo.Active.Model.csproj +++ b/Thermo.Active.Model/Thermo.Active.Model.csproj @@ -102,6 +102,8 @@ + + diff --git a/Thermo.Active/Controllers/WebApi/ModulesController.cs b/Thermo.Active/Controllers/WebApi/ModulesController.cs new file mode 100644 index 00000000..20244e1f --- /dev/null +++ b/Thermo.Active/Controllers/WebApi/ModulesController.cs @@ -0,0 +1,41 @@ +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; + +namespace Thermo.Active.Controllers.WebApi +{ + [RoutePrefix("api/ModBlock")] + public class ModulesController : ApiController + { + [Route("current"), HttpGet] + public IHttpActionResult GetModules() + { + using (NcAdapter ncAdapter = new NcAdapter()) + { + // Try connection + CmsError libraryError = ncAdapter.Connect(); + if (libraryError.errorCode != 0) + return NotFound(); + + CmsError cmsError = ncAdapter.ReadFullRecipe(out Dictionary currRecipe); + if (cmsError.IsError()) + return BadRequest(cmsError.localizationKey); + + return Ok(currRecipe); + } + } + + } +} \ No newline at end of file diff --git a/Thermo.Active/Thermo.Active.csproj b/Thermo.Active/Thermo.Active.csproj index 3677d1d4..27014bd2 100644 --- a/Thermo.Active/Thermo.Active.csproj +++ b/Thermo.Active/Thermo.Active.csproj @@ -222,6 +222,7 @@ +