Index: dam failuremechanisms/damMacroStability/trunk/src/Tests/Deltares.DamMacroStability.CalculatorTests/DGeoStabilityResultReaderTests.cs
===================================================================
diff -u -r422 -r423
--- dam failuremechanisms/damMacroStability/trunk/src/Tests/Deltares.DamMacroStability.CalculatorTests/DGeoStabilityResultReaderTests.cs (.../DGeoStabilityResultReaderTests.cs) (revision 422)
+++ dam failuremechanisms/damMacroStability/trunk/src/Tests/Deltares.DamMacroStability.CalculatorTests/DGeoStabilityResultReaderTests.cs (.../DGeoStabilityResultReaderTests.cs) (revision 423)
@@ -1,9 +1,5 @@
using System;
-using System.Collections.Generic;
using System.IO;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
using Deltares.DamMacroStability.Calculator;
using NUnit.Framework;
@@ -22,7 +18,7 @@
// expected results are based on test in 'https://repos.deltares.nl/repos/dam/dam classic' revision 230
string expectedFileName = Path.Combine(TestFolder, TestFile);
var result = DGeoStabilityResultReader.ExtractStabilityResults(expectedFileName);
- Assert.GreaterOrEqual(1.276, result.zone1.SafetyFactor);
+ Assert.GreaterOrEqual(1.276, result.Zone1.SafetyFactor);
}
[Test]
@@ -57,11 +53,11 @@
@" 1 : Bishop" + Environment.NewLine;
var result = DGeoStabilityResultReader.GetDGeoStabilityResults(contents);
- Assert.AreEqual(1.276, result.zone1.SafetyFactor, 0.001);
+ Assert.AreEqual(1.276, result.Zone1.SafetyFactor, 0.001);
}
[Test]
- public void CanParseStringContentWhenSafetyFactorIsInOtherColumn()
+ public void TestCanParseStringContentWhenSafetyFactorIsInOtherColumn()
{
// expected results are based on test in 'https://repos.deltares.nl/repos/dam/dam classic' revision 230
var contents = @" 28.237 28.850 23.786 2.324 " + Environment.NewLine +
@@ -92,22 +88,22 @@
@" 1 : Bishop" + Environment.NewLine;
var result = DGeoStabilityResultReader.GetDGeoStabilityResults(contents);
- Assert.AreEqual(21.971, result.zone1.SafetyFactor, 0.001);
+ Assert.AreEqual(21.971, result.Zone1.SafetyFactor, 0.001);
}
[Test]
- public void CanParseFileContentsStability()
+ public void TestCanParseFileContentsStability()
{
// expected results are based on test in 'https://repos.deltares.nl/repos/dam/dam classic' revision 230
string fileName = Path.Combine(TestFolder, TestFile);
var contents = DGeoStabilityResultReader.GetFileContents(fileName);
var result = DGeoStabilityResultReader.GetDGeoStabilityResults(contents);
- Assert.AreEqual(1.276, result.zone1.SafetyFactor, 0.001);
- Assert.AreEqual(26.091, result.zone1.CircleSurfacePointRightXCoordinate, 0.001);
+ Assert.AreEqual(1.276, result.Zone1.SafetyFactor, 0.001);
+ Assert.AreEqual(26.091, result.Zone1.CircleSurfacePointRightXCoordinate, 0.001);
}
[Test]
- public void ValidateIfFileContentsHasZonePlotEnabled()
+ public void TestValidateIfFileContentsHasZonePlotEnabled()
{
// expected results are based on test in 'https://repos.deltares.nl/repos/dam/dam classic' revision 230
string fileName = Path.Combine(TestFolder, TestFileWithZonePlot);
@@ -117,29 +113,9 @@
}
[Test]
- public void FileContentsHasZonePlotZone1a()
+ public void TestFileContentsHasZonePlotDisabled()
{
// expected results are based on test in 'https://repos.deltares.nl/repos/dam/dam classic' revision 230
- string fileName = Path.Combine(TestFolder, TestFileWithZonePlot);
- var contents = DGeoStabilityResultReader.GetFileContents(fileName);
- DGeoStabilityResultReader.DGeoStabilityResultsSingleZone? actualStabilityZone1a =
- DGeoStabilityResultReader.GetZoneStability1a(contents);
- DGeoStabilityResultReader.DGeoStabilityResultsSingleZone expectedStabilityZone1a =
- new DGeoStabilityResultReader.DGeoStabilityResultsSingleZone();
- expectedStabilityZone1a.SafetyFactor = 1.104;
- expectedStabilityZone1a.CircleSurfacePointLeftXCoordinate = 35.401;
- expectedStabilityZone1a.CircleSurfacePointRightXCoordinate = 54.764;
-
- Assert.IsNotNull(actualStabilityZone1a);
- Assert.AreEqual(expectedStabilityZone1a.SafetyFactor, actualStabilityZone1a.Value.SafetyFactor, 0.001);
- Assert.AreEqual(expectedStabilityZone1a.CircleSurfacePointRightXCoordinate,
- actualStabilityZone1a.Value.CircleSurfacePointRightXCoordinate, 0.001);
- }
-
- [Test]
- public void FileContentsHasZonePlotDisabled()
- {
- // expected results are based on test in 'https://repos.deltares.nl/repos/dam/dam classic' revision 230
string zonePlotOff = @"[MODEL]" + Environment.NewLine +
@" 1 : Bishop" + Environment.NewLine +
@" 1 : C phi" + Environment.NewLine +
@@ -158,59 +134,9 @@
}
[Test]
- public void FileContentsHasZonePlotZone1b()
+ public void TestFileContentsHasZonePlotZone1bAndZone2b()
{
// expected results are based on test in 'https://repos.deltares.nl/repos/dam/dam classic' revision 230
- string testWithZonePlot1b = @"[Dump]" + Environment.NewLine +
- @"[Dump Header]" + Environment.NewLine +
- @"[Column Indication]" + Environment.NewLine +
- @"Stability factor" + Environment.NewLine +
- @"Number of slices" + Environment.NewLine +
- @"X-Centrepoint" + Environment.NewLine +
- @"Y-Centrepoint" + Environment.NewLine +
- @"Radius" + Environment.NewLine +
- @"X coordinate left surface" + Environment.NewLine +
- @"X coordinate right surface" + Environment.NewLine +
- @"Zone number" + Environment.NewLine +
- @"Dump name" + Environment.NewLine +
- @"[End of Column Indication]" + Environment.NewLine +
- @"[Data]" + Environment.NewLine +
- @" 1.234 35 46.429 7.714 11.357 17.810 24.310 2 Design level" + Environment.NewLine +
- @"[End of Data]" + Environment.NewLine +
- @"[End Of Dump Header]" + Environment.NewLine +
- @"[MODEL]" + Environment.NewLine +
- @" 1 : Bishop" + Environment.NewLine;
-
- DGeoStabilityResultReader.DGeoStabilityResultsSingleZone? actualStabilityZone1b =
- DGeoStabilityResultReader.GetZoneStability1b(testWithZonePlot1b);
- DGeoStabilityResultReader.DGeoStabilityResultsSingleZone expectedStabilityZone1b =
- new DGeoStabilityResultReader.DGeoStabilityResultsSingleZone();
- expectedStabilityZone1b.SafetyFactor = 1.234;
- expectedStabilityZone1b.CircleSurfacePointLeftXCoordinate = 17.810;
- expectedStabilityZone1b.CircleSurfacePointRightXCoordinate = 24.310;
-
- Assert.IsNotNull(actualStabilityZone1b);
- Assert.AreEqual(expectedStabilityZone1b.SafetyFactor, actualStabilityZone1b.Value.SafetyFactor, 0.001);
- Assert.AreEqual(expectedStabilityZone1b.CircleSurfacePointRightXCoordinate,
- actualStabilityZone1b.Value.CircleSurfacePointRightXCoordinate, 0.001);
- }
-
-
- [Test]
- public void FileContentsHasNoZonePlotZone1b()
- {
- // expected results are based on test in 'https://repos.deltares.nl/repos/dam/dam classic' revision 230
- DGeoStabilityResultReader.DGeoStabilityResultsSingleZone? actualStabilityZone1b =
- DGeoStabilityResultReader.GetZoneStability1b(TestFileWithZonePlot);
- DGeoStabilityResultReader.DGeoStabilityResultsSingleZone? expectedStabilityZone1b = null;
-
- Assert.AreEqual(actualStabilityZone1b, expectedStabilityZone1b);
- }
-
- [Test]
- public void FileContentsHasZonePlotZone1bAndZone2b()
- {
- // expected results are based on test in 'https://repos.deltares.nl/repos/dam/dam classic' revision 230
string testWithZonePlot1bAnd2b = @"[MODEL]" + Environment.NewLine +
@" 1 : Bishop" + Environment.NewLine +
@" 1 : C phi" + Environment.NewLine +
@@ -270,117 +196,51 @@
expectedStabilityZone2.CircleSurfacePointRightXCoordinate = 26.310;
Assert.IsNotNull(actualMStabResults);
- Assert.AreEqual(expectedStabilityZone1.SafetyFactor, actualMStabResults.zone1.SafetyFactor, 0.001);
+ Assert.AreEqual(expectedStabilityZone1.SafetyFactor, actualMStabResults.Zone1.SafetyFactor, 0.001);
Assert.AreEqual(expectedStabilityZone1.CircleSurfacePointRightXCoordinate,
- actualMStabResults.zone1.CircleSurfacePointRightXCoordinate, 0.001);
- Assert.IsNotNull(actualMStabResults.zone2);
- Assert.AreEqual(expectedStabilityZone2.SafetyFactor, actualMStabResults.zone2.Value.SafetyFactor, 0.001);
+ actualMStabResults.Zone1.CircleSurfacePointRightXCoordinate, 0.001);
+ Assert.IsNotNull(actualMStabResults.Zone2);
+ Assert.AreEqual(expectedStabilityZone2.SafetyFactor, actualMStabResults.Zone2.Value.SafetyFactor, 0.001);
Assert.AreEqual(expectedStabilityZone2.CircleSurfacePointRightXCoordinate,
- actualMStabResults.zone2.Value.CircleSurfacePointRightXCoordinate, 0.001);
+ actualMStabResults.Zone2.Value.CircleSurfacePointRightXCoordinate, 0.001);
}
[Test]
- public void CanParseFileHasStabilityFactorZone()
+ public void TestCanParseFileHasStabilityFactorZone()
{
// expected results are based on test in 'https://repos.deltares.nl/repos/dam/dam classic' revision 230
string fileName = Path.Combine(TestFolder, TestFileWithZonePlot);
var contents = DGeoStabilityResultReader.GetFileContents(fileName);
var result = DGeoStabilityResultReader.GetDGeoStabilityResults(contents);
- Assert.AreEqual(1.104, result.zone1.SafetyFactor, 0.001);
+ Assert.AreEqual(1.104, result.Zone1.SafetyFactor, 0.001);
}
- [Test]
- public void CanParseStringContentForPositiveBeta()
- {
- // expected results are based on test in 'https://repos.deltares.nl/repos/dam/dam classic' revision 230
- var contents = @" 28.237 28.850 23.786 2.324 " + Environment.NewLine +
- @"[End of CircleResults]" + Environment.NewLine +
- Environment.NewLine +
- @"[Dumps]" + Environment.NewLine +
- @" 1 : number of dumps in file" + Environment.NewLine +
- Environment.NewLine +
- @"[Dump]" + Environment.NewLine +
- @"[Dump Header]" + Environment.NewLine +
- @"[Column Indication]" + Environment.NewLine +
- @"Number of slices" + Environment.NewLine +
- @"X-Centrepoint" + Environment.NewLine +
- @"Y-Centrepoint" + Environment.NewLine +
- @"Stability factor" + Environment.NewLine +
- @"Radius" + Environment.NewLine +
- @"X coordinate right surface" + Environment.NewLine +
- @"Beta" + Environment.NewLine +
- @"Dump name" + Environment.NewLine +
- @"[End of Column Indication]" + Environment.NewLine +
- @"[Data]" + Environment.NewLine +
- @" 1.276 35 18.216 21.971 12.907 17.810 1.1 Design level" + Environment.NewLine +
- @"[End of Data]" + Environment.NewLine +
- @"[End Of Dump Header]" + Environment.NewLine +
- @"[SliceGeometry]" + Environment.NewLine +
- @"[Column Indication]";
-
- var beta = DGeoStabilityResultReader.GetBeta(contents);
- Assert.AreEqual(1.1, beta, 0.001);
- }
-
- [Test]
- public void CanParseStringContentForNegativeBeta()
- {
- // expected results are based on test in 'https://repos.deltares.nl/repos/dam/dam classic' revision 230
- var contents = @" 28.237 28.850 23.786 2.324 " + Environment.NewLine +
- @"[End of CircleResults]" + Environment.NewLine +
- Environment.NewLine +
- @"[Dumps]" + Environment.NewLine +
- @" 1 : number of dumps in file" + Environment.NewLine +
- Environment.NewLine +
- @"[Dump]" + Environment.NewLine +
- @"[Dump Header]" + Environment.NewLine +
- @"[Column Indication]" + Environment.NewLine +
- @"Number of slices" + Environment.NewLine +
- @"X-Centrepoint" + Environment.NewLine +
- @"Y-Centrepoint" + Environment.NewLine +
- @"Stability factor" + Environment.NewLine +
- @"Radius" + Environment.NewLine +
- @"X coordinate right surface" + Environment.NewLine +
- @"Beta" + Environment.NewLine +
- @"Dump name" + Environment.NewLine +
- @"[End of Column Indication]" + Environment.NewLine +
- @"[Data]" + Environment.NewLine +
- @" 1.276 35 18.216 21.971 12.907 17.810 -1.1 Design level" + Environment.NewLine +
- @"[End of Data]" + Environment.NewLine +
- @"[End Of Dump Header]" + Environment.NewLine +
- @"[SliceGeometry]" + Environment.NewLine +
- @"[Column Indication]";
-
- var beta = DGeoStabilityResultReader.GetBeta(contents);
- Assert.AreEqual(-1.1, beta, 0.001);
- }
-
#region Exceptions
[Test]
[ExpectedException(typeof(ArgumentException))]
- public void ThrowsExceptionWhenFileHasNoContent()
+ public void TestThrowsExceptionWhenFileHasNoContent()
{
DGeoStabilityResultReader.GetDGeoStabilityResults("");
}
[Test]
[ExpectedException(typeof(ArgumentException))]
- public void ThrowsExceptionWhenFileHasContentIsNull()
+ public void TestThrowsExceptionWhenFileHasContentIsNull()
{
DGeoStabilityResultReader.GetDGeoStabilityResults(null);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
- public void ThrowsExceptionWhenFileContainsOnlySpaces()
+ public void TestThrowsExceptionWhenFileContainsOnlySpaces()
{
DGeoStabilityResultReader.GetDGeoStabilityResults(" ");
}
[Test]
[ExpectedException(typeof(DGeoStabilityResultReaderException))]
- public void ThrowIfDumpsHeaderNotFoundInContent()
+ public void TestThrowIfDumpsHeaderNotFoundInContent()
{
var contents = " 8.30 " + Environment.NewLine;
contents += " [Dumps] " + Environment.NewLine;
@@ -393,7 +253,7 @@
[Test]
[ExpectedException(typeof(DGeoStabilityResultReaderException))]
- public void ThrowIfDumpHeaderNotFoundInContent()
+ public void TestThrowIfDumpHeaderNotFoundInContent()
{
var contents = " 8.30 " + Environment.NewLine;
contents += " test ";
@@ -405,7 +265,7 @@
[Test]
[ExpectedException(typeof(DGeoStabilityResultReaderException))]
- public void ThrowIfDataHeaderNotFoundInContent()
+ public void TestThrowIfDataHeaderNotFoundInContent()
{
var contents = " 8.30 " + Environment.NewLine;
contents += "[Dump]" + Environment.NewLine;
@@ -418,7 +278,7 @@
[Test]
[ExpectedException(typeof(DGeoStabilityResultReaderException))]
- public void ThrowIfStabilityColumnNotFound()
+ public void TestThrowIfStabilityColumnNotFound()
{
var contents = @" 28.237 28.850 23.786 2.324 " + Environment.NewLine +
@"[End of CircleResults]" + Environment.NewLine +
@@ -450,7 +310,7 @@
[Test]
[ExpectedException(typeof(DGeoStabilityResultReaderException))]
- public void ThrowIfExitPointXCoordinateColumnNotFound()
+ public void TestThrowIfExitPointXCoordinateColumnNotFound()
{
var contents = @" 28.237 28.850 23.786 2.324 " + Environment.NewLine +
@"[End of CircleResults]" + Environment.NewLine +
@@ -481,7 +341,7 @@
[Test]
[ExpectedException(typeof(DGeoStabilityResultReaderException))]
- public void ThrowIfStabilityColumnCouldntBeParsed()
+ public void TestThrowIfStabilityColumnCouldntBeParsed()
{
var contents = @" 28.237 28.850 23.786 2.324 " + Environment.NewLine +
@"[End of CircleResults]" + Environment.NewLine +
@@ -513,7 +373,7 @@
[Test]
[ExpectedException(typeof(DGeoStabilityResultReaderException))]
- public void ThrowIfExitPointXCoordinateColumnCouldntBeParsed()
+ public void TestThrowIfExitPointXCoordinateColumnCouldntBeParsed()
{
var contents = @" 28.237 28.850 23.786 2.324 " + Environment.NewLine +
@"[End of CircleResults]" + Environment.NewLine +
@@ -544,63 +404,32 @@
[Test]
[ExpectedException(typeof(ArgumentException))]
- public void ThrowIfOuputFileNameEmpty()
+ public void TestThrowIfOuputFileNameEmpty()
{
DGeoStabilityResultReader.GetFileContents("");
}
[Test]
[ExpectedException(typeof(ArgumentException))]
- public void ThrowIfOuputFileNameIsNull()
+ public void TestThrowIfOuputFileNameIsNull()
{
DGeoStabilityResultReader.GetFileContents(null);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
- public void ThrowIfOuputFileNameContainsSpaces()
+ public void TestThrowIfOuputFileNameContainsSpaces()
{
DGeoStabilityResultReader.GetFileContents("");
}
[Test]
[ExpectedException(typeof(FileNotFoundException))]
- public void ThrowIfOuputFileNotFound()
+ public void TestThrowIfOuputFileNotFound()
{
DGeoStabilityResultReader.GetFileContents("test.std");
}
- [Test]
- [ExpectedException(typeof(DGeoStabilityResultReaderException))]
- public void ThrowIfBetaColumnNotFound()
- {
- var contents = @" 28.237 28.850 23.786 2.324 " + Environment.NewLine +
- @"[End of CircleResults]" + Environment.NewLine +
- Environment.NewLine +
- @"[Dumps]" + Environment.NewLine +
- @" 1 : number of dumps in file" + Environment.NewLine +
- Environment.NewLine +
- @"[Dump]" + Environment.NewLine +
- @"[Dump Header]" + Environment.NewLine +
- @"[Column Indication]" + Environment.NewLine +
- @"Stability factor" + Environment.NewLine +
- @"Number of slices" + Environment.NewLine +
- @"X-Centrepoint" + Environment.NewLine +
- @"Y-Centrepoint" + Environment.NewLine +
- @"Radius" + Environment.NewLine +
- @"X coordinate right surface" + Environment.NewLine +
- @"Dump name" + Environment.NewLine +
- @"[End of Column Indication]" + Environment.NewLine +
- @"[Data]" + Environment.NewLine +
- @" 1.276 35 18.216 21.971 12.907 17.810 Design level" + Environment.NewLine +
- @"[End of Data]" + Environment.NewLine +
- @"[End Of Dump Header]" + Environment.NewLine +
- @"[SliceGeometry]" + Environment.NewLine +
- @"[Column Indication]";
-
- DGeoStabilityResultReader.GetBeta(contents);
- }
-
#endregion
}
Index: dam failuremechanisms/damMacroStability/trunk/src/Deltares.DamMacroStability.Calculator/Geo/ConversionException.cs
===================================================================
diff -u
--- dam failuremechanisms/damMacroStability/trunk/src/Deltares.DamMacroStability.Calculator/Geo/ConversionException.cs (revision 0)
+++ dam failuremechanisms/damMacroStability/trunk/src/Deltares.DamMacroStability.Calculator/Geo/ConversionException.cs (revision 423)
@@ -0,0 +1,50 @@
+using System;
+
+namespace Deltares.DamMacroStability.Calculator.Geo
+{
+ ///
+ /// Exception class for conversion
+ ///
+ ///
+ public class ConversionException : Exception
+ {
+ private Exception e;
+ private object str;
+ private Type type;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public ConversionException() : this("There was an error") { }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The message that describes the error.
+ public ConversionException(string message) : base(message) { }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The message.
+ /// The inner.
+ public ConversionException(string message, Exception inner) : base(message, inner) { }
+
+ public ConversionException(Type type, object str, Exception e)
+ {
+ this.type = type;
+ this.str = str;
+ this.e = e;
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The that holds the serialized object data about the exception being thrown.
+ /// The that contains contextual information about the source or destination.
+ protected ConversionException(
+ System.Runtime.Serialization.SerializationInfo info,
+ System.Runtime.Serialization.StreamingContext context)
+ : base(info, context) { }
+ }
+}
Index: dam failuremechanisms/damMacroStability/trunk/src/Deltares.DamMacroStability.Calculator/Geo/ObjectExtensions.cs
===================================================================
diff -u
--- dam failuremechanisms/damMacroStability/trunk/src/Deltares.DamMacroStability.Calculator/Geo/ObjectExtensions.cs (revision 0)
+++ dam failuremechanisms/damMacroStability/trunk/src/Deltares.DamMacroStability.Calculator/Geo/ObjectExtensions.cs (revision 423)
@@ -0,0 +1,151 @@
+using System;
+using System.ComponentModel;
+using System.Globalization;
+
+namespace Deltares.DamMacroStability.Calculator.Geo
+{
+ public static class ObjectExtensions
+ {
+ public static readonly CultureInfo DefaultCulture = new CultureInfo("nl-NL");
+
+ public static T ToType(this object value)
+ {
+ if (value != null)
+ return (T) value.ToType(typeof(T), DefaultCulture);
+ ThrowIfValueType();
+ return default(T);
+ }
+
+ public static T ToType(this object value, CultureInfo culture)
+ {
+ if (value != null)
+ return (T) value.ToType(typeof(T), culture);
+ ThrowIfValueType();
+ return default(T);
+ }
+
+ public static object ToType(this object value, Type type, CultureInfo culture)
+ {
+ if (value == null)
+ {
+ ThrowIfValueType(type);
+ return null;
+ }
+ if (type.IsEnum)
+ return value.ToEnumType(type, false);
+ object obj = null;
+ if (IsNullable(type))
+ try
+ {
+ type = new NullableConverter(type).UnderlyingType;
+ obj = Convert.ChangeType(value, type, CultureInfo.InvariantCulture);
+ }
+ catch
+ {
+ obj = null;
+ }
+ else
+ try
+ {
+ if ((type == typeof(double)) && value is string)
+ {
+ if (Equals(culture, new CultureInfo("nl-NL")))
+ {
+ var str = value as string;
+ if (str.Contains(",") && !str.Contains("."))
+ value = str.Replace(",", ".");
+ else if (str.Contains(",") && str.Contains(".") && (str.Length > 4) && !str.Contains(" "))
+ value = str.Replace(",", "");
+ }
+ obj = value.Equals("NaN")
+ ? double.NaN
+ : Convert.ChangeType(value, type, CultureInfo.InvariantCulture);
+ }
+ else
+ {
+ switch (type.Name)
+ {
+ case "SByte":
+ case "Byte":
+ case "Int16":
+ case "UInt16":
+ case "Int32":
+ case "UInt32":
+ case "Int64":
+ case "UInt64":
+ obj =
+ Convert.ChangeType(
+ Convert.ChangeType(value, typeof(double), CultureInfo.InvariantCulture), type);
+ break;
+ default:
+ obj = Convert.ChangeType(value, type, CultureInfo.InvariantCulture);
+ break;
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ ThrowConversionException(value, type, ex);
+ }
+ return obj;
+ }
+
+ public static T ToEnumType(this object value)
+ {
+ if (value == null)
+ throw new ArgumentNullException("value");
+ return (T) value.ToEnumType(typeof(T), false);
+ }
+
+ public static object ToEnumType(this object value, Type type, bool ignoreCase = false)
+ {
+ if (value == null)
+ throw new ArgumentNullException("value");
+ if (!ignoreCase && !Enum.IsDefined(type, value))
+ ThrowConversionException(value, type, null);
+ var str = value.ToString();
+ object obj = null;
+ try
+ {
+ obj = Enum.Parse(type, str, ignoreCase);
+ }
+ catch (Exception ex)
+ {
+ ThrowConversionException(value, type, ex);
+ }
+ return obj;
+ }
+
+ private static void ThrowIfValueType()
+ {
+ ThrowIfValueType(typeof(T));
+ }
+
+ private static void ThrowIfValueType(Type type)
+ {
+ if (type.IsValueType && !IsNullable(type))
+ throw new ArgumentNullException(
+ string.Format("The value can't be null because parameter type {0} is a value type", type));
+ }
+
+ private static bool IsNullable(Type type)
+ {
+ if (type.IsGenericType)
+ return type.GetGenericTypeDefinition() == typeof(Nullable<>);
+ return false;
+ }
+
+ private static void ThrowConversionException(object value, Type type, Exception e)
+ {
+ var str = "";
+ try
+ {
+ str = value.ToString().Replace("\0", " ");
+ }
+ catch
+ {
+ }
+ throw new ConversionException(type, str, e);
+ }
+ }
+}
\ No newline at end of file
Index: dam failuremechanisms/damMacroStability/trunk/src/Deltares.DamMacroStability.Calculator/Deltares.DamMacroStability.Calculator.csproj
===================================================================
diff -u -r411 -r423
--- dam failuremechanisms/damMacroStability/trunk/src/Deltares.DamMacroStability.Calculator/Deltares.DamMacroStability.Calculator.csproj (.../Deltares.DamMacroStability.Calculator.csproj) (revision 411)
+++ dam failuremechanisms/damMacroStability/trunk/src/Deltares.DamMacroStability.Calculator/Deltares.DamMacroStability.Calculator.csproj (.../Deltares.DamMacroStability.Calculator.csproj) (revision 423)
@@ -41,6 +41,8 @@
+
+
True
True
Index: dam failuremechanisms/damMacroStability/trunk/src/Deltares.DamMacroStability.Calculator/Properties/Resources.resx
===================================================================
diff -u -r421 -r423
--- dam failuremechanisms/damMacroStability/trunk/src/Deltares.DamMacroStability.Calculator/Properties/Resources.resx (.../Resources.resx) (revision 421)
+++ dam failuremechanisms/damMacroStability/trunk/src/Deltares.DamMacroStability.Calculator/Properties/Resources.resx (.../Resources.resx) (revision 423)
@@ -138,7 +138,28 @@
No valid calculation performed
-
- Could not read DGeoStability output file because it has no valid content
+
+ Output file {0} is not valid
+
+ Output file {0} does not exist
+
+
+ Could not read Column Indication
+
+
+ Could not parse stabilityZone:
+
+
+ stabilityZone or stabilityFactorIndex not found
+
+
+ Stability zone 1a or 1b should exist
+
+
+ Output file {0} has no content
+
+
+ Stabiliteitsbestand bevat geen identificator
+
\ No newline at end of file
Index: dam failuremechanisms/damMacroStability/trunk/src/Deltares.DamMacroStability.Calculator/DGeoStabilityResultReader.cs
===================================================================
diff -u -r421 -r423
--- dam failuremechanisms/damMacroStability/trunk/src/Deltares.DamMacroStability.Calculator/DGeoStabilityResultReader.cs (.../DGeoStabilityResultReader.cs) (revision 421)
+++ dam failuremechanisms/damMacroStability/trunk/src/Deltares.DamMacroStability.Calculator/DGeoStabilityResultReader.cs (.../DGeoStabilityResultReader.cs) (revision 423)
@@ -5,6 +5,7 @@
using System.Linq;
using System.Text.RegularExpressions;
using Deltares.DamMacroStability.Calculator.Properties;
+using Deltares.DamMacroStability.Calculator.Geo;
namespace Deltares.DamMacroStability.Calculator
{
@@ -14,24 +15,24 @@
///
public static class DGeoStabilityResultReader
{
- enum StabilityZone { stabilityZone1a = 1, stabilityZone1b = 2, stabilityZone2a = 3, stabilityZone2b = 4, stabilityZone3a = 5, stabilityZone3b = 6 };
+ private enum StabilityZone { stabilityZone1a = 1, stabilityZone1b = 2, stabilityZone2a = 3, stabilityZone2b = 4, stabilityZone3a = 5, stabilityZone3b = 6 };
#region structs
public struct DGeoStabilityResults
{
- public DGeoStabilityResultsSingleZone zone1;
- public DGeoStabilityResultsSingleZone? zone2;
+ public DGeoStabilityResultsSingleZone Zone1;
+ public DGeoStabilityResultsSingleZone? Zone2;
public string CalculationName;
public string CalculationSubDir;
public int IterationNumber;
public void Init()
{
- zone1 = new DGeoStabilityResultsSingleZone();
- zone1.Init();
- zone2 = new DGeoStabilityResultsSingleZone();
- zone2.Value.Init();
+ Zone1 = new DGeoStabilityResultsSingleZone();
+ Zone1.Init();
+ Zone2 = new DGeoStabilityResultsSingleZone();
+ Zone2.Value.Init();
}
}
@@ -133,18 +134,18 @@
///
/// The name of the file
/// The content string
- public static string GetFileContents(string fileName)
+ internal static string GetFileContents(string fileName)
{
if (string.IsNullOrEmpty(fileName) || fileName.Trim() == "")
{
throw new ArgumentException(string.Format(
- "Output file {0} is not valid", fileName));
+ Resources.DGeoStabilityResultReader_GetFileContents_OutputFileIsNotValid, fileName));
}
if (!File.Exists(fileName))
{
throw new FileNotFoundException(string.Format(
- "Output file {0} does not exist", fileName));
+ Resources.DGeoStabilityResultReader_GetFileContents_OutputFileDoesNotExist, fileName));
}
string fileContents;
@@ -160,37 +161,42 @@
///
///
///
- public static DGeoStabilityResults GetDGeoStabilityResults(string fileContent)
+ internal static DGeoStabilityResults GetDGeoStabilityResults(string fileContent)
{
DGeoStabilityResults results = new DGeoStabilityResults();
if (string.IsNullOrEmpty(fileContent) || fileContent.Trim() == "")
{
throw new ArgumentException(string.Format(
- "Output file {0} has no content", fileContent));
+ Resources.DGeoStabilityResultReader_GetDGeoStabilityResults_OutputFileHasNoContent, fileContent));
}
if (ParseHasZonePlotEnabled(fileContent))
{
DGeoStabilityResultsSingleZone? zoneResults1 = GetDGeoStabilityResultsSingleZoneFrom(fileContent, StabilityZone.stabilityZone1a, StabilityZone.stabilityZone1b);
if (zoneResults1 != null)
{
- results.zone1 = zoneResults1.Value;
+ results.Zone1 = zoneResults1.Value;
}
else
{
- throw new DGeoStabilityResultReaderException("Stabilityzone 1a or 1b should exist");
+ throw new DGeoStabilityResultReaderException(Resources.DGeoStabilityResultReader_GetDGeoStabilityResults_StabilityZone1aOr1bShouldExist);
}
- results.zone2 = GetDGeoStabilityResultsSingleZoneFrom(fileContent, StabilityZone.stabilityZone2a, StabilityZone.stabilityZone2b);
+ results.Zone2 = GetDGeoStabilityResultsSingleZoneFrom(fileContent, StabilityZone.stabilityZone2a, StabilityZone.stabilityZone2b);
}
else
{
DGeoStabilityResultsSingleZone? noZoneResults = GetDGeoStabilityResultsNoZones(fileContent);
- results.zone1 = noZoneResults.Value;
+ results.Zone1 = noZoneResults.Value;
}
return results;
}
- public static bool ParseHasZonePlotEnabled(string fileContent)
+ ///
+ /// Parses the fileContent if zone plot is enabled.
+ ///
+ /// Content of the file.
+ /// True when zone plot option is on
+ internal static bool ParseHasZonePlotEnabled(string fileContent)
{
StringReader stringReader = new StringReader(fileContent);
string line = "";
@@ -214,15 +220,14 @@
{
DGeoStabilityResultsSingleZone? resultsSingleZone = null;
DGeoStabilityResultsSingleZone? zoneAResults = ParseZoneResults(fileContent, (int)zoneA);
- DGeoStabilityResultsSingleZone? zoneBResults = null;
if (zoneAResults != null)
{
resultsSingleZone = zoneAResults.Value;
}
else
{
- zoneBResults = ParseZoneResults(fileContent, (int)zoneB);
+ var zoneBResults = ParseZoneResults(fileContent, (int)zoneB);
if (zoneBResults != null)
{
resultsSingleZone = zoneBResults.Value;
@@ -235,28 +240,27 @@
{
StringReader stringReader = new StringReader(fileContent);
string line = "";
- string zoneStabilityResults = null;
- int stabilityFactorIndex = -1;
- int xCoordinateLeftSurfaceIndex = -1;
- int xCoordinateRightSurfaceIndex = -1;
- int zoneNumberIndex = -1;
+ int stabilityFactorIndex;
+ int xCoordinateLeftSurfaceIndex;
+ int xCoordinateRightSurfaceIndex;
+ int zoneNumberIndex;
int betaIndex = -1;
DGeoStabilityResultsSingleZone resultsStruct = new DGeoStabilityResultsSingleZone();
while ((line = stringReader.ReadLine()) != null)
{
if (line.Equals("[Dump]"))
{
- if (!ReadParameterColumnIndices(stringReader, ref stabilityFactorIndex,
- ref xCoordinateLeftSurfaceIndex, ref xCoordinateRightSurfaceIndex, ref zoneNumberIndex, ref betaIndex))
- throw new DGeoStabilityResultReaderException("Could not read Column Indication");
+ if (!ReadParameterColumnIndices(stringReader, out stabilityFactorIndex,
+ out xCoordinateLeftSurfaceIndex, out xCoordinateRightSurfaceIndex, out zoneNumberIndex, ref betaIndex))
+ throw new DGeoStabilityResultReaderException(Resources.DGeoStabilityResultReader_ParseZoneResults_CouldNotReadColumnIndication);
while ((line = stringReader.ReadLine()) != null)
{
if (line.Equals("[Data]"))
{
- zoneStabilityResults = stringReader.ReadLine();
+ var zoneStabilityResults = stringReader.ReadLine();
var zoneStabilityResultsElements = zoneStabilityResults.Split(' ').ToList().Where(x => x.Length > 0).ToArray();
@@ -268,25 +272,25 @@
{
if (int.Parse(zoneStabilityResultsElements[zoneNumberIndex]).Equals(stabilityZone))
{
- Double.TryParse(zoneStabilityResultsElements[stabilityFactorIndex], out resultsStruct.SafetyFactor);
+ resultsStruct.SafetyFactor = zoneStabilityResultsElements[stabilityFactorIndex].ToType();
if (IsUpliftResults(fileContent))
resultsStruct.SafetyFactor = resultsStruct.SafetyFactor / 1.05;
- Double.TryParse(zoneStabilityResultsElements[xCoordinateLeftSurfaceIndex], out resultsStruct.CircleSurfacePointLeftXCoordinate);
- Double.TryParse(zoneStabilityResultsElements[xCoordinateRightSurfaceIndex], out resultsStruct.CircleSurfacePointRightXCoordinate);
+ resultsStruct.CircleSurfacePointLeftXCoordinate = zoneStabilityResultsElements[xCoordinateLeftSurfaceIndex].ToType();
+ resultsStruct.CircleSurfacePointRightXCoordinate = zoneStabilityResultsElements[xCoordinateRightSurfaceIndex].ToType();
if (betaIndex > -1)
{
- Double.TryParse(zoneStabilityResultsElements[betaIndex], out resultsStruct.Beta);
+ resultsStruct.Beta = zoneStabilityResultsElements[betaIndex].ToType();
}
return resultsStruct;
}
}
catch (Exception e)
{
- throw new DGeoStabilityResultReaderException("Could not parse Stabilityzone : " + e);
+ throw new DGeoStabilityResultReaderException(Resources.DGeoStabilityResultReader_ParseZoneResults_CouldNotParseStabilityZone + e);
}
}
else
- throw new DGeoStabilityResultReaderException("stabilityZone or stabilityFactorIndex not found");
+ throw new DGeoStabilityResultReaderException(Resources.DGeoStabilityResultReader_ParseZoneResults_StabilityZoneOrStabilityFactorIndexNotFound);
}
break;
}
@@ -296,8 +300,8 @@
return null;
}
- private static bool ReadParameterColumnIndices(StringReader stringReader, ref int stabilityFactorIndex,
- ref int xCoordinateLeftSurfaceIndex, ref int xCoordinateRightSurfaceIndex, ref int zoneNumberIndex, ref int betaIndex)
+ private static bool ReadParameterColumnIndices(StringReader stringReader, out int stabilityFactorIndex,
+ out int xCoordinateLeftSurfaceIndex, out int xCoordinateRightSurfaceIndex, out int zoneNumberIndex, ref int betaIndex)
{
string line = "";
const string startCondition = "[Column Indication]";
@@ -347,7 +351,7 @@
break;
}
- return ((stabilityFactorIndex >= 0) && (zoneNumberIndex >= 0) && (xCoordinateLeftSurfaceIndex >= 0) && (xCoordinateRightSurfaceIndex >= 0)) ? true : false;
+ return (stabilityFactorIndex >= 0) && (zoneNumberIndex >= 0) && (xCoordinateLeftSurfaceIndex >= 0) && (xCoordinateRightSurfaceIndex >= 0);
}
private static bool IsUpliftResults(string fileContent)
@@ -363,16 +367,11 @@
}
}
- ///
- ///
- ///
- ///
- ///
- ///
private static string ReadContentAfterIdentifier(string fileContent, string identifier)
{
if (!fileContent.Contains(identifier))
- throw new DGeoStabilityResultReaderException("Stability file doesn't contain identifier " + identifier);
+ throw new DGeoStabilityResultReaderException(
+ Resources.DGeoStabilityResultReader_ReadContentAfterIdentifier_StabilityFileDoesNotContainIdentifier + identifier);
fileContent = fileContent.Substring(fileContent.IndexOf(identifier));
return fileContent.Replace(identifier + Environment.NewLine, "");
}
@@ -392,7 +391,10 @@
/// Parses the content to get the safety factory
///
/// The text to parse
- /// The safety factor
+ /// Name of the column.
+ ///
+ /// The safety factor
+ ///
private static double GetColumnValueNoZones(string fileContent, string columnName)
{
fileContent = ReadContentAfterIdentifier(fileContent, "[Dumps]");
@@ -410,14 +412,19 @@
}
///
- ///
+ /// Gets the index of the data column.
///
+ /// The content to search in
+ /// The identifier to look for
+ /// The end tag.
+ ///
+ /// The index of the column
+ ///
+ ///
+ ///
///
/// Returns -1 if identifier is not found
///
- /// The content to search in
- /// The identifier to look for
- /// The index of the column
private static int GetDataColumnIndex(string fileContent, string identifier, string endTag)
{
if (!fileContent.Contains(identifier))
@@ -457,11 +464,6 @@
left.Equals(right, StringComparison.InvariantCulture));
}
- ///
- ///
- ///
- ///
- ///
private static double GetNumberFromLine(string fileContent, int idPos)
{
var doublesPattern = new Regex(@"-?\d+(?:\.\d+)?");
@@ -501,56 +503,5 @@
return new string[0];
}
}
- public static DGeoStabilityResultsSingleZone? GetZoneStability1a(string fileContent)
- {
- return ParseZoneResults(fileContent, (int)StabilityZone.stabilityZone1a);
- }
-
- public static DGeoStabilityResultsSingleZone? GetZoneStability1b(string fileContent)
- {
- return ParseZoneResults(fileContent, (int)StabilityZone.stabilityZone1b);
- }
-
- public static double GetBeta(string fileContent)
- {
- if (string.IsNullOrEmpty(fileContent) || fileContent.Trim() == "")
- {
- throw new ArgumentException(string.Format(
- Resources.DGeoStabilityResultReader_GetBeta_OutputFileHasNoContent, fileContent));
- }
-
- if (ParseHasZonePlotEnabled(fileContent))
- {
- return GetBetaWithZones(fileContent);
- }
- else
- {
- return GetBetaNoZones(fileContent);
- }
-
- }
-
- public static double GetBetaNoZones(string fileContent)
- {
- return GetColumnValueNoZones(fileContent, "Beta");
- }
-
- public static double GetBetaWithZones(string fileContent)
- {
- DGeoStabilityResults mStabResults = new DGeoStabilityResults();
- DGeoStabilityResultsSingleZone? zoneResults1 = GetDGeoStabilityResultsSingleZoneFrom(fileContent,
- StabilityZone.stabilityZone1a, StabilityZone.stabilityZone1b);
- if (zoneResults1 != null)
- {
- mStabResults.zone1 = zoneResults1.Value;
- }
- else
- {
- throw new DGeoStabilityResultReaderException("Stabilityzone 1a or 1b should exist");
- }
- //mStabResults.zone2 = GetMStabResultsSingleZoneFrom(fileContent, StabilityZone.stabilityZone2a, StabilityZone.stabilityZone2b);
- return mStabResults.zone1.Beta;
- }
-
}
}
Index: dam failuremechanisms/damMacroStability/trunk/src/Deltares.DamMacroStability.Calculator/Properties/Resources.Designer.cs
===================================================================
diff -u -r421 -r423
--- dam failuremechanisms/damMacroStability/trunk/src/Deltares.DamMacroStability.Calculator/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 421)
+++ dam failuremechanisms/damMacroStability/trunk/src/Deltares.DamMacroStability.Calculator/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 423)
@@ -115,15 +115,42 @@
}
///
- /// Looks up a localized string similar to Could not read DGeoStability output file because it has no valid content.
+ /// Looks up a localized string similar to Output file {0} has no content.
///
- internal static string DGeoStabilityResultReader_GetBeta_OutputFileHasNoContent {
+ internal static string DGeoStabilityResultReader_GetDGeoStabilityResults_OutputFileHasNoContent {
get {
- return ResourceManager.GetString("DGeoStabilityResultReader_GetBeta_OutputFileHasNoContent", resourceCulture);
+ return ResourceManager.GetString("DGeoStabilityResultReader_GetDGeoStabilityResults_OutputFileHasNoContent", resourceCulture);
}
}
///
+ /// Looks up a localized string similar to Stability zone 1a or 1b should exist.
+ ///
+ internal static string DGeoStabilityResultReader_GetDGeoStabilityResults_StabilityZone1aOr1bShouldExist {
+ get {
+ return ResourceManager.GetString("DGeoStabilityResultReader_GetDGeoStabilityResults_StabilityZone1aOr1bShouldExist", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Output file {0} does not exist.
+ ///
+ internal static string DGeoStabilityResultReader_GetFileContents_OutputFileDoesNotExist {
+ get {
+ return ResourceManager.GetString("DGeoStabilityResultReader_GetFileContents_OutputFileDoesNotExist", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Output file {0} is not valid.
+ ///
+ internal static string DGeoStabilityResultReader_GetFileContents_OutputFileIsNotValid {
+ get {
+ return ResourceManager.GetString("DGeoStabilityResultReader_GetFileContents_OutputFileIsNotValid", resourceCulture);
+ }
+ }
+
+ ///
/// Looks up a localized string similar to No valid calculation performed.
///
internal static string DGeoStabilityResultReader_ParseResultsFromOutputFile_No_valid_calculation_performed {
@@ -132,5 +159,43 @@
"ed", resourceCulture);
}
}
+
+ ///
+ /// Looks up a localized string similar to Could not parse stabilityZone: .
+ ///
+ internal static string DGeoStabilityResultReader_ParseZoneResults_CouldNotParseStabilityZone {
+ get {
+ return ResourceManager.GetString("DGeoStabilityResultReader_ParseZoneResults_CouldNotParseStabilityZone", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Could not read Column Indication.
+ ///
+ internal static string DGeoStabilityResultReader_ParseZoneResults_CouldNotReadColumnIndication {
+ get {
+ return ResourceManager.GetString("DGeoStabilityResultReader_ParseZoneResults_CouldNotReadColumnIndication", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to stabilityZone or stabilityFactorIndex not found.
+ ///
+ internal static string DGeoStabilityResultReader_ParseZoneResults_StabilityZoneOrStabilityFactorIndexNotFound {
+ get {
+ return ResourceManager.GetString("DGeoStabilityResultReader_ParseZoneResults_StabilityZoneOrStabilityFactorIndexNot" +
+ "Found", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Stabiliteitsbestand bevat geen identificator .
+ ///
+ internal static string DGeoStabilityResultReader_ReadContentAfterIdentifier_StabilityFileDoesNotContainIdentifier {
+ get {
+ return ResourceManager.GetString("DGeoStabilityResultReader_ReadContentAfterIdentifier_StabilityFileDoesNotContainI" +
+ "dentifier", resourceCulture);
+ }
+ }
}
}
Index: dam failuremechanisms/damMacroStability/trunk/src/Deltares.DamMacroStability.Calculator/Properties/Resources.nl-NL.resx
===================================================================
diff -u -r421 -r423
--- dam failuremechanisms/damMacroStability/trunk/src/Deltares.DamMacroStability.Calculator/Properties/Resources.nl-NL.resx (.../Resources.nl-NL.resx) (revision 421)
+++ dam failuremechanisms/damMacroStability/trunk/src/Deltares.DamMacroStability.Calculator/Properties/Resources.nl-NL.resx (.../Resources.nl-NL.resx) (revision 423)
@@ -135,10 +135,31 @@
Projectfile '{0}' niet gevonden
-
- Kan DGeoStability uitvoerfile niet lezen omdat het geen geldige inhoud heeft
+
+ Uitvoerbestand {0} heeft geen inhoud
+
+ Stabiliteitszone 1a of 1b zou moeten bestaan
+
+
+ Uitvoerbestand {0} bestaat niet
+
+
+ Uitvoerbestand {0} is niet geldig
+
Geen geldige berekening uitgevoerd
+
+ Kan stabilityZone niet inlezen:
+
+
+ Kan kolom identificatie niet lezen
+
+
+ stabilityZone of stabilityFactorIndex niet gevonden
+
+
+ Stability file does not contain identifier
+
\ No newline at end of file