7ba9db0fd1
WIP error hanling
141 lines
4.8 KiB
C#
141 lines
4.8 KiB
C#
using Step.Model.DTOModels;
|
|
using Step.NC;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web.Http;
|
|
using static CMS_CORE_Library.DataStructures;
|
|
using static Step.Config.ServerConfig;
|
|
using static Step.Model.Constants;
|
|
|
|
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
|
|
};
|
|
|
|
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
|
|
};
|
|
|
|
return Ok(clientConfiguration);
|
|
}
|
|
|
|
[Route("nc_softKeys"), HttpGet]
|
|
public IHttpActionResult GetNcSoftKeysConfig()
|
|
{
|
|
return Ok(NcSoftKeysConfig);
|
|
}
|
|
|
|
[Route("softKeys"), HttpGet]
|
|
public IHttpActionResult GetUserSoftKeysConfig()
|
|
{
|
|
Dictionary<int, List<DTOUserSoftKeyConfigModel>> output = new Dictionary<int, List<DTOUserSoftKeyConfigModel>>();
|
|
foreach (var softKey in SoftKeysConfig)
|
|
{
|
|
// Check if category exists
|
|
if (!output.ContainsKey(softKey.Category))
|
|
{
|
|
// Add category if not exits
|
|
output.Add(softKey.Category, new List<DTOUserSoftKeyConfigModel>());
|
|
}
|
|
|
|
// Create subkeys dictionary for group
|
|
Dictionary<int, string> tmpSubKey = new Dictionary<int, string>();
|
|
if (softKey.Type == SOFTKEY_TYPE.GROUP && softKey.SubKeys != null)
|
|
{
|
|
tmpSubKey = new Dictionary<int, string>();
|
|
foreach (var subKey in softKey.SubKeys)
|
|
{
|
|
tmpSubKey.Add(subKey.Id, subKey.Text);
|
|
}
|
|
}
|
|
// Add to the category the new softkey
|
|
output[softKey.Category].Add(new DTOUserSoftKeyConfigModel()
|
|
{
|
|
Id = softKey.Id,
|
|
Category = softKey.Category,
|
|
OperatorConfirmationNeeded = softKey.OperatorConfirmationNeeded,
|
|
Type = softKey.Type,
|
|
SubKeys = tmpSubKey
|
|
});
|
|
}
|
|
|
|
return Ok(output);
|
|
}
|
|
|
|
[Route("heads"), HttpGet]
|
|
public IHttpActionResult GetHeadsConfig()
|
|
{
|
|
List<DTOHeadsConfigModel> heads = HeadsConfig.Select(x => new DTOHeadsConfigModel()
|
|
{
|
|
Id = x.Id,
|
|
Name = x.Name,
|
|
Type = x.Type.ToString()
|
|
}).ToList();
|
|
|
|
return Ok(heads);
|
|
}
|
|
|
|
[Route("alarms"), HttpGet]
|
|
public IHttpActionResult GetAlarmsConfig()
|
|
{
|
|
List<DTOAlarmConfigModel> alarmsConfig = new List<DTOAlarmConfigModel>();
|
|
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 (NcHandler ncHandler = new NcHandler())
|
|
{
|
|
ncHandler.Connect();
|
|
CmsError libraryError = ncHandler.GetToolTableConfiguration(out ToolTableConfiguration toolTableConfiguration);
|
|
if (libraryError.IsError())
|
|
return BadRequest(libraryError.message);
|
|
|
|
return Ok(toolTableConfiguration);
|
|
}
|
|
}
|
|
}
|
|
} |