Index: Riskeer/Common/src/Riskeer.Common.IO/Configurations/Import/CalculationConfigurationReader.cs
===================================================================
diff -u -r4b596cdfd60b2f47f25bb1d5fefa4f539a56905e -rc569d5705bffb682cde45f5f18077c9f95aeb736
--- Riskeer/Common/src/Riskeer.Common.IO/Configurations/Import/CalculationConfigurationReader.cs (.../CalculationConfigurationReader.cs) (revision 4b596cdfd60b2f47f25bb1d5fefa4f539a56905e)
+++ Riskeer/Common/src/Riskeer.Common.IO/Configurations/Import/CalculationConfigurationReader.cs (.../CalculationConfigurationReader.cs) (revision c569d5705bffb682cde45f5f18077c9f95aeb736)
@@ -74,18 +74,19 @@
xmlDocument = LoadDocument(xmlFilePath);
- CalculationConfigurationSchemaDefinition matchingSchemaDefinition = GetMatchingSchemaDefinition(schemaDefinitions);
- if (matchingSchemaDefinition == null)
- {
- return;
- }
+ int versionNumber = GetVersionNumber();
- ValidateToSchema(xmlDocument, xmlFilePath, matchingSchemaDefinition.MainSchemaDefinition, matchingSchemaDefinition.NestedSchemaDefinitions);
+ // Check of versienummer bestaat in lijst
+ // if (!schemaDefinitions.Any(schemaDefinition => schemaDefinition.VersionNumber == versionNumber))
+ // {
+ // throw new Exception();
+ // }
+ ValidateToSchema(xmlDocument, xmlFilePath, schemaDefinitions.ElementAt(versionNumber).MainSchemaDefinition, schemaDefinitions.ElementAt(versionNumber).NestedSchemaDefinitions);
+
ValidateNotEmpty(xmlDocument, xmlFilePath);
- // Migrate with XSLT
- // ...
+ //XmlMigrator.Migrate(xmlDocument, schemaDefinitions, );
}
///
@@ -104,27 +105,24 @@
/// A parsed .
protected abstract TReadCalculation ParseCalculationElement(XElement calculationElement);
- private CalculationConfigurationSchemaDefinition GetMatchingSchemaDefinition(IEnumerable schemaDefinitions)
+ private int GetVersionNumber()
{
- for (var i = 0; i < schemaDefinitions.Count(); i++)
+ int versionNumber;
+ try
{
- try
- {
- CalculationConfigurationSchemaDefinition current = schemaDefinitions.ElementAt(i);
+ var combinedXmlSchemaDefinition = new CombinedXmlSchemaDefinition(Resources.VersieSchema, new Dictionary());
- var combinedXmlSchemaDefinition = new CombinedXmlSchemaDefinition(current.VersionSchemaDefinition, new Dictionary());
+ combinedXmlSchemaDefinition.Validate(xmlDocument);
- combinedXmlSchemaDefinition.Validate(xmlDocument);
-
- return current;
- }
- catch (XmlSchemaValidationException)
- {
- // Do nothing and continue search
- }
+ var versionNumberString = xmlDocument.Elements("configuration").Attributes("versie").ToString();
+ versionNumber = int.Parse(versionNumberString);
}
+ catch (XmlSchemaValidationException)
+ {
+ versionNumber = 0;
+ }
- return null;
+ return versionNumber;
}
///
Index: Riskeer/Common/src/Riskeer.Common.IO/Configurations/Import/CalculationConfigurationSchemaDefinition.cs
===================================================================
diff -u -r083a5a0ffd2030fe3d8d5ca5e1c78a06d7cff9b4 -rc569d5705bffb682cde45f5f18077c9f95aeb736
--- Riskeer/Common/src/Riskeer.Common.IO/Configurations/Import/CalculationConfigurationSchemaDefinition.cs (.../CalculationConfigurationSchemaDefinition.cs) (revision 083a5a0ffd2030fe3d8d5ca5e1c78a06d7cff9b4)
+++ Riskeer/Common/src/Riskeer.Common.IO/Configurations/Import/CalculationConfigurationSchemaDefinition.cs (.../CalculationConfigurationSchemaDefinition.cs) (revision c569d5705bffb682cde45f5f18077c9f95aeb736)
@@ -28,48 +28,32 @@
///
public class CalculationConfigurationSchemaDefinition
{
- private string mainSchemaDefinition;
- private IDictionary nestedSchemaDefinitions;
- private string versionSchemaDefinition;
-
///
/// Creates a new instance of .
///
/// The main schema definition xsd.
/// The nested schema definition xsd.
- /// The version schema definition xsd.
- public CalculationConfigurationSchemaDefinition(string mainSchemaDefinition, IDictionary nestedSchemaDefinitions, string versionSchemaDefinition = null)
+ /// The version number of the xml that is read.
+ public CalculationConfigurationSchemaDefinition(string mainSchemaDefinition, IDictionary nestedSchemaDefinitions, int versionNumber = 0)
{
MainSchemaDefinition = mainSchemaDefinition;
NestedSchemaDefinitions = nestedSchemaDefinitions;
- VersionSchemaDefinition = versionSchemaDefinition;
+ VersionNumber = versionNumber;
}
///
/// Gets or sets the version schema definition.
///
- public string VersionSchemaDefinition
- {
- get => versionSchemaDefinition;
- private set => versionSchemaDefinition = value;
- }
+ public int VersionNumber { get; private set; }
///
/// Gets or sets the main schema definition.
///
- public string MainSchemaDefinition
- {
- get => mainSchemaDefinition;
- private set => mainSchemaDefinition = value;
- }
+ public string MainSchemaDefinition { get; private set; }
///
/// Gets or sets the nested schema definitions.
///
- public IDictionary NestedSchemaDefinitions
- {
- get => nestedSchemaDefinitions;
- private set => nestedSchemaDefinitions = value;
- }
+ public IDictionary NestedSchemaDefinitions { get; private set; }
}
-}
+}
\ No newline at end of file
Index: Riskeer/Common/src/Riskeer.Common.IO/Configurations/Import/XmlMigrator.cs
===================================================================
diff -u
--- Riskeer/Common/src/Riskeer.Common.IO/Configurations/Import/XmlMigrator.cs (revision 0)
+++ Riskeer/Common/src/Riskeer.Common.IO/Configurations/Import/XmlMigrator.cs (revision c569d5705bffb682cde45f5f18077c9f95aeb736)
@@ -0,0 +1,84 @@
+// Copyright (C) Stichting Deltares 2019. All rights reserved.
+//
+// This file is part of Riskeer.
+//
+// Riskeer is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+using System.IO;
+using System.Xml;
+using System.Xml.Linq;
+using System.Xml.Xsl;
+
+namespace Riskeer.Common.IO.Configurations.Import
+{
+ public static class XmlMigrator
+ {
+ private const string versionZeroToVersionOneXsl =
+ "" +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " 1" +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ "";
+
+ // public static void Migrate(XDocument xmlDocument, string )
+ // {
+ // using (var stringReader = new StringReader(startingConfiguration))
+ // {
+ // using (var xmlReader = XmlReader.Create(stringReader))
+ // {
+ // using (var stringWriter = new StringWriter())
+ // {
+ // XslCompiledTransform transformer = CreateTransformer(migrationXsl);
+ //
+ // transformer.Transform(xmlReader, null, stringWriter);
+ // }
+ // }
+ // }
+ // }
+
+ private static XslCompiledTransform CreateTransformer(string xsl)
+ {
+ var xslCompiledTransform = new XslCompiledTransform();
+
+ using (var stringReader = new StringReader(xsl))
+ {
+ using (var xmlReader = XmlReader.Create(stringReader))
+ {
+ xslCompiledTransform.Load(xmlReader);
+ }
+ }
+
+ return xslCompiledTransform;
+ }
+ }
+}
\ No newline at end of file
Index: Riskeer/Common/src/Riskeer.Common.IO/Properties/Resources.Designer.cs
===================================================================
diff -u -r106eeb3a0608bd85eb1fcc8fff72256fd9c3ac5f -rc569d5705bffb682cde45f5f18077c9f95aeb736
--- Riskeer/Common/src/Riskeer.Common.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 106eeb3a0608bd85eb1fcc8fff72256fd9c3ac5f)
+++ Riskeer/Common/src/Riskeer.Common.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision c569d5705bffb682cde45f5f18077c9f95aeb736)
@@ -1,4 +1,4 @@
-// Copyright (C) Stichting Deltares 2019. All rights reserved.
+// Copyright (C) Stichting Deltares 2019. All rights reserved.
//
// This file is part of Riskeer.
//
@@ -40,7 +40,7 @@
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
public class Resources {
@@ -2605,6 +2605,27 @@
///but WITHOUT ANY WARRANTY; without even the implied warranty of
///ME [rest of string was truncated]";.
///
+ public static string VersieSchema {
+ get {
+ return ResourceManager.GetString("VersieSchema", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to <?xml version="1.0" encoding="utf-8"?><!--
+ ///Copyright (C) Stichting Deltares 2019. All rights reserved.
+ ///
+ ///This file is part of Riskeer.
+ ///
+ ///Riskeer is free software: you can redistribute it and/or modify
+ ///it under the terms of the GNU General Public License as published by
+ ///the Free Software Foundation, either version 3 of the License, or
+ ///(at your option) any later version.
+ ///
+ ///This program is distributed in the hope that it will be useful,
+ ///but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ///ME [rest of string was truncated]";.
+ ///
public static string VoorlandProfielSchema {
get {
return ResourceManager.GetString("VoorlandProfielSchema", resourceCulture);
Index: Riskeer/Common/src/Riskeer.Common.IO/Properties/Resources.resx
===================================================================
diff -u -r21a7128b30ab9723fc7aef0e2d62855267ac8214 -rc569d5705bffb682cde45f5f18077c9f95aeb736
--- Riskeer/Common/src/Riskeer.Common.IO/Properties/Resources.resx (.../Resources.resx) (revision 21a7128b30ab9723fc7aef0e2d62855267ac8214)
+++ Riskeer/Common/src/Riskeer.Common.IO/Properties/Resources.resx (.../Resources.resx) (revision c569d5705bffb682cde45f5f18077c9f95aeb736)
@@ -876,4 +876,7 @@
Profielgegevens definiëren geen geldige dijkgeometrie. De dijkgeometrie moet bestaan uit tenminste 2 punten. Bestand '{0}' wordt overgeslagen.
+
+ ..\Resources\VersieSchema.xsd;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8
+
\ No newline at end of file
Index: Riskeer/Common/test/Riskeer.Common.IO.Test/Configurations/Import/CalculationConfigurationReaderTest.cs
===================================================================
diff -u -r083a5a0ffd2030fe3d8d5ca5e1c78a06d7cff9b4 -rc569d5705bffb682cde45f5f18077c9f95aeb736
--- Riskeer/Common/test/Riskeer.Common.IO.Test/Configurations/Import/CalculationConfigurationReaderTest.cs (.../CalculationConfigurationReaderTest.cs) (revision 083a5a0ffd2030fe3d8d5ca5e1c78a06d7cff9b4)
+++ Riskeer/Common/test/Riskeer.Common.IO.Test/Configurations/Import/CalculationConfigurationReaderTest.cs (.../CalculationConfigurationReaderTest.cs) (revision c569d5705bffb682cde45f5f18077c9f95aeb736)
@@ -85,11 +85,11 @@
public void Constructor_NoFilePath_ThrowArgumentException(string invalidFilePath)
{
// Call
- TestDelegate call = () => new CalculationConfigurationReader(invalidFilePath, validMainSchemaDefinition, new Dictionary());
+ void Call() => new CalculationConfigurationReader(invalidFilePath, validMainSchemaDefinition, new Dictionary());
// Assert
string expectedMessage = $"Fout bij het lezen van bestand '{invalidFilePath}': bestandspad mag niet leeg of ongedefinieerd zijn.";
- TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage);
+ TestHelper.AssertThrowsArgumentExceptionAndTestMessage(Call, expectedMessage);
}
[Test]
@@ -101,12 +101,12 @@
string invalidFilePath = validFilePath.Replace("Config", invalidPathChars[3].ToString());
// Call
- TestDelegate call = () => new CalculationConfigurationReader(invalidFilePath, validMainSchemaDefinition, new Dictionary());
+ void Call() => new CalculationConfigurationReader(invalidFilePath, validMainSchemaDefinition, new Dictionary());
// Assert
string expectedMessage = $"Fout bij het lezen van bestand '{invalidFilePath}': "
+ "er zitten ongeldige tekens in het bestandspad. Alle tekens in het bestandspad moeten geldig zijn.";
- TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage);
+ TestHelper.AssertThrowsArgumentExceptionAndTestMessage(Call, expectedMessage);
}
[Test]
@@ -116,11 +116,11 @@
string invalidFilePath = Path.Combine(testDirectoryPath, Path.DirectorySeparatorChar.ToString());
// Call
- TestDelegate call = () => new CalculationConfigurationReader(invalidFilePath, validMainSchemaDefinition, new Dictionary());
+ void Call() => new CalculationConfigurationReader(invalidFilePath, validMainSchemaDefinition, new Dictionary());
// Assert
string expectedMessage = $"Fout bij het lezen van bestand '{invalidFilePath}': bestandspad mag niet verwijzen naar een lege bestandsnaam.";
- TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage);
+ TestHelper.AssertThrowsArgumentExceptionAndTestMessage(Call, expectedMessage);
}
[Test]
@@ -130,11 +130,11 @@
string invalidFilePath = Path.Combine(testDirectoryPath, "notExisting.xml");
// Call
- TestDelegate call = () => new CalculationConfigurationReader(invalidFilePath, validMainSchemaDefinition, new Dictionary());
+ void Call() => new CalculationConfigurationReader(invalidFilePath, validMainSchemaDefinition, new Dictionary());
// Assert
string expectedMessage = $"Fout bij het lezen van bestand '{invalidFilePath}': het bestand bestaat niet.";
- string message = Assert.Throws(call).Message;
+ string message = Assert.Throws(Call).Message;
Assert.AreEqual(expectedMessage, message);
}
@@ -146,10 +146,10 @@
string filePath = Path.Combine(testDirectoryPath, fileName);
// Call
- TestDelegate call = () => new CalculationConfigurationReader(filePath, validMainSchemaDefinition, new Dictionary());
+ void Call() => new CalculationConfigurationReader(filePath, validMainSchemaDefinition, new Dictionary());
// Assert
- var exception = Assert.Throws(call);
+ var exception = Assert.Throws(Call);
string expectedMessage = $"Fout bij het lezen van bestand '{filePath}': " +
"het XML-document dat de configuratie voor de berekeningen beschrijft is niet geldig. " +
$"De validatie geeft de volgende melding: {expectedInnerMessage}";
@@ -169,11 +169,11 @@
fileDisposeHelper.LockFiles();
// Call
- TestDelegate call = () => new CalculationConfigurationReader(path, validMainSchemaDefinition, new Dictionary());
+ void Call() => new CalculationConfigurationReader(path, validMainSchemaDefinition, new Dictionary());
// Assert
string expectedMessage = $"Fout bij het lezen van bestand '{path}': het bestand kon niet worden geopend. Mogelijk is het bestand corrupt of in gebruik door een andere applicatie.";
- var exception = Assert.Throws(call);
+ var exception = Assert.Throws(Call);
Assert.AreEqual(expectedMessage, exception.Message);
Assert.IsInstanceOf(exception.InnerException);
}
@@ -187,10 +187,10 @@
string xsdPath = Path.Combine(testDirectoryPath, "mainSchemaDefinitionNotReferencingDefaultSchema.xsd");
// Call
- TestDelegate call = () => new CalculationConfigurationReader(filePath, File.ReadAllText(xsdPath), new Dictionary());
+ void Call() => new CalculationConfigurationReader(filePath, File.ReadAllText(xsdPath), new Dictionary());
// Assert
- var exception = Assert.Throws(call);
+ var exception = Assert.Throws(Call);
Assert.AreEqual("'mainSchemaDefinition' does not reference the default schema 'ConfiguratieSchema.xsd'.", exception.Message);
}
@@ -202,10 +202,10 @@
string filePath = Path.Combine(testDirectoryPath, fileName);
// Call
- TestDelegate call = () => new CalculationConfigurationReader(filePath, validMainSchemaDefinition, new Dictionary());
+ void Call() => new CalculationConfigurationReader(filePath, validMainSchemaDefinition, new Dictionary());
// Assert
- var exception = Assert.Throws(call);
+ var exception = Assert.Throws(Call);
Assert.IsInstanceOf(exception.InnerException);
Assert.IsTrue(exception.InnerException?.Message.Contains(expectedParsingMessage));
}
@@ -217,13 +217,13 @@
string filePath = Path.Combine(testDirectoryPath, "invalidFolderNoName.xml");
// Call
- TestDelegate call = () => new CalculationConfigurationReader(filePath, validMainSchemaDefinition, new Dictionary());
+ void Call() => new CalculationConfigurationReader(filePath, validMainSchemaDefinition, new Dictionary());
// Assert
string expectedMessage = $"Fout bij het lezen van bestand '{filePath}': het XML-document dat de configuratie" +
" voor de berekeningen beschrijft is niet geldig. De validatie geeft de volgende melding" +
" op regel 3, positie 4: The required attribute \'naam\' is missing.";
- var exception = Assert.Throws(call);
+ var exception = Assert.Throws(Call);
Assert.AreEqual(expectedMessage, exception.Message);
}
@@ -234,13 +234,13 @@
string filePath = Path.Combine(testDirectoryPath, "emptyConfiguration.xml");
// Call
- TestDelegate call = () => new CalculationConfigurationReader(filePath, validMainSchemaDefinition, new Dictionary());
+ void Call() => new CalculationConfigurationReader(filePath, validMainSchemaDefinition, new Dictionary());
// Assert
string expectedMessage = $"Fout bij het lezen van bestand '{filePath}': " +
"het XML-document dat de configuratie voor de berekeningen beschrijft, " +
"moet mappen en/of berekeningen bevatten.";
- var exception = Assert.Throws(call);
+ var exception = Assert.Throws(Call);
Assert.AreEqual(expectedMessage, exception.Message);
}
@@ -251,10 +251,10 @@
string filePath = Path.Combine(testDirectoryPath, "validConfiguration.xml");
// Call
- TestDelegate call = () => new CalculationConfigurationReader(filePath, validMainSchemaDefinition, new Dictionary());
+ void Call() => new CalculationConfigurationReader(filePath, validMainSchemaDefinition, new Dictionary());
// Assert
- Assert.DoesNotThrow(call);
+ Assert.DoesNotThrow(Call);
}
[Test]
@@ -350,7 +350,8 @@
IDictionary nestedSchemaDefinitions)
: base(xmlFilePath, new[]
{
- new CalculationConfigurationSchemaDefinition(mainSchemaDefinition, nestedSchemaDefinitions)
+ new CalculationConfigurationSchemaDefinition(
+ mainSchemaDefinition, nestedSchemaDefinitions)
}) {}
protected override ReadCalculation ParseCalculationElement(XElement calculationElement)