Index: DamEngine/trunk/src/Deltares.DamEngine.Interface/Properties/Resources.Designer.cs
===================================================================
diff -u -r1553 -r2102
--- DamEngine/trunk/src/Deltares.DamEngine.Interface/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 1553)
+++ DamEngine/trunk/src/Deltares.DamEngine.Interface/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 2102)
@@ -97,6 +97,15 @@
}
///
+ /// Looks up a localized string similar to Location.
+ ///
+ internal static string Location {
+ get {
+ return ResourceManager.GetString("Location", resourceCulture);
+ }
+ }
+
+ ///
/// Looks up a localized string similar to Model accepted.
///
internal static string ModelAccepted {
@@ -241,6 +250,51 @@
}
///
+ /// Looks up a localized string similar to {0} has an invalid name {1}.
+ ///
+ internal static string NoValidId {
+ get {
+ return ResourceManager.GetString("NoValidId", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Segment.
+ ///
+ internal static string Segment {
+ get {
+ return ResourceManager.GetString("Segment", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Materiaal.
+ ///
+ internal static string Soil {
+ get {
+ return ResourceManager.GetString("Soil", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Soilporfile 1D.
+ ///
+ internal static string SoilProfile1D {
+ get {
+ return ResourceManager.GetString("SoilProfile1D", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Soilprofile 2D.
+ ///
+ internal static string SoilProfile2D {
+ get {
+ return ResourceManager.GetString("SoilProfile2D", resourceCulture);
+ }
+ }
+
+ ///
/// Looks up a localized string similar to Start calculation.
///
internal static string StartCalculation {
@@ -257,5 +311,14 @@
return ResourceManager.GetString("StartValidation", resourceCulture);
}
}
+
+ ///
+ /// Looks up a localized string similar to Surfaceline.
+ ///
+ internal static string SurfaceLine {
+ get {
+ return ResourceManager.GetString("SurfaceLine", resourceCulture);
+ }
+ }
}
}
Index: DamEngine/trunk/src/Deltares.DamEngine.Interface/Properties/Resources.resx
===================================================================
diff -u -r1553 -r2102
--- DamEngine/trunk/src/Deltares.DamEngine.Interface/Properties/Resources.resx (.../Resources.resx) (revision 1553)
+++ DamEngine/trunk/src/Deltares.DamEngine.Interface/Properties/Resources.resx (.../Resources.resx) (revision 2102)
@@ -129,6 +129,9 @@
Error: empty input string
+
+ Location
+
Model accepted
@@ -177,10 +180,28 @@
No surfacelines defined in this project
+
+ {0} has an invalid name {1}
+
+
+ Segment
+
+
+ Materiaal
+
+
+ Soilporfile 1D
+
+
+ Soilprofile 2D
+
Start calculation
Start validation
+
+ Surfaceline
+
\ No newline at end of file
Index: DamEngine/trunk/src/Deltares.DamEngine.Io/Deltares.DamEngine.Io.csproj
===================================================================
diff -u -r2101 -r2102
--- DamEngine/trunk/src/Deltares.DamEngine.Io/Deltares.DamEngine.Io.csproj (.../Deltares.DamEngine.Io.csproj) (revision 2101)
+++ DamEngine/trunk/src/Deltares.DamEngine.Io/Deltares.DamEngine.Io.csproj (.../Deltares.DamEngine.Io.csproj) (revision 2102)
@@ -40,6 +40,7 @@
+
Index: DamEngine/trunk/src/Deltares.DamEngine.Io/IdValidatorException.cs
===================================================================
diff -u
--- DamEngine/trunk/src/Deltares.DamEngine.Io/IdValidatorException.cs (revision 0)
+++ DamEngine/trunk/src/Deltares.DamEngine.Io/IdValidatorException.cs (revision 2102)
@@ -0,0 +1,36 @@
+// Copyright (C) Stichting Deltares 2019. All rights reserved.
+//
+// This file is part of the Dam Engine.
+//
+// The Dam Engine is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero 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 Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero 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;
+namespace Deltares.DamEngine.Io
+{
+ ///
+ /// Exception for IdValidator
+ ///
+ ///
+ public class IdValidatorException : Exception
+ {
+ public IdValidatorException(string message) : base(message)
+ {
+ }
+ }
+}
+
Index: DamEngine/trunk/src/Deltares.DamEngine.Interface/FillXmlInputFromDam.cs
===================================================================
diff -u -r2002 -r2102
--- DamEngine/trunk/src/Deltares.DamEngine.Interface/FillXmlInputFromDam.cs (.../FillXmlInputFromDam.cs) (revision 2002)
+++ DamEngine/trunk/src/Deltares.DamEngine.Interface/FillXmlInputFromDam.cs (.../FillXmlInputFromDam.cs) (revision 2102)
@@ -28,6 +28,7 @@
using Deltares.DamEngine.Data.General.TimeSeries;
using Deltares.DamEngine.Data.Geotechnics;
using Deltares.DamEngine.Interface.Properties;
+using Deltares.DamEngine.Io;
using Deltares.DamEngine.Io.XmlInput;
using Input = Deltares.DamEngine.Io.XmlInput.Input;
using Location = Deltares.DamEngine.Data.General.Location;
@@ -357,6 +358,51 @@
{
throw new NullReferenceException(Resources.NoSoilProfiles1DInProject);
}
+
+ // Check for invalid Id names
+ foreach (var location in damProjectData.Dike.Locations)
+ {
+ if (!IdValidator.IsCorrectName(location.Name))
+ {
+ throw new IdValidatorException(string.Format(Resources.NoValidId, Resources.Location, location.Name));
+ }
+ }
+ foreach (var segment in damProjectData.Segments)
+ {
+ if (!IdValidator.IsCorrectName(segment.Name))
+ {
+ throw new IdValidatorException(string.Format(Resources.NoValidId, Resources.Location, segment.Name));
+ }
+ }
+ foreach (var surfaceLine2 in damProjectData.Dike.SurfaceLines2)
+ {
+ if (!IdValidator.IsCorrectName(surfaceLine2.Name))
+ {
+ throw new IdValidatorException(string.Format(Resources.NoValidId, Resources.SurfaceLine, surfaceLine2.Name));
+ }
+ }
+ foreach (var soilProfile in damProjectData.Dike.SoilProfiles)
+ {
+ if (!IdValidator.IsCorrectName(soilProfile.Name))
+ {
+ throw new IdValidatorException(string.Format(Resources.NoValidId, Resources.SoilProfile1D, soilProfile.Name));
+ }
+ }
+ foreach (var soilProfile2D in damProjectData.Dike.SoilProfiles2D)
+ {
+ if (!IdValidator.IsCorrectName(soilProfile2D.Name))
+ {
+ throw new IdValidatorException(string.Format(Resources.NoValidId, Resources.SoilProfile2D, soilProfile2D.Name));
+ }
+ }
+ foreach (var soil in damProjectData.Dike.SoilList.Soils)
+ {
+ if (!IdValidator.IsCorrectName(soil.Name))
+ {
+ throw new IdValidatorException(string.Format(Resources.NoValidId, Resources.Soil, soil.Name));
+ }
+ }
+
}
private static void TransferSoils(List soils, Soil[] inputSoils)
Index: DamEngine/trunk/src/Deltares.DamEngine.Interface/Properties/Resources.nl-NL.resx
===================================================================
diff -u -r1553 -r2102
--- DamEngine/trunk/src/Deltares.DamEngine.Interface/Properties/Resources.nl-NL.resx (.../Resources.nl-NL.resx) (revision 1553)
+++ DamEngine/trunk/src/Deltares.DamEngine.Interface/Properties/Resources.nl-NL.resx (.../Resources.nl-NL.resx) (revision 2102)
@@ -129,6 +129,9 @@
Fout: lege input string
+
+ Lokatie
+
Model geaccepteerd
@@ -177,10 +180,28 @@
Geen dijkprofielen gedefinieerd in dit project
+
+ {0} heeft een ongeldige naam {1}
+
+
+ Segment
+
+
+ Materiaal
+
+
+ 1D ondergrondprofiel
+
+
+ 2D ondergrondprofiel
+
Start berekening
Start validatie
+
+ Hoogtegeometrie
+
\ No newline at end of file
Index: DamEngine/trunk/src/Deltares.DamEngine.Interface.Tests/FillDamFromXmlInputTests.cs
===================================================================
diff -u -r2101 -r2102
--- DamEngine/trunk/src/Deltares.DamEngine.Interface.Tests/FillDamFromXmlInputTests.cs (.../FillDamFromXmlInputTests.cs) (revision 2101)
+++ DamEngine/trunk/src/Deltares.DamEngine.Interface.Tests/FillDamFromXmlInputTests.cs (.../FillDamFromXmlInputTests.cs) (revision 2102)
@@ -82,9 +82,8 @@
}
[Test]
- [TestCase("segment_12_2_1D1")] // Between "segment_12" and "_2_1D1" there are 2 illegal characters (1F hex)
- // This should be a better exception type and exception message
- [ExpectedException(typeof(System.InvalidOperationException))]
+ [TestCase("location_12_2_1D1")] // Between "location_12" and "_2_1D1" there are 2 illegal characters (1F hex)
+ [ExpectedException(typeof(IdValidatorException), ExpectedMessage = "Location has an invalid name location_12_2_1D1")]
public void GivenDataSetContainingIllegalCharactersWhenWritingXmlThenRaiseExceptionWithClearMessage(string id)
{
// Given DataSet Containing Illegal Characters
Index: DamEngine/trunk/src/Deltares.DamEngine.Io.Tests/IdValidatorTests.cs
===================================================================
diff -u -r2101 -r2102
--- DamEngine/trunk/src/Deltares.DamEngine.Io.Tests/IdValidatorTests.cs (.../IdValidatorTests.cs) (revision 2101)
+++ DamEngine/trunk/src/Deltares.DamEngine.Io.Tests/IdValidatorTests.cs (.../IdValidatorTests.cs) (revision 2102)
@@ -55,16 +55,16 @@
Assert.IsTrue(isOk);
}
- [TestCase("segment_12_2_1D1")] // Between "segment_12" and "_2_1D1" there are 2 illegal characters (1F hex)
- [TestCase("De laatste letter is foutÀ")]
- [TestCase("Een letter ¡ middenin is fout")]
- [TestCase("ÀDe eerste letter is fout")]
+ [TestCase("location_12_2_1D1")] // Between "location_12" and "_2_1D1" there are 2 illegal characters (1F hex)
+ [TestCase("The last character is incorrectÀ")]
+ [TestCase("A character ¡ int he middle is incorrect")]
+ [TestCase("ÀThe first character is incorrect")]
public void GivenInCorrectIdWhenValidatingThenFails(string id)
{
- // Given Correct Id When Validating
+ // Given Inorrect Id When Validating
bool isOk = IdValidator.IsCorrectName(id);
- // Then Succeeds
+ // Then Fails
Assert.IsFalse(isOk);
}
}