137 lines
4.7 KiB
C#
137 lines
4.7 KiB
C#
using CMS_CORE_Library.Models;
|
|
using Step.Database.Controllers;
|
|
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
|
|
};
|
|
|
|
return Ok(clientConfiguration);
|
|
}
|
|
|
|
[Route("nc_softKeys"), HttpGet]
|
|
public IHttpActionResult GetNcSoftKeysConfig()
|
|
{
|
|
return Ok(NcSoftKeysConfig);
|
|
}
|
|
|
|
[Route("softKeys"), HttpGet]
|
|
public IHttpActionResult GetUserSoftKeysConfig()
|
|
{
|
|
Dictionary<int, List<DTOUserSoftKeyConfigModel>> config = new Dictionary<int, List<DTOUserSoftKeyConfigModel>>();
|
|
|
|
using (UserSoftkeysController controller = new UserSoftkeysController())
|
|
{
|
|
List<DTOUserSoftKeyConfigModel> 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<DTOUserSoftKeyConfigModel>());
|
|
}
|
|
|
|
// Add to the category the new softkey
|
|
config[softkey.Category].Add(softkey);
|
|
}
|
|
}
|
|
|
|
return Ok(config);
|
|
}
|
|
|
|
[Route("heads"), HttpGet]
|
|
public IHttpActionResult GetHeadsConfig()
|
|
{
|
|
List<DTOHeadsConfigModel> 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<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 (SiemensToolTableHandler ncHandler = new SiemensToolTableHandler())
|
|
{
|
|
ncHandler.Connect();
|
|
CmsError libraryError = ncHandler.GetToolTableConfiguration(out ToolTableConfiguration toolTableConfiguration);
|
|
if (libraryError.IsError())
|
|
return BadRequest(libraryError.localizationKey);
|
|
|
|
return Ok(toolTableConfiguration);
|
|
}
|
|
}
|
|
}
|
|
} |