* Refactored configuration
* Added Selected process and select process action * Added Heads signalR and configuration
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using Step.Model.ConfigModels;
|
||||
using Step.Utils;
|
||||
using static Step.Utils.SupportFunctions;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
@@ -16,106 +17,12 @@ namespace Step.Config
|
||||
{
|
||||
try
|
||||
{
|
||||
// Get server file handler
|
||||
XDocument xmlConfigFile = GetXmlHandlerWithValidator(SERVER_CONFIG_SCHEMA_PATH, SERVER_CONFIG_PATH);
|
||||
|
||||
// Read nc Config with LINQ
|
||||
NcConfig = xmlConfigFile
|
||||
.Descendants(NC_CONFIG_KEY)
|
||||
.Select(x => new NcConfigModel()
|
||||
{
|
||||
NcVendor = x.Element("ncVendor").Value,
|
||||
showNcHMI = Convert.ToBoolean(x.Element("showNcHMI").Value),
|
||||
NcIpAddress = x.Element("ncIpAddress").Value,
|
||||
NcPort = Convert.ToUInt16(x.Element("ncPort").Value),
|
||||
NcName = x.Element("machineModel").Value
|
||||
}).FirstOrDefault();
|
||||
|
||||
// Read server config with LINQ and save into static config
|
||||
ServerStartupConfig = xmlConfigFile
|
||||
.Descendants(SERVER_CONFIG_KEY)
|
||||
.Select(x => new ServerConfigModel()
|
||||
{ // Set server config model data
|
||||
Language = CultureInfo.CreateSpecificCulture(x.Element("language").Value),
|
||||
ServerAddress = x.Element("serverAddress").Value,
|
||||
ServerPort = Convert.ToInt32(x.Element("serverPort").Value),
|
||||
EnableDirectoryBrowsing = Convert.ToBoolean(x.Element("enableDirectoryBrowsing").Value),
|
||||
DatabaseAddress = x.Element("databaseAddress").Value
|
||||
}).FirstOrDefault();
|
||||
|
||||
// Get Areas file handler
|
||||
xmlConfigFile = GetXmlHandlerWithValidator(AREAS_CONFIG_SCHEMA_PATH, AREAS_CONFIG_PATH);
|
||||
|
||||
// Read areas config with LINQ
|
||||
xmlConfigFile
|
||||
.Descendants(AREAS_CONFIG_KEY) // Get areas config node
|
||||
.Elements()
|
||||
.ToList()
|
||||
.ForEach(x => SetAreaValueByName(x)); // Loop through elements
|
||||
|
||||
// Get Maintenances file handler
|
||||
xmlConfigFile = GetXmlHandlerWithValidator(MAINTENANCES_CONFIG_SCHEMA_PATH, MAINTENANCES_CONFIG_PATH);
|
||||
|
||||
MaintenancesConfig = xmlConfigFile
|
||||
.Root
|
||||
.Elements()
|
||||
.ToList()
|
||||
.Select(x =>
|
||||
new MaintenanceConfigModel()
|
||||
{
|
||||
Id = Convert.ToInt32(x.Element("id").Value),
|
||||
LocalizedNames = x.Element("localizedNames").Elements().ToDictionary( // Read names list
|
||||
y => y.Attribute("langKey").Value, y => y.Value
|
||||
),
|
||||
Intervall = TimeSpan.FromMinutes(Convert.ToDouble(x.Element("interval").Value)),
|
||||
Deadline = DateTime.Parse(x.Element("deadline").Value),
|
||||
Type = x.Element("type").Value,
|
||||
CouterId = Convert.ToInt32(x.Element("counterId").Value)
|
||||
}
|
||||
)
|
||||
.ToList();
|
||||
|
||||
// Get SoftKeys
|
||||
xmlConfigFile = GetXmlHandlerWithValidator(SOFT_KEY_CONFIG_SCHEMA_PATH, SOFT_KEY_CONFIG_PATH);
|
||||
int id = 1;
|
||||
|
||||
SoftKeysConfig = xmlConfigFile
|
||||
.Root
|
||||
.Elements()
|
||||
.Where(x => Convert.ToBoolean(x.Element("active").Value) == true) // Only active softkey
|
||||
.Select(x => new SoftKeyConfigModel()
|
||||
{
|
||||
Id = id++,
|
||||
PlcId = Convert.ToInt32(x.Element("plcId")?.Value), // If exists
|
||||
IsActive = Convert.ToBoolean(x.Element("active").Value),
|
||||
Category = Convert.ToInt32(x.Element("category").Value),
|
||||
LocalizedNames = x.Element("localizedNames").Elements().ToDictionary( // Read localized names and convert into a dictionary
|
||||
y => y.Attribute("langKey").Value, y => y.Value
|
||||
),
|
||||
|
||||
SubKeys = x.Element("plcKeys")?.Elements().Select(y => new SubKeysModel() // Populate subkeys if exist
|
||||
{
|
||||
Id = id++,
|
||||
PlcId = Convert.ToInt32(y.Attribute("plcId").Value),
|
||||
Text = y.Value
|
||||
}).ToList(),
|
||||
Type = GetSoftKeyType(x.Name.ToString()),
|
||||
OperatorConfirmationNeeded = Convert.ToBoolean(x.Element("operatorConfirmationNeeded").Value)
|
||||
})
|
||||
.ToList();
|
||||
|
||||
xmlConfigFile = GetXmlHandlerWithValidator(ALARM_CONFIG_SCHEMA_PATH, ALARM_CONFIG_PATH);
|
||||
|
||||
InitialAlarmsConfig = xmlConfigFile
|
||||
.Root
|
||||
.Elements()
|
||||
.Select(x => new AlarmsConfigModel()
|
||||
{
|
||||
AlarmId = Convert.ToInt32(x.Element("alarmId").Value),
|
||||
PlcId = Convert.ToInt32(x.Element("plcId").Value),
|
||||
RestoreIsActive = Convert.ToBoolean(x.Element("restoreIsActive").Value)
|
||||
})
|
||||
.ToList();
|
||||
ReadServerConfig();
|
||||
ReadAreaConfig();
|
||||
ReadMaintenancesConfig();
|
||||
ReadSoftkeysConfig();
|
||||
ReadAlarmsConfig();
|
||||
ReadHeadsConfig();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -138,16 +45,6 @@ namespace Step.Config
|
||||
return xmlConfigFile;
|
||||
}
|
||||
|
||||
private static SOFTKEY_TYPE GetSoftKeyType(string type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case "softkey_procedure": return SOFTKEY_TYPE.PROCEDURE;
|
||||
case "softkey_group": return SOFTKEY_TYPE.GROUP;
|
||||
default: return SOFTKEY_TYPE.TOGGLE;
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetAreaValueByName(XElement element)
|
||||
{
|
||||
// Choose which area to be set
|
||||
@@ -239,5 +136,147 @@ namespace Step.Config
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#region Read config from file
|
||||
|
||||
public static void ReadServerConfig()
|
||||
{
|
||||
// Get server file handler
|
||||
XDocument xmlConfigFile = GetXmlHandlerWithValidator(SERVER_CONFIG_SCHEMA_PATH, SERVER_CONFIG_PATH);
|
||||
|
||||
// Read nc Config with LINQ
|
||||
NcConfig = xmlConfigFile
|
||||
.Descendants(NC_CONFIG_KEY)
|
||||
.Select(x => new NcConfigModel()
|
||||
{
|
||||
NcVendor = x.Element("ncVendor").Value,
|
||||
showNcHMI = Convert.ToBoolean(x.Element("showNcHMI").Value),
|
||||
NcIpAddress = x.Element("ncIpAddress").Value,
|
||||
NcPort = Convert.ToUInt16(x.Element("ncPort").Value),
|
||||
NcName = x.Element("machineModel").Value
|
||||
}).FirstOrDefault();
|
||||
|
||||
// Read server config with LINQ and save into static config
|
||||
ServerStartupConfig = xmlConfigFile
|
||||
.Descendants(SERVER_CONFIG_KEY)
|
||||
.Select(x => new ServerConfigModel()
|
||||
{ // Set server config model data
|
||||
Language = CultureInfo.CreateSpecificCulture(x.Element("language").Value),
|
||||
ServerAddress = x.Element("serverAddress").Value,
|
||||
ServerPort = Convert.ToInt32(x.Element("serverPort").Value),
|
||||
EnableDirectoryBrowsing = Convert.ToBoolean(x.Element("enableDirectoryBrowsing").Value),
|
||||
DatabaseAddress = x.Element("databaseAddress").Value
|
||||
}).FirstOrDefault();
|
||||
}
|
||||
|
||||
private static void ReadAreaConfig()
|
||||
{
|
||||
// Get Areas file handler
|
||||
XDocument xmlConfigFile = GetXmlHandlerWithValidator(AREAS_CONFIG_SCHEMA_PATH, AREAS_CONFIG_PATH);
|
||||
|
||||
// Read areas config with LINQ
|
||||
xmlConfigFile
|
||||
.Descendants(AREAS_CONFIG_KEY) // Get areas config node
|
||||
.Elements()
|
||||
.ToList()
|
||||
.ForEach(x => SetAreaValueByName(x)); // Loop through elements
|
||||
}
|
||||
|
||||
public static void ReadMaintenancesConfig()
|
||||
{
|
||||
// Get Maintenances file handler
|
||||
XDocument xmlConfigFile = GetXmlHandlerWithValidator(MAINTENANCES_CONFIG_SCHEMA_PATH, MAINTENANCES_CONFIG_PATH);
|
||||
|
||||
MaintenancesConfig = xmlConfigFile
|
||||
.Root
|
||||
.Elements()
|
||||
.ToList()
|
||||
.Select(x =>
|
||||
new MaintenanceConfigModel()
|
||||
{
|
||||
Id = Convert.ToInt32(x.Element("id").Value),
|
||||
LocalizedNames = x.Element("localizedNames").Elements().ToDictionary( // Read names list
|
||||
y => y.Attribute("langKey").Value, y => y.Value
|
||||
),
|
||||
Intervall = TimeSpan.FromMinutes(Convert.ToDouble(x.Element("interval").Value)),
|
||||
Deadline = DateTime.Parse(x.Element("deadline").Value),
|
||||
Type = x.Element("type").Value,
|
||||
CouterId = Convert.ToInt32(x.Element("counterId").Value)
|
||||
}
|
||||
)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
private static void ReadSoftkeysConfig()
|
||||
{
|
||||
// Get Softkeys
|
||||
XDocument xmlConfigFile = GetXmlHandlerWithValidator(SOFTKEYS_CONFIG_SCHEMA_PATH, SOFTKEYS_CONFIG_PATH);
|
||||
int id = 1;
|
||||
// Read softkey configuration from XML with LINQ
|
||||
SoftKeysConfig = xmlConfigFile
|
||||
.Root
|
||||
.Elements()
|
||||
.Where(x => Convert.ToBoolean(x.Element("active").Value) == true) // Only active softkey
|
||||
.Select(x => new SoftKeyConfigModel()
|
||||
{
|
||||
Id = id++, // autoincrement Id
|
||||
PlcId = Convert.ToInt32(x.Element("plcId")?.Value), // If exists
|
||||
IsActive = Convert.ToBoolean(x.Element("active").Value),
|
||||
Category = Convert.ToInt32(x.Element("category").Value),
|
||||
LocalizedNames = x.Element("localizedNames").Elements().ToDictionary( // Read localized names and convert into a dictionary
|
||||
y => y.Attribute("langKey").Value, y => y.Value
|
||||
),
|
||||
|
||||
SubKeys = x.Element("plcKeys")?.Elements().Select(y => new SubKeysModel() // Populate subkeys if exist
|
||||
{
|
||||
Id = id++,
|
||||
PlcId = Convert.ToInt32(y.Attribute("plcId").Value),
|
||||
Text = y.Value
|
||||
}).ToList(),
|
||||
Type = GetSoftKeyType(x.Name.ToString()),
|
||||
OperatorConfirmationNeeded = Convert.ToBoolean(x.Element("operatorConfirmationNeeded").Value)
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
private static void ReadAlarmsConfig()
|
||||
{
|
||||
XDocument xmlConfigFile = GetXmlHandlerWithValidator(ALARMS_CONFIG_SCHEMA_PATH, ALARMS_CONFIG_PATH);
|
||||
// Read alarms config from XML file
|
||||
InitialAlarmsConfig = xmlConfigFile
|
||||
.Root
|
||||
.Elements()
|
||||
.Select(x => new AlarmsConfigModel()
|
||||
{
|
||||
AlarmId = Convert.ToInt32(x.Element("alarmId").Value),
|
||||
PlcId = Convert.ToInt32(x.Element("plcId").Value),
|
||||
RestoreIsActive = Convert.ToBoolean(x.Element("restoreIsActive").Value)
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
private static void ReadHeadsConfig()
|
||||
{
|
||||
XDocument xmlConfigFile = GetXmlHandlerWithValidator(HEADS_CONFIG_SCHEMA_PATH, HEADS_CONFIG_PATH);
|
||||
|
||||
int i = 0;
|
||||
// Read head config from XML file
|
||||
HeadsConfig = xmlConfigFile
|
||||
.Root
|
||||
.Elements()
|
||||
.Select(x => new HeadsConfigModel()
|
||||
{
|
||||
Id = i++, // Autoincrement Id
|
||||
Name = x.Element("name").Value,
|
||||
Type = GetHeadType(x.Element("type").Value),
|
||||
WarningLimit = Convert.ToInt16(x.Element("warningLimit").Value),
|
||||
AlarmLimit = Convert.ToInt16(x.Element("alarmLimit").Value),
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
#endregion Read config from file
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user