Index: Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/CalculationConfigurationImporter.cs
===================================================================
diff -u -r1144837cd4defc65250e08e83d9ab8583324e21b -r3fa1f22b25a81f42d033e29e29d57e362eff8662
--- Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/CalculationConfigurationImporter.cs (.../CalculationConfigurationImporter.cs) (revision 1144837cd4defc65250e08e83d9ab8583324e21b)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/CalculationConfigurationImporter.cs (.../CalculationConfigurationImporter.cs) (revision 3fa1f22b25a81f42d033e29e29d57e362eff8662)
@@ -26,7 +26,6 @@
using Core.Common.IO.Readers;
using log4net;
using Ringtoets.Common.Data.Calculation;
-using Ringtoets.Common.IO.Exceptions;
using Ringtoets.Common.IO.Properties;
using Ringtoets.Common.IO.Readers;
@@ -113,28 +112,9 @@
/// Parses a calculation from the provided .
///
/// The calculation read from XML.
- /// A parsed calculation instance.
- /// Thrown when something goes wrong while parsing.
+ /// A parsed calculation instance, or null when something goes wrong while parsing.
protected abstract ICalculation ParseReadCalculation(TReadCalculation readCalculation);
- ///
- /// Performs the provided and handles any thrown .
- ///
- /// The action to perform.
- /// The error message to provide when rethrowing any thrown .
- /// Thrown when throws an .
- protected static void PerformActionHandlingAnyArgumentOutOfRangeException(Action action, string errorMessage)
- {
- try
- {
- action();
- }
- catch (ArgumentOutOfRangeException e)
- {
- throw new CriticalFileValidationException($"{errorMessage} {e.Message}");
- }
- }
-
protected void LogOutOfRangeException(string errorMessage, string calculationName, ArgumentOutOfRangeException e)
{
LogReadCalculationConversionError($"{errorMessage} {e.Message}", calculationName);
@@ -175,7 +155,7 @@
var readCalculation = readConfigurationItem as TReadCalculation;
if (readCalculation != null)
{
- return ParseReadCalculationInternal(readCalculation);
+ return ParseReadCalculation(readCalculation);
}
return null;
@@ -197,19 +177,6 @@
return calculationGroup;
}
- private ICalculation ParseReadCalculationInternal(TReadCalculation readCalculation)
- {
- try
- {
- return ParseReadCalculation(readCalculation);
- }
- catch (CriticalFileValidationException e)
- {
- LogReadCalculationConversionError(e.Message, readCalculation.Name);
- return null;
- }
- }
-
private void AddItemsToModel(IEnumerable parsedCalculationItems)
{
foreach (ICalculationBase parsedCalculationItem in parsedCalculationItems)
Index: Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Importers/WaveConditionsCalculationConfigurationImporter.cs
===================================================================
diff -u -r09fb591f0e8017e22b62ca554f6eceeeafa51219 -r3fa1f22b25a81f42d033e29e29d57e362eff8662
--- Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Importers/WaveConditionsCalculationConfigurationImporter.cs (.../WaveConditionsCalculationConfigurationImporter.cs) (revision 09fb591f0e8017e22b62ca554f6eceeeafa51219)
+++ Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Importers/WaveConditionsCalculationConfigurationImporter.cs (.../WaveConditionsCalculationConfigurationImporter.cs) (revision 3fa1f22b25a81f42d033e29e29d57e362eff8662)
@@ -21,14 +21,12 @@
using System;
using System.Collections.Generic;
-using System.Globalization;
using System.Linq;
using Core.Common.Base.Data;
using Ringtoets.Common.Data.Calculation;
using Ringtoets.Common.Data.DikeProfiles;
using Ringtoets.Common.Data.Hydraulics;
using Ringtoets.Common.IO;
-using Ringtoets.Common.IO.Exceptions;
using Ringtoets.Common.IO.FileImporters;
using Ringtoets.Revetment.Data;
using Ringtoets.Revetment.IO.Properties;
@@ -46,35 +44,35 @@
: CalculationConfigurationImporter
where T : IWaveConditionsCalculation, new()
{
- private readonly IEnumerable hydraulicBoundaryLocations;
+ private readonly IEnumerable availableHydraulicBoundaryLocations;
private readonly IEnumerable foreshoreProfiles;
///
/// Creates a new instance of .
///
/// The path to the XML file to import from.
/// The calculation group to update.
- /// The hydraulic boundary locations
+ /// The hydraulic boundary locations
/// used to check if the imported objects contain the right location.
/// The foreshore profiles used to check if
/// the imported objects contain the right profile.
/// Thrown when any parameter is
/// null.
public WaveConditionsCalculationConfigurationImporter(string xmlFilePath,
CalculationGroup importTarget,
- IEnumerable hydraulicBoundaryLocations,
+ IEnumerable availableHydraulicBoundaryLocations,
IEnumerable foreshoreProfiles)
: base(xmlFilePath, importTarget)
{
- if (hydraulicBoundaryLocations == null)
+ if (availableHydraulicBoundaryLocations == null)
{
- throw new ArgumentNullException(nameof(hydraulicBoundaryLocations));
+ throw new ArgumentNullException(nameof(availableHydraulicBoundaryLocations));
}
if (foreshoreProfiles == null)
{
throw new ArgumentNullException(nameof(foreshoreProfiles));
}
- this.hydraulicBoundaryLocations = hydraulicBoundaryLocations;
+ this.availableHydraulicBoundaryLocations = availableHydraulicBoundaryLocations;
this.foreshoreProfiles = foreshoreProfiles;
}
@@ -90,12 +88,27 @@
Name = readCalculation.Name
};
- ReadHydraulicBoundaryLocation(readCalculation, waveConditionsCalculation);
- ReadBoundaries(readCalculation, waveConditionsCalculation);
+ if (!ReadHydraulicBoundaryLocation(readCalculation, waveConditionsCalculation))
+ {
+ return null;
+ }
+ if (!ReadBoundaries(readCalculation, waveConditionsCalculation))
+ {
+ return null;
+ }
ReadStepSize(readCalculation, waveConditionsCalculation);
- ReadForeshoreProfile(readCalculation, waveConditionsCalculation);
- ReadOrientation(readCalculation, waveConditionsCalculation);
- ReadWaveReduction(readCalculation, waveConditionsCalculation);
+ if (!ReadForeshoreProfile(readCalculation, waveConditionsCalculation))
+ {
+ return null;
+ }
+ if (!ReadOrientation(readCalculation, waveConditionsCalculation))
+ {
+ return null;
+ }
+ if (!ReadWaveReduction(readCalculation, waveConditionsCalculation))
+ {
+ return null;
+ }
return waveConditionsCalculation;
}
@@ -105,68 +118,111 @@
///
/// The calculation read from the imported file.
/// The calculation to configure.
- /// Thrown when the
- /// has a set which is not available in .
- private void ReadHydraulicBoundaryLocation(ReadWaveConditionsCalculation readCalculation, IWaveConditionsCalculation calculation)
+ /// false when the has a
+ /// set which is not available in
+ /// , true otherwise.
+ private bool ReadHydraulicBoundaryLocation(ReadWaveConditionsCalculation readCalculation, IWaveConditionsCalculation calculation)
{
if (readCalculation.HydraulicBoundaryLocation != null)
{
- HydraulicBoundaryLocation location = hydraulicBoundaryLocations
+ HydraulicBoundaryLocation location = availableHydraulicBoundaryLocations
.FirstOrDefault(l => l.Name == readCalculation.HydraulicBoundaryLocation);
if (location == null)
{
- throw new CriticalFileValidationException(string.Format(RingtoetsCommonIOResources.CalculationConfigurationImporter_ReadHydraulicBoundaryLocation_Hydraulic_boundary_location_0_does_not_exist,
- readCalculation.HydraulicBoundaryLocation));
+ LogReadCalculationConversionError(string.Format(
+ RingtoetsCommonIOResources.CalculationConfigurationImporter_ReadHydraulicBoundaryLocation_Hydraulic_boundary_location_0_does_not_exist,
+ readCalculation.HydraulicBoundaryLocation),
+ calculation.Name);
+ return false;
}
calculation.InputParameters.HydraulicBoundaryLocation = location;
}
+ return true;
}
///
/// Reads the entry point and exit point.
///
/// The calculation read from the imported file.
/// The calculation to configure.
- /// Thrown when one of the boundaries is invalid.
- private static void ReadBoundaries(ReadWaveConditionsCalculation readCalculation, IWaveConditionsCalculation calculation)
+ /// false when one of the boundaries is invalid, true otherwise.
+ private bool ReadBoundaries(ReadWaveConditionsCalculation readCalculation, IWaveConditionsCalculation calculation)
{
if (readCalculation.UpperBoundaryRevetment.HasValue)
{
var upperBoundaryRevetment = (double) readCalculation.UpperBoundaryRevetment;
- PerformActionHandlingAnyArgumentOutOfRangeException(
- () => calculation.InputParameters.UpperBoundaryRevetment = (RoundedDouble) upperBoundaryRevetment,
- string.Format(Resources.WaveConditionsCalculationConfigurationImporter_ReadBoundaries_Upper_boundary_revetment_0_invalid, upperBoundaryRevetment));
+ try
+ {
+ calculation.InputParameters.UpperBoundaryRevetment = (RoundedDouble) upperBoundaryRevetment;
+ }
+ catch (ArgumentOutOfRangeException e)
+ {
+ LogOutOfRangeException(string.Format(
+ Resources.WaveConditionsCalculationConfigurationImporter_ReadBoundaries_Upper_boundary_revetment_0_invalid,
+ upperBoundaryRevetment),
+ calculation.Name, e);
+ return false;
+ }
}
if (readCalculation.LowerBoundaryRevetment.HasValue)
{
var lowerBoundaryRevetment = (double) readCalculation.LowerBoundaryRevetment;
- PerformActionHandlingAnyArgumentOutOfRangeException(
- () => calculation.InputParameters.LowerBoundaryRevetment = (RoundedDouble) lowerBoundaryRevetment,
- string.Format(Resources.WaveConditionsCalculationConfigurationImporter_ReadBoundaries_Lower_boundary_revetment_0_invalid, lowerBoundaryRevetment));
+ try
+ {
+ calculation.InputParameters.LowerBoundaryRevetment = (RoundedDouble) lowerBoundaryRevetment;
+ }
+ catch (ArgumentOutOfRangeException e)
+ {
+ LogOutOfRangeException(string.Format(
+ Resources.WaveConditionsCalculationConfigurationImporter_ReadBoundaries_Lower_boundary_revetment_0_invalid,
+ lowerBoundaryRevetment),
+ calculation.Name, e);
+ return false;
+ }
}
if (readCalculation.UpperBoundaryWaterLevels.HasValue)
{
var upperBoundaryWaterLevels = (double) readCalculation.UpperBoundaryWaterLevels;
- PerformActionHandlingAnyArgumentOutOfRangeException(
- () => calculation.InputParameters.UpperBoundaryWaterLevels = (RoundedDouble) upperBoundaryWaterLevels,
- string.Format(Resources.WaveConditionsCalculationConfigurationImporter_ReadBoundaries_Upper_boundary_waterlevels_0_invalid, upperBoundaryWaterLevels));
+ try
+ {
+ calculation.InputParameters.UpperBoundaryWaterLevels = (RoundedDouble)upperBoundaryWaterLevels;
+ }
+ catch (ArgumentOutOfRangeException e)
+ {
+ LogOutOfRangeException(string.Format(
+ Resources.WaveConditionsCalculationConfigurationImporter_ReadBoundaries_Upper_boundary_waterlevels_0_invalid,
+ upperBoundaryWaterLevels),
+ calculation.Name, e);
+ return false;
+ }
}
if (readCalculation.LowerBoundaryWaterLevels.HasValue)
{
var lowerBoundaryWaterLevels = (double) readCalculation.LowerBoundaryWaterLevels;
- PerformActionHandlingAnyArgumentOutOfRangeException(
- () => calculation.InputParameters.LowerBoundaryWaterLevels = (RoundedDouble) lowerBoundaryWaterLevels,
- string.Format(Resources.WaveConditionsCalculationConfigurationImporter_ReadBoundaries_Lower_boundary_waterlevels_0_invalid, lowerBoundaryWaterLevels));
+ try
+ {
+ calculation.InputParameters.LowerBoundaryWaterLevels = (RoundedDouble)lowerBoundaryWaterLevels;
+ }
+ catch (ArgumentOutOfRangeException e)
+ {
+ LogOutOfRangeException(string.Format(
+ Resources.WaveConditionsCalculationConfigurationImporter_ReadBoundaries_Lower_boundary_waterlevels_0_invalid,
+ lowerBoundaryWaterLevels),
+ calculation.Name, e);
+ return false;
+ }
}
+
+ return true;
}
private void ReadStepSize(ReadWaveConditionsCalculation readCalculation, IWaveConditionsCalculation calculation)
@@ -185,52 +241,70 @@
///
/// The calculation read from the imported file.
/// The calculation to configure.
- /// Thrown when the
- /// has a set which is not available in .
- private void ReadForeshoreProfile(ReadWaveConditionsCalculation readCalculation, IWaveConditionsCalculation calculation)
+ /// false when the has a
+ /// set which is not available in ,
+ /// true otherwise.
+ private bool ReadForeshoreProfile(ReadWaveConditionsCalculation readCalculation, IWaveConditionsCalculation calculation)
{
if (readCalculation.ForeshoreProfile != null)
{
ForeshoreProfile foreshoreProfile = foreshoreProfiles.FirstOrDefault(fp => fp.Name == readCalculation.ForeshoreProfile);
if (foreshoreProfile == null)
{
- throw new CriticalFileValidationException(string.Format(Resources.WaveConditionsCalculationConfigurationImporter_ReadForeshoreProfile_Foreshore_profile_0_does_not_exist,
- readCalculation.ForeshoreProfile));
+ LogReadCalculationConversionError(string.Format(
+ Resources.WaveConditionsCalculationConfigurationImporter_ReadForeshoreProfile_Foreshore_profile_0_does_not_exist,
+ readCalculation.ForeshoreProfile),
+ calculation.Name);
+ return false;
}
calculation.InputParameters.ForeshoreProfile = foreshoreProfile;
}
+ return true;
}
///
/// Reads the orientation.
///
/// The calculation read from the imported file.
/// The calculation to configure.
- /// Thrown when the orientation is invalid.
- private static void ReadOrientation(ReadWaveConditionsCalculation readCalculation, IWaveConditionsCalculation calculation)
+ /// falce when the orientation is invalid, true otherwise.
+ private bool ReadOrientation(ReadWaveConditionsCalculation readCalculation, IWaveConditionsCalculation calculation)
{
if (readCalculation.Orientation.HasValue)
{
var orientation = (double) readCalculation.Orientation;
- PerformActionHandlingAnyArgumentOutOfRangeException(
- () => calculation.InputParameters.Orientation = (RoundedDouble) orientation,
- string.Format(Resources.WaveConditionsCalculationConfigurationImporter_ReadOrientation_Orientation_0_invalid, orientation));
+ try
+ {
+ calculation.InputParameters.Orientation = (RoundedDouble) orientation;
+ }
+ catch (ArgumentOutOfRangeException e)
+ {
+ LogOutOfRangeException(string.Format(
+ Resources.WaveConditionsCalculationConfigurationImporter_ReadOrientation_Orientation_0_invalid,
+ orientation),
+ calculation.Name, e);
+ return false;
+ }
}
+ return true;
}
///
/// Reads the wave reduction parameters.
///
/// The calculation read from the imported file.
/// The calculation to configure.
- /// Thrown when there is an invalid
- /// wave reduction parameter defined.
- private static void ReadWaveReduction(ReadWaveConditionsCalculation readCalculation, IWaveConditionsCalculation calculation)
+ /// false when there is an invalid wave reduction parameter defined,
+ /// true otherwise.
+ private bool ReadWaveReduction(ReadWaveConditionsCalculation readCalculation, IWaveConditionsCalculation calculation)
{
- ValidateWaveReduction(readCalculation, calculation);
+ if (!ValidateWaveReduction(readCalculation, calculation))
+ {
+ return false;
+ }
if (readCalculation.UseForeshore.HasValue)
{
@@ -251,16 +325,17 @@
{
calculation.InputParameters.BreakWater.Height = (RoundedDouble) readCalculation.BreakWaterHeight;
}
+ return true;
}
///
/// Validation to check if the defined wave reduction parameters are valid.
///
/// The calculation read from the imported file.
/// The calculation to configure.
- /// Thrown when there is an
- /// invalid wave reduction parameter defined.
- private static void ValidateWaveReduction(ReadWaveConditionsCalculation readCalculation, IWaveConditionsCalculation calculation)
+ /// false when there is an invalid wave reduction parameter defined,
+ /// true otherwise.
+ private bool ValidateWaveReduction(ReadWaveConditionsCalculation readCalculation, IWaveConditionsCalculation calculation)
{
if (calculation.InputParameters.ForeshoreProfile == null)
{
@@ -269,17 +344,24 @@
|| readCalculation.BreakWaterHeight != null
|| readCalculation.BreakWaterType != null)
{
- throw new CriticalFileValidationException(Resources.WaveConditionsCalculationConfigurationImporter_ValidateWaveReduction_No_foreshore_profile_provided);
+ LogReadCalculationConversionError(
+ Resources.WaveConditionsCalculationConfigurationImporter_ValidateWaveReduction_No_foreshore_profile_provided,
+ calculation.Name);
+ return false;
}
}
else if (!calculation.InputParameters.ForeshoreGeometry.Any())
{
if (readCalculation.UseForeshore.HasValue)
{
- throw new CriticalFileValidationException(string.Format(Resources.WaveConditionsCalculationConfigurationImporter_ValidateWaveReduction_Foreshore_profile_0_has_no_geometry_and_cannot_be_used,
- readCalculation.ForeshoreProfile));
+ LogReadCalculationConversionError(string.Format(
+ Resources.WaveConditionsCalculationConfigurationImporter_ValidateWaveReduction_Foreshore_profile_0_has_no_geometry_and_cannot_be_used,
+ readCalculation.ForeshoreProfile),
+ calculation.Name);
+ return false;
}
}
+ return true;
}
}
}
\ No newline at end of file
Index: Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/Importers/WaveConditionsCalculationConfigurationImporterTest.cs
===================================================================
diff -u -r28b8182ae19e0d84eb705a013149c05ef99a94dc -r3fa1f22b25a81f42d033e29e29d57e362eff8662
--- Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/Importers/WaveConditionsCalculationConfigurationImporterTest.cs (.../WaveConditionsCalculationConfigurationImporterTest.cs) (revision 28b8182ae19e0d84eb705a013149c05ef99a94dc)
+++ Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/Importers/WaveConditionsCalculationConfigurationImporterTest.cs (.../WaveConditionsCalculationConfigurationImporterTest.cs) (revision 3fa1f22b25a81f42d033e29e29d57e362eff8662)
@@ -70,7 +70,7 @@
// Assert
var exception = Assert.Throws(test);
- Assert.AreEqual("hydraulicBoundaryLocations", exception.ParamName);
+ Assert.AreEqual("availableHydraulicBoundaryLocations", exception.ParamName);
}
[Test]