Index: Riskeer/Common/src/Riskeer.Common.IO/Configurations/Import/CalculationConfigurationReader.cs =================================================================== diff -u -r661230a589ec46dcfe7c68806be1c61900755b56 -r4dddcf9e7644f7dba41895c486f63a5a968dddcb --- Riskeer/Common/src/Riskeer.Common.IO/Configurations/Import/CalculationConfigurationReader.cs (.../CalculationConfigurationReader.cs) (revision 661230a589ec46dcfe7c68806be1c61900755b56) +++ Riskeer/Common/src/Riskeer.Common.IO/Configurations/Import/CalculationConfigurationReader.cs (.../CalculationConfigurationReader.cs) (revision 4dddcf9e7644f7dba41895c486f63a5a968dddcb) @@ -51,7 +51,7 @@ /// /// The file path to the XML file. /// The . - /// Thrown when + /// Thrown when /// is null. /// Thrown when: /// @@ -68,24 +68,21 @@ /// protected CalculationConfigurationReader(string xmlFilePath, IEnumerable schemaDefinitions) { + if (schemaDefinitions == null) + { + throw new ArgumentNullException(nameof(schemaDefinitions)); + } + IOUtils.ValidateFilePath(xmlFilePath); ValidateFileExists(xmlFilePath); xmlDocument = LoadDocument(xmlFilePath); - int versionNumber = GetSchemaDefinition(); + CalculationConfigurationSchemaDefinition schemaDefinition = GetSchemaDefinition(schemaDefinitions, xmlFilePath); + + ValidateToSchema(xmlDocument, xmlFilePath, schemaDefinition.MainSchemaDefinition, schemaDefinition.NestedSchemaDefinitions); - if (!schemaDefinitions.Any(schemaDefinition => schemaDefinition.VersionNumber == versionNumber)) - { - string message = new FileReaderErrorMessageBuilder(xmlFilePath) - .Build("Het versienummer van het bestand wordt niet ondersteund."); - - throw new CriticalFileReadException(message); - } - - ValidateToSchema(xmlDocument, xmlFilePath, schemaDefinitions.ElementAt(versionNumber).MainSchemaDefinition, schemaDefinitions.ElementAt(versionNumber).NestedSchemaDefinitions); - ValidateNotEmpty(xmlDocument, xmlFilePath); } @@ -105,9 +102,18 @@ /// A parsed . protected abstract TReadCalculation ParseCalculationElement(XElement calculationElement); - private int GetSchemaDefinition() + /// + /// Gets the correct schema definition depending on the version. + /// + /// All the schema definitions. + /// The file path to the XML file. + /// The schema definition that belongs to the XML file. + /// Thrown when the version + /// from the XML file is not supported. + private CalculationConfigurationSchemaDefinition GetSchemaDefinition(IEnumerable schemaDefinitions, string xmlFilePath) { int versionNumber; + try { var combinedXmlSchemaDefinition = new CombinedXmlSchemaDefinition(Resources.VersieSchema, new Dictionary()); @@ -122,7 +128,17 @@ versionNumber = 0; } - return versionNumber; + CalculationConfigurationSchemaDefinition schemaDefinition = schemaDefinitions.SingleOrDefault(sd => sd.VersionNumber == versionNumber); + + if (schemaDefinition == null) + { + string message = new FileReaderErrorMessageBuilder(xmlFilePath) + .Build(Resources.CalculationConfigurationReader_GetSchemaDefinition_Not_supported_version); + + throw new CriticalFileReadException(message); + } + + return schemaDefinition; } /// Index: Riskeer/Common/src/Riskeer.Common.IO/Properties/Resources.Designer.cs =================================================================== diff -u -rc569d5705bffb682cde45f5f18077c9f95aeb736 -r4dddcf9e7644f7dba41895c486f63a5a968dddcb --- Riskeer/Common/src/Riskeer.Common.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision c569d5705bffb682cde45f5f18077c9f95aeb736) +++ Riskeer/Common/src/Riskeer.Common.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 4dddcf9e7644f7dba41895c486f63a5a968dddcb) @@ -293,6 +293,15 @@ } /// + /// Looks up a localized string similar to Het versienummer van het bestand wordt niet ondersteund.. + /// + public static string CalculationConfigurationReader_GetSchemaDefinition_Not_supported_version { + get { + return ResourceManager.GetString("CalculationConfigurationReader_GetSchemaDefinition_Not_supported_version", resourceCulture); + } + } + + /// /// Looks up a localized string similar to Het XML-document dat de configuratie voor de berekeningen beschrijft, moet mappen en/of berekeningen bevatten.. /// public static string CalculationConfigurationReader_No_configuration_items_found {