using System.Collections.Generic; using System.Linq; using System.Web.Http; using Thermo.Active.Database.Controllers; using Thermo.Active.Model.ConfigModels; using Thermo.Active.Model.DTOModels; using Thermo.Active.Model.DTOModels.AlarmModels; using Thermo.Active.Model.DTOModels.ThIO; using Thermo.Active.Model.DTOModels.ThProd; using Thermo.Active.Model.DTOModels.ThRecipe; using static Thermo.Active.Config.ServerConfig; namespace Thermo.Active.Controllers.WebApi { [RoutePrefix("api/configuration")] public class ConfigurationController : ApiController { [Route("areas"), HttpGet] public IHttpActionResult GetStartupConfiguration() { DTOStartupConfigurationModel startupConfiguration = new DTOStartupConfigurationModel() { ProductionConfig = ProductionConfig, AlarmsConfig = AlarmsConfig, ScadaConfig = ScadaConfig, MaintenanceConfig = MaintenanceConfig, ReportConfig = ReportConfig, UtilitiesConfig = UtilitiesConfig, JobEditorConfig = JobEditorConfig, UsersConfig = UsersConfig }; return Ok(startupConfiguration); } [Route("client"), HttpGet] public IHttpActionResult GetInfoConfiguration() { DTOClientConfigurationModel clientConfiguration = new DTOClientConfigurationModel() { NcVendor = NcConfig.NcVendor, ShowHMI = NcConfig.ShowNcHMI, DefaultLanguage = ServerStartupConfig.Language, NcIp = NcConfig.NcIpAddress, NcPort = NcConfig.NcPort, ProdEnabled = SoftwareProdConfig.Enabled, ProdPath = SoftwareProdConfig.Path, ExtSoftwares = ExtSoftwaresConfig, AdditionalParameters = AdditionalParametersConfig, Autorun = ServerStartupConfig.AutoOpenCmsClient, EditorPath = ServerStartupConfig.TextEditorPath, MgiOption = NcConfig.MgiOption, //CmsConnectReady = CmsConnectConfig.Enabled CmsConnectReady = ServerStartupConfig.CmsConnectReady, SiemensKeyboardOption = NcConfig.SiemensKeyboardOption }; return Ok(clientConfiguration); } [Route("nc_softKeys"), HttpGet] public IHttpActionResult GetNcSoftKeysConfig() { return Ok(NcSoftKeysConfig); } [Route("softKeys"), HttpGet] public IHttpActionResult GetUserSoftKeysConfig() { Dictionary> config = new Dictionary>(); using (UserSoftkeysController controller = new UserSoftkeysController()) { List softkeys = controller.GetUserSoftkeyConfig(); // Organize by category foreach (var softkey in softkeys) { // Check if category exists if (!config.ContainsKey(softkey.Category)) { // Add category if not exits config.Add(softkey.Category, new List()); } // Add to the category the new softkey config[softkey.Category].Add(softkey); } } return Ok(config); } [Route("heads"), HttpGet] public IHttpActionResult GetHeadsConfig() { List heads = HeadsConfig.Select(x => new DTOHeadsConfigModel() { Id = x.Id, Name = "Head " + x.Id, Type = x.Type.ToString(), FixedHead = x.FixedHead }).ToList(); return Ok(heads); } [Route("recipe"), HttpGet] public IHttpActionResult GetRecipeConfig() { List recipeConfig = RecipeConfig.Select(x => new DTORecipeConfigModel() { Id = x.Id, ScaleFactor = x.ScaleFactor, NumDec = x.NumDec, Category = x.Category.ToString(), SubCategory_1 = x.SubCategory_1, SubCategory_2 = x.SubCategory_2, Name = x.Name, Description = x.Description, Format = x.Format, Label = $"{x.Category}_{x.SubCategory_1}_{x.SubCategory_2}_{x.Name}".Replace("__", "_").Replace("__", "_").ToLower(), EnumVal = x.EnumVal }).ToList(); return Ok(recipeConfig); } [Route("recipeTest"), HttpGet] public IHttpActionResult GetRecipeTest() { List recipeConfig = RecipeConfig.Select(x => new DTORecipeConfigModel() { Id = x.Id, ScaleFactor = x.ScaleFactor, NumDec = x.NumDec, Category = x.Category.ToString(), SubCategory_1 = x.SubCategory_1, SubCategory_2 = x.SubCategory_2, Name = x.Name, Description = x.Description, Format = x.Format, Label = $"{x.Category}_{x.SubCategory_1}_{x.SubCategory_2}_{x.Name}".Replace("__", "_").Replace("__", "_").ToLower(), EnumVal = x.EnumVal }).ToList(); return Ok(recipeConfig); } [Route("configIO"), HttpGet] public IHttpActionResult GetIOConfig() { DTOChannelsSetup configIO = new DTOChannelsSetup(); // leggo i 4 tipi di oggetti e popolo List listDI = IOConfig.Where(x => x.Category == Model.Constants.TACT_IO_TYPE.DI).GroupBy(x => x.Bank).Select(x => x.Key).ToList(); List listDO = IOConfig.Where(x => x.Category == Model.Constants.TACT_IO_TYPE.DO).GroupBy(x => x.Bank).Select(x => x.Key).ToList(); List listAI = IOConfig.Where(x => x.Category == Model.Constants.TACT_IO_TYPE.AI).GroupBy(x => x.Bank).Select(x => x.Key).ToList(); List listAO = IOConfig.Where(x => x.Category == Model.Constants.TACT_IO_TYPE.AO).GroupBy(x => x.Bank).Select(x => x.Key).ToList(); // assegno! configIO.DI = listDI; configIO.DO = listDO; configIO.AI = listAI; configIO.AO = listAO; // restituisco return Ok(configIO); } [Route("thermoProd"), HttpGet] public IHttpActionResult GetThermoProdConfig() { // FIXME TODO List thermoProdConfig = ThermoProdConfig.Select(x => new DTOThermoProd() { Category = x.Category, Name = x.Name, Label = x.Label, UM= x.UM, ScaleFactor = x.ScaleFactor, NumDec = x.NumDec, MinVal = x.MinVal, MaxVal = x.MaxVal, }).ToList(); return Ok(thermoProdConfig); } [Route("alarms"), HttpGet] public IHttpActionResult GetAlarmsConfig() { List alarmsConfig = new List(); bool restoreIsEnabled = false; for (int i = 1; i <= 1024; i++) { var configuredAlarm = InitialAlarmsConfig.Where(x => x.PlcId == i).FirstOrDefault(); if (configuredAlarm == null) restoreIsEnabled = false; else restoreIsEnabled = configuredAlarm.RestoreIsActive; alarmsConfig.Add(new DTOAlarmConfigModel { Id = i, RestoreIsEnabled = restoreIsEnabled }); } return Ok(alarmsConfig); } [Route("cmscontact"), HttpGet] public IHttpActionResult GetCmsContact() { if (!Config.ServerConfigController.ReadAssistanceCustomConfig()) ContactInfoError = Model.Constants.API_ERROR_KEYS.CUSTOMER_FILE_INVALID; else ContactInfoError = ""; ContactModel ContactConfig = CmsContactConfig; ContactModel AuxContact1 = CmsAuxContact1; ContactModel AuxContact2 = CmsAuxContact2; ContactModel ItalyContactConfig = CmsContactConfig; if (DealerContactConfig != null && DealerAuxContact1 != null && DealerAuxContact2 != null) { ContactConfig = DealerContactConfig; AuxContact1 = DealerAuxContact1; AuxContact2 = DealerAuxContact2; } return Ok(new { ContactConfig, AuxContact1, AuxContact2, ItalyContactConfig, ContactInfoError }); } [Route("scmcontact"), HttpGet] public IHttpActionResult GetScmContact() { ContactInfoError = ""; ContactModel ContactConfig = ScmContactConfig; ContactModel AuxContact1 = ScmAuxContact1; ContactModel AuxContact2 = ScmAuxContact2; ContactModel ItalyContactConfig = ScmContactConfig; return Ok(new { ContactConfig, AuxContact1, AuxContact2, ItalyContactConfig, ContactInfoError }); } } }