Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Service/ClosingStructuresCalculationService.cs
===================================================================
diff -u -rf4f041e353f89e0e93a4243968acee599b2186a7 -r27bbccd73d24f6aedcb58d209662b1fe224d2aaa
--- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Service/ClosingStructuresCalculationService.cs (.../ClosingStructuresCalculationService.cs) (revision f4f041e353f89e0e93a4243968acee599b2186a7)
+++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Service/ClosingStructuresCalculationService.cs (.../ClosingStructuresCalculationService.cs) (revision 27bbccd73d24f6aedcb58d209662b1fe224d2aaa)
@@ -19,10 +19,12 @@
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
+using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
+using Core.Common.IO.Exceptions;
using log4net;
using Ringtoets.ClosingStructures.Data;
using Ringtoets.ClosingStructures.Service.Properties;
@@ -63,6 +65,18 @@
/// The that holds information about the norm used in the calculation.
/// The that holds the information about the contribution
/// and the general inputs used in the calculation.
+ /// Thrown when or
+ /// or is null.
+ /// Thrown when the
+ /// contains invalid characters.
+ /// Thrown when:
+ ///
+ /// - No settings database file could be found at the location of
+ /// with the same name.
+ /// - Unable to open settings database file.
+ /// - Unable to read required data from database file.
+ ///
+ ///
/// The path which points to the hydraulic boundary database file.
/// Thrown when is an invalid
/// .
@@ -73,6 +87,18 @@
ClosingStructuresFailureMechanism failureMechanism,
string hydraulicBoundaryDatabaseFilePath)
{
+ if (calculation == null)
+ {
+ throw new ArgumentNullException(nameof(calculation));
+ }
+ if (assessmentSection == null)
+ {
+ throw new ArgumentNullException(nameof(assessmentSection));
+ }
+ if (failureMechanism == null)
+ {
+ throw new ArgumentNullException(nameof(failureMechanism));
+ }
var calculationName = calculation.Name;
FailureMechanismSection failureMechanismSection = StructuresHelper.FailureMechanismSectionForCalculation(failureMechanism.Sections,
@@ -148,11 +174,7 @@
///
public void Cancel()
{
- if (calculator != null)
- {
- calculator.Cancel();
- }
-
+ calculator?.Cancel();
canceled = true;
}
@@ -163,8 +185,19 @@
/// The for which to validate the values.
/// The for which to validate the values.
/// true if has no validation errors; false otherwise.
+ /// Thrown when any parameter is null.
+ /// Thrown when is an invalid
+ /// .
public static bool Validate(StructuresCalculation calculation, IAssessmentSection assessmentSection)
{
+ if (calculation == null)
+ {
+ throw new ArgumentNullException(nameof(calculation));
+ }
+ if (assessmentSection == null)
+ {
+ throw new ArgumentNullException(nameof(assessmentSection));
+ }
CalculationServiceHelper.LogValidationBeginTime(calculation.Name);
var messages = ValidateInput(calculation.InputParameters, assessmentSection);
CalculationServiceHelper.LogMessagesAsError(RingtoetsCommonServiceResources.Error_in_validation_0, messages);
@@ -173,6 +206,27 @@
return !messages.Any();
}
+ ///
+ /// Creates the input for the calculation.
+ ///
+ /// The to create the input for.
+ /// The that holds the information about the contribution
+ /// and the general inputs used in the calculation.
+ /// The section to use in the calcluation.
+ /// The filepath to the hydraulic boundary database.
+ ///
+ /// Thrown when is an invalid
+ /// .
+ /// Thrown when the
+ /// contains invalid characters.
+ /// Thrown when:
+ ///
+ /// - No settings database file could be found at the location of
+ /// with the same name.
+ /// - Unable to open settings database file.
+ /// - Unable to read required data from database file.
+ ///
+ ///
private static StructuresClosureCalculationInput CreateStructuresClosureCalculationInput(
StructuresCalculation calculation,
ClosingStructuresFailureMechanism failureMechanism,
@@ -183,29 +237,30 @@
switch (calculation.InputParameters.InflowModelType)
{
case ClosingStructureInflowModelType.VerticalWall:
- input = CreateClosureVerticalWallCalculationInput(calculation, failureMechanismSection, failureMechanism.GeneralInput, hydraulicBoundaryDatabaseFilePath);
+ input = CreateClosureVerticalWallCalculationInput(calculation, failureMechanismSection, failureMechanism.GeneralInput);
break;
case ClosingStructureInflowModelType.LowSill:
- input = CreateLowSillCalculationInput(calculation, failureMechanismSection, failureMechanism.GeneralInput, hydraulicBoundaryDatabaseFilePath);
+ input = CreateLowSillCalculationInput(calculation, failureMechanismSection, failureMechanism.GeneralInput);
break;
case ClosingStructureInflowModelType.FloodedCulvert:
- input = CreateFloodedCulvertCalculationInput(calculation, failureMechanismSection, failureMechanism.GeneralInput, hydraulicBoundaryDatabaseFilePath);
+ input = CreateFloodedCulvertCalculationInput(calculation, failureMechanismSection, failureMechanism.GeneralInput);
break;
default:
throw new InvalidEnumArgumentException("calculation",
(int) calculation.InputParameters.InflowModelType,
typeof(ClosingStructureInflowModelType));
}
+
+ HydraRingSettingsDatabaseHelper.AssignSettingsFromDatabase(input, hydraulicBoundaryDatabaseFilePath);
return input;
}
private static StructuresClosureVerticalWallCalculationInput CreateClosureVerticalWallCalculationInput(
StructuresCalculation calculation,
FailureMechanismSection failureMechanismSection,
- GeneralClosingStructuresInput generalInput,
- string hydraulicBoundaryDatabaseFilePath)
+ GeneralClosingStructuresInput generalInput)
{
- var structuresClosureVerticalWallCalculationInput = new StructuresClosureVerticalWallCalculationInput(
+ return new StructuresClosureVerticalWallCalculationInput(
calculation.InputParameters.HydraulicBoundaryLocation.Id,
new HydraRingSection(1, failureMechanismSection.GetSectionLength(), calculation.InputParameters.StructureNormalOrientation),
HydraRingInputParser.ParseForeshore(calculation.InputParameters),
@@ -230,19 +285,14 @@
calculation.InputParameters.LevelCrestStructureNotClosing.Mean, calculation.InputParameters.LevelCrestStructureNotClosing.StandardDeviation,
calculation.InputParameters.WidthFlowApertures.Mean, calculation.InputParameters.WidthFlowApertures.CoefficientOfVariation,
calculation.InputParameters.DeviationWaveDirection);
-
- HydraRingSettingsDatabaseHelper.AssignSettingsFromDatabase(structuresClosureVerticalWallCalculationInput, hydraulicBoundaryDatabaseFilePath);
-
- return structuresClosureVerticalWallCalculationInput;
}
private static StructuresClosureLowSillCalculationInput CreateLowSillCalculationInput(
StructuresCalculation calculation,
FailureMechanismSection failureMechanismSection,
- GeneralClosingStructuresInput generalInput,
- string hydraulicBoundaryDatabaseFilePath)
+ GeneralClosingStructuresInput generalInput)
{
- var structuresClosureLowSillCalculationInput = new StructuresClosureLowSillCalculationInput(
+ return new StructuresClosureLowSillCalculationInput(
calculation.InputParameters.HydraulicBoundaryLocation.Id,
new HydraRingSection(1, failureMechanismSection.GetSectionLength(), calculation.InputParameters.StructureNormalOrientation),
HydraRingInputParser.ParseForeshore(calculation.InputParameters),
@@ -266,19 +316,14 @@
calculation.InputParameters.ThresholdHeightOpenWeir.Mean, calculation.InputParameters.ThresholdHeightOpenWeir.StandardDeviation,
calculation.InputParameters.InsideWaterLevel.Mean, calculation.InputParameters.InsideWaterLevel.StandardDeviation,
calculation.InputParameters.WidthFlowApertures.Mean, calculation.InputParameters.WidthFlowApertures.CoefficientOfVariation);
-
- HydraRingSettingsDatabaseHelper.AssignSettingsFromDatabase(structuresClosureLowSillCalculationInput, hydraulicBoundaryDatabaseFilePath);
-
- return structuresClosureLowSillCalculationInput;
}
private static StructuresClosureFloodedCulvertCalculationInput CreateFloodedCulvertCalculationInput(
StructuresCalculation calculation,
FailureMechanismSection failureMechanismSection,
- GeneralClosingStructuresInput generalInput,
- string hydraulicBoundaryDatabaseFilePath)
+ GeneralClosingStructuresInput generalInput)
{
- var structuresClosureFloodedCulvertCalculationInput = new StructuresClosureFloodedCulvertCalculationInput(
+ return new StructuresClosureFloodedCulvertCalculationInput(
calculation.InputParameters.HydraulicBoundaryLocation.Id,
new HydraRingSection(1, failureMechanismSection.GetSectionLength(), calculation.InputParameters.StructureNormalOrientation),
HydraRingInputParser.ParseForeshore(calculation.InputParameters),
@@ -300,10 +345,6 @@
calculation.InputParameters.DrainCoefficient.Mean, calculation.InputParameters.DrainCoefficient.StandardDeviation,
calculation.InputParameters.AreaFlowApertures.Mean, calculation.InputParameters.AreaFlowApertures.StandardDeviation,
calculation.InputParameters.InsideWaterLevel.Mean, calculation.InputParameters.InsideWaterLevel.StandardDeviation);
-
- HydraRingSettingsDatabaseHelper.AssignSettingsFromDatabase(structuresClosureFloodedCulvertCalculationInput, hydraulicBoundaryDatabaseFilePath);
-
- return structuresClosureFloodedCulvertCalculationInput;
}
private static string[] ValidateInput(ClosingStructuresInput inputParameters, IAssessmentSection assessmentSection)