Index: Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Parsers/DunesBoundaryConditionsCalculationParser.cs
===================================================================
diff -u
--- Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Parsers/DunesBoundaryConditionsCalculationParser.cs (revision 0)
+++ Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Parsers/DunesBoundaryConditionsCalculationParser.cs (revision ca4b4bd58a131771afc45ac41fb8342acd29c048)
@@ -0,0 +1,127 @@
+// Copyright (C) Stichting Deltares 2016. All rights reserved.
+//
+// This file is part of Ringtoets.
+//
+// Ringtoets 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.Globalization;
+using System.IO;
+using Ringtoets.HydraRing.Calculation.Data.Output;
+using Ringtoets.HydraRing.Calculation.Exceptions;
+using Ringtoets.HydraRing.IO;
+
+namespace Ringtoets.HydraRing.Calculation.Parsers
+{
+ ///
+ /// Class for parsing dunes boundary condition results from a dunes boundary conditions calculation.
+ ///
+ public class DunesBoundaryConditionsCalculationParser : IHydraRingFileParser
+ {
+ private const string waterLevelText = "Considered water level";
+ private const string waveHeightText = "Computed wave height";
+ private const string wavePeriodText = "Computed wave period";
+
+ private const char equalsCharacter = '=';
+
+ private double? waterLevel;
+ private double? waveHeight;
+ private double? wavePeriod;
+ ///
+ /// Gets the output that was parsed from the output file.
+ ///
+ public DunesBoundaryConditionsCalculationOutput Output { get; private set; }
+
+ public void Parse(string workingDirectory, int sectionId)
+ {
+ string fileName = string.Format("{0}{1}", sectionId, HydraRingFileConstants.OutputFileSuffix);
+
+ try
+ {
+ ReadFile(Path.Combine(workingDirectory, fileName));
+ SetOutput();
+ }
+ catch
+ {
+ throw new HydraRingFileParserException();
+ }
+ }
+
+ private void SetOutput()
+ {
+ if (waterLevel != null && waveHeight != null && wavePeriod != null)
+ {
+ Output = new DunesBoundaryConditionsCalculationOutput(waterLevel.Value,
+ waveHeight.Value,
+ wavePeriod.Value);
+ }
+ }
+
+ private void ReadFile(string filePath)
+ {
+ if (File.Exists(filePath))
+ {
+ using (var file = new StreamReader(File.OpenRead(filePath)))
+ {
+ while (!file.EndOfStream)
+ {
+ string currentLine = file.ReadLine();
+
+ waterLevel = TryParseWaterLevel(currentLine) ?? waterLevel;
+ waveHeight = TryParseWaveHeight(currentLine) ?? waveHeight;
+ wavePeriod = TryParseWavePeriod(currentLine) ?? wavePeriod;
+ }
+ }
+ }
+ }
+
+ private static double? TryParseWaterLevel(string line)
+ {
+ if (line.Contains(waterLevelText))
+ {
+ string resultAsString = line.Split(equalsCharacter)[1].Trim();
+ return ParseStringResult(resultAsString);
+ }
+ return null;
+ }
+
+ private static double? TryParseWaveHeight(string line)
+ {
+ if (line.Contains(waveHeightText))
+ {
+ string resultAsString = line.Split(equalsCharacter)[1].Trim();
+ return ParseStringResult(resultAsString);
+ }
+ return null;
+ }
+
+ private static double? TryParseWavePeriod(string line)
+ {
+ if (line.Contains(wavePeriodText))
+ {
+ string resultAsString = line.Split(equalsCharacter)[1].Trim();
+ return ParseStringResult(resultAsString);
+ }
+ return null;
+ }
+
+ private static double ParseStringResult(string resultAsString)
+ {
+ return double.Parse(resultAsString, CultureInfo.InvariantCulture);
+ }
+ }
+}
\ No newline at end of file
Fisheye: Tag ca4b4bd58a131771afc45ac41fb8342acd29c048 refers to a dead (removed) revision in file `Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Parsers/DunesBoundaryConditionsParser.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Index: Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Ringtoets.HydraRing.Calculation.csproj
===================================================================
diff -u -r20ced464356ed080cfba4ef1fff929b3f002648a -rca4b4bd58a131771afc45ac41fb8342acd29c048
--- Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Ringtoets.HydraRing.Calculation.csproj (.../Ringtoets.HydraRing.Calculation.csproj) (revision 20ced464356ed080cfba4ef1fff929b3f002648a)
+++ Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Ringtoets.HydraRing.Calculation.csproj (.../Ringtoets.HydraRing.Calculation.csproj) (revision ca4b4bd58a131771afc45ac41fb8342acd29c048)
@@ -108,7 +108,7 @@
-
+
Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/Parsers/DunesBoundaryConditionsCalculationParserTest.cs
===================================================================
diff -u
--- Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/Parsers/DunesBoundaryConditionsCalculationParserTest.cs (revision 0)
+++ Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/Parsers/DunesBoundaryConditionsCalculationParserTest.cs (revision ca4b4bd58a131771afc45ac41fb8342acd29c048)
@@ -0,0 +1,137 @@
+// Copyright (C) Stichting Deltares 2016. All rights reserved.
+//
+// This file is part of Ringtoets.
+//
+// Ringtoets 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 Core.Common.TestUtil;
+using NUnit.Framework;
+using Ringtoets.HydraRing.Calculation.Parsers;
+
+namespace Ringtoets.HydraRing.Calculation.Test.Parsers
+{
+ [TestFixture]
+ public class DunesBoundaryConditionsCalculationParserTest
+ {
+ private const int sectionId = 1;
+ private readonly string testDataPath = Path.Combine(TestHelper.GetTestDataPath(TestDataPath.Ringtoets.HydraRing.Calculation, "Parsers"), "DunesBoundaryConditionsParser");
+ private readonly string outputFileName = sectionId + "-output.txt";
+
+ [Test]
+ public void Constructor_ExpectedValues()
+ {
+ // Call
+ var parser = new DunesBoundaryConditionsCalculationParser();
+
+ // Assert
+ Assert.IsInstanceOf(parser);
+ Assert.IsNull(parser.Output);
+ }
+
+ [Test]
+ public void Parse_NotExistingOutputFile_OutputNull()
+ {
+ // Setup
+ var parser = new DunesBoundaryConditionsCalculationParser();
+
+ // Call
+ parser.Parse(testDataPath, sectionId);
+
+ // Assert
+ Assert.IsNull(parser.Output);
+ }
+
+ [Test]
+ public void Parse_EmptyOutputFile_OutputNull()
+ {
+ // Setup
+ var parser = new DunesBoundaryConditionsCalculationParser();
+ var workingDirectory = Path.Combine(testDataPath, "empty");
+
+ // Call
+ parser.Parse(workingDirectory, sectionId);
+
+ // Assert
+ Assert.IsNull(parser.Output);
+ Assert.IsTrue(TestHelper.CanOpenFileForWrite(Path.Combine(workingDirectory, outputFileName)));
+ }
+
+ [Test]
+ public void Parse_ValidHydraRingOutputFile_OutputSetWithExpectedCalculationResult()
+ {
+ // Setup
+ var parser = new DunesBoundaryConditionsCalculationParser();
+ var workingDirectory = Path.Combine(testDataPath, "valid");
+
+ // Call
+ parser.Parse(workingDirectory, sectionId);
+
+ // Assert
+ Assert.AreEqual(4.82912, parser.Output.WaterLevel);
+ Assert.AreEqual(2.88936, parser.Output.WaveHeight);
+ Assert.AreEqual(10.65437, parser.Output.WavePeriod);
+ Assert.IsTrue(TestHelper.CanOpenFileForWrite(Path.Combine(workingDirectory, outputFileName)));
+ }
+
+ [Test]
+ public void Parse_InvalidHydraRingOutputFileWaterLevelMissing_OutputNull()
+ {
+ // Setup
+ var parser = new DunesBoundaryConditionsCalculationParser();
+ var workingDirectory = Path.Combine(testDataPath, "output-no-waterLevel");
+
+ // Call
+ parser.Parse(workingDirectory, sectionId);
+
+ // Assert
+ Assert.IsNull(parser.Output);
+ Assert.IsTrue(TestHelper.CanOpenFileForWrite(Path.Combine(workingDirectory, outputFileName)));
+ }
+
+ [Test]
+ public void Parse_InvalidHydraRingOutputFileWaveHeightMissing_OutputNull()
+ {
+ // Setup
+ var parser = new DunesBoundaryConditionsCalculationParser();
+ var workingDirectory = Path.Combine(testDataPath, "output-no-waveHeight");
+
+ // Call
+ parser.Parse(workingDirectory, sectionId);
+
+ // Assert
+ Assert.IsNull(parser.Output);
+ Assert.IsTrue(TestHelper.CanOpenFileForWrite(Path.Combine(workingDirectory, outputFileName)));
+ }
+
+ [Test]
+ public void Parse_InvalidHydraRingOutputFileWavePeriodMissing_OutputNull()
+ {
+ // Setup
+ var parser = new DunesBoundaryConditionsCalculationParser();
+ var workingDirectory = Path.Combine(testDataPath, "output-no-wavePeriod");
+
+ // Call
+ parser.Parse(workingDirectory, sectionId);
+
+ // Assert
+ Assert.IsNull(parser.Output);
+ Assert.IsTrue(TestHelper.CanOpenFileForWrite(Path.Combine(workingDirectory, outputFileName)));
+ }
+ }
+}
\ No newline at end of file
Fisheye: Tag ca4b4bd58a131771afc45ac41fb8342acd29c048 refers to a dead (removed) revision in file `Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/Parsers/DunesBoundaryConditionsParserTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/Ringtoets.HydraRing.Calculation.Test.csproj
===================================================================
diff -u -r20ced464356ed080cfba4ef1fff929b3f002648a -rca4b4bd58a131771afc45ac41fb8342acd29c048
--- Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/Ringtoets.HydraRing.Calculation.Test.csproj (.../Ringtoets.HydraRing.Calculation.Test.csproj) (revision 20ced464356ed080cfba4ef1fff929b3f002648a)
+++ Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/Ringtoets.HydraRing.Calculation.Test.csproj (.../Ringtoets.HydraRing.Calculation.Test.csproj) (revision ca4b4bd58a131771afc45ac41fb8342acd29c048)
@@ -106,7 +106,7 @@
-
+