Fix Nullreference error on Opening window, adde SCADA validator
This commit is contained in:
@@ -19,6 +19,8 @@ namespace Step.Config
|
||||
{
|
||||
public static class ServerConfigController
|
||||
{
|
||||
private static string actualFileName;
|
||||
|
||||
public static void ReadStartupConfig()
|
||||
{
|
||||
try
|
||||
@@ -64,6 +66,8 @@ namespace Step.Config
|
||||
readerSettings.Add(null, schemaReader);
|
||||
}
|
||||
}
|
||||
|
||||
actualFileName = configFilePath;
|
||||
|
||||
// Open file reader
|
||||
XDocument xmlConfigFile = XDocument.Load(BASE_PATH + "\\" + configFilePath);
|
||||
@@ -73,6 +77,30 @@ namespace Step.Config
|
||||
return xmlConfigFile;
|
||||
}
|
||||
|
||||
|
||||
private static void validateScada(string configSchemaFilePath, string configFilePath)
|
||||
{
|
||||
// Create new instance
|
||||
XmlSchemaSet readerSettings = new XmlSchemaSet();
|
||||
|
||||
// Add Schema from Assembly
|
||||
Assembly myAssembly = Assembly.GetExecutingAssembly();
|
||||
using (Stream schemaStream = myAssembly.GetManifestResourceStream(configSchemaFilePath))
|
||||
{
|
||||
using (XmlReader schemaReader = XmlReader.Create(schemaStream))
|
||||
{
|
||||
readerSettings.Add(null, schemaReader);
|
||||
}
|
||||
}
|
||||
|
||||
actualFileName = Path.GetFileName(configFilePath);
|
||||
|
||||
// Open file reader
|
||||
XDocument xmlConfigFile = XDocument.Load(configFilePath);
|
||||
// Validate file
|
||||
xmlConfigFile.Validate(readerSettings, ValidationHandler);
|
||||
}
|
||||
|
||||
private static void SetAreaValueByName(XElement element)
|
||||
{
|
||||
// Choose which area to be set
|
||||
@@ -140,7 +168,7 @@ namespace Step.Config
|
||||
{
|
||||
ExceptionManager.Manage(ERROR_LEVEL.FATAL,
|
||||
// "Error while reading file: " + e.Exception.SourceUri +
|
||||
"Error while reading configuration file: " + e.Message,
|
||||
"Error while reading XML file \"" + actualFileName + "\" \n\n" + e.Message,
|
||||
true
|
||||
);
|
||||
}
|
||||
@@ -192,9 +220,13 @@ namespace Step.Config
|
||||
// Cycle inside xml files
|
||||
foreach (var file in files)
|
||||
{
|
||||
validateScada(SCADA_PAGES_SCHEMA_PATH, SCADA_DIRECTORY + file.Name);
|
||||
|
||||
StreamReader sr = new StreamReader(SCADA_DIRECTORY + file.Name);
|
||||
XmlSerializer xmlSerializer = new XmlSerializer(typeof(ScadaSchemaModel));
|
||||
ScadaSchemaModel schema = xmlSerializer.Deserialize(sr) as ScadaSchemaModel;
|
||||
|
||||
|
||||
// Setup incremental ids
|
||||
schema.Id = i++;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user