using CMS_CORE_Library.Models; using Step.Database.Controllers; using Step.Model.ConfigModels; using Step.Model.DTOModels; using Step.Model.DTOModels.AlarmModels; using Step.NC; using System.Collections.Generic; using System.Linq; using System.Web.Http; using static Step.Config.ServerConfig; namespace Step.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, ToolingConfig = ToolingConfig, 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, 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("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("tool_manager"), HttpGet] public IHttpActionResult GetToolTableConfiguration() { using (SiemensToolTableAdapter ncAdapter = new SiemensToolTableAdapter()) { ncAdapter.Connect(); CmsError libraryError = ncAdapter.GetToolTableConfiguration(out ToolTableConfigurationModel toolTableConfiguration); if (libraryError.IsError()) return BadRequest(libraryError.localizationKey); return Ok(toolTableConfiguration); } } [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 }); } } }