Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Service/ClosingStructuresCalculationService.cs =================================================================== diff -u -r5a66def262d2740442baf3a2719fa50e4e09b7d3 -r57204fccf6a575312ab30225ff37aa5bf969eaef --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Service/ClosingStructuresCalculationService.cs (.../ClosingStructuresCalculationService.cs) (revision 5a66def262d2740442baf3a2719fa50e4e09b7d3) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Service/ClosingStructuresCalculationService.cs (.../ClosingStructuresCalculationService.cs) (revision 57204fccf6a575312ab30225ff37aa5bf969eaef) @@ -42,16 +42,23 @@ /// Service that provides methods for performing Hydra-ring calculations for closing structures. /// public class ClosingStructuresCalculationService : StructuresCalculationServiceBase + ClosingStructuresInput, ClosingStructure, ClosingStructuresFailureMechanism, StructuresClosureCalculationInput> { private static readonly ILog log = LogManager.GetLogger(typeof(ClosingStructuresCalculationService)); private IStructuresClosureCalculator calculator; private bool canceled; /// + /// Cancels any ongoing structures closure calculation. + /// + public void Cancel() + { + calculator?.Cancel(); + canceled = true; + } + + /// /// Performs a closing structures calculation based on the supplied and sets /// if the calculation was successful. Error and status information is /// logged during the execution of the operation. @@ -76,17 +83,17 @@ /// . /// Thrown when an error occurs while performing the calculation. public override void Calculate(StructuresCalculation calculation, - IAssessmentSection assessmentSection, - ClosingStructuresFailureMechanism failureMechanism, - string hydraulicBoundaryDatabaseFilePath) + IAssessmentSection assessmentSection, + ClosingStructuresFailureMechanism failureMechanism, + string hydraulicBoundaryDatabaseFilePath) { base.Calculate(calculation, assessmentSection, failureMechanism, hydraulicBoundaryDatabaseFilePath); string calculationName = calculation.Name; - StructuresClosureCalculationInput input = CreateStructuresClosureCalculationInput(calculation, - failureMechanism, - hydraulicBoundaryDatabaseFilePath); + StructuresClosureCalculationInput input = CreateInput(calculation, + failureMechanism, + hydraulicBoundaryDatabaseFilePath); string hlcdDirectory = Path.GetDirectoryName(hydraulicBoundaryDatabaseFilePath); calculator = HydraRingCalculatorFactory.Instance.CreateStructuresClosureCalculator(hlcdDirectory); @@ -150,43 +157,8 @@ } } - /// - /// Cancels any ongoing structures closure calculation. - /// - public void Cancel() + protected override StructuresClosureCalculationInput CreateInput(StructuresCalculation calculation, ClosingStructuresFailureMechanism failureMechanism, string hydraulicBoundaryDatabaseFilePath) { - calculator?.Cancel(); - canceled = true; - } - - /// - /// 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 file path to the hydraulic - /// boundary database. - /// A . - /// 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, - string hydraulicBoundaryDatabaseFilePath) - { StructuresClosureCalculationInput input; switch (calculation.InputParameters.InflowModelType) { @@ -200,7 +172,7 @@ input = CreateFloodedCulvertCalculationInput(calculation, failureMechanism.GeneralInput); break; default: - throw new InvalidEnumArgumentException("calculation", + throw new InvalidEnumArgumentException(nameof(calculation), (int) calculation.InputParameters.InflowModelType, typeof(ClosingStructureInflowModelType)); } Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Service.Test/ClosingStructuresCalculationServiceTest.cs =================================================================== diff -u -r5a66def262d2740442baf3a2719fa50e4e09b7d3 -r57204fccf6a575312ab30225ff37aa5bf969eaef --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Service.Test/ClosingStructuresCalculationServiceTest.cs (.../ClosingStructuresCalculationServiceTest.cs) (revision 5a66def262d2740442baf3a2719fa50e4e09b7d3) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Service.Test/ClosingStructuresCalculationServiceTest.cs (.../ClosingStructuresCalculationServiceTest.cs) (revision 57204fccf6a575312ab30225ff37aa5bf969eaef) @@ -60,7 +60,7 @@ // Assert Assert.IsInstanceOf>(service); + ClosingStructure, ClosingStructuresFailureMechanism, StructuresClosureCalculationInput>>(service); } [Test] Index: Ringtoets/Common/src/Ringtoets.Common.Service/Structures/StructuresCalculationServiceBase.cs =================================================================== diff -u -r5a66def262d2740442baf3a2719fa50e4e09b7d3 -r57204fccf6a575312ab30225ff37aa5bf969eaef --- Ringtoets/Common/src/Ringtoets.Common.Service/Structures/StructuresCalculationServiceBase.cs (.../StructuresCalculationServiceBase.cs) (revision 5a66def262d2740442baf3a2719fa50e4e09b7d3) +++ Ringtoets/Common/src/Ringtoets.Common.Service/Structures/StructuresCalculationServiceBase.cs (.../StructuresCalculationServiceBase.cs) (revision 57204fccf6a575312ab30225ff37aa5bf969eaef) @@ -22,6 +22,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; +using System.IO; using System.Linq; using Core.Common.Base.IO; using Ringtoets.Common.Data; @@ -31,6 +32,8 @@ using Ringtoets.Common.IO.HydraRing; using Ringtoets.Common.Service.Properties; using Ringtoets.Common.Service.ValidationRules; +using Ringtoets.HydraRing.Calculation.Data.Input; +using Ringtoets.HydraRing.Calculation.Data.Input.Structures; using Ringtoets.HydraRing.Calculation.Exceptions; namespace Ringtoets.Common.Service.Structures @@ -42,11 +45,13 @@ /// The input type. /// The structure type. /// The failure mechanism type. - public abstract class StructuresCalculationServiceBase + public abstract class StructuresCalculationServiceBase where TStructureValidationRules : IStructuresValidationRulesRegistry, new() where TStructureInput : StructuresInputBase, new() where TStructure : StructureBase where TFailureMechanism : IFailureMechanism + where TCalculationInput : ExceedanceProbabilityCalculationInput + { /// /// Performs validation over the values on the given . Error and status information is logged during @@ -77,38 +82,6 @@ return !messages.Any(); } - private static string[] ValidateInput(TStructureInput input, IAssessmentSection assessmentSection) - { - var validationResults = new List(); - - string validationProblem = HydraulicDatabaseHelper.ValidatePathForCalculation(assessmentSection.HydraulicBoundaryDatabase.FilePath); - if (!string.IsNullOrEmpty(validationProblem)) - { - validationResults.Add(validationProblem); - return validationResults.ToArray(); - } - - if (input.HydraulicBoundaryLocation == null) - { - validationResults.Add(Resources.CalculationService_ValidateInput_No_hydraulic_boundary_location_selected); - } - - if (input.Structure == null) - { - validationResults.Add(Resources.StructuresCalculationService_ValidateInput_No_Structure_selected); - } - else - { - IEnumerable validationRules = new TStructureValidationRules().GetValidationRules(input); - - foreach (ValidationRule validationRule in validationRules) - { - validationResults.AddRange(validationRule.Validate()); - } - } - return validationResults.ToArray(); - } - /// /// Performs a structures calculation based on the supplied and sets /// if the calculation was successful. Error and status information is logged during the execution of the operation. @@ -122,6 +95,8 @@ /// or is null. /// Thrown when the /// contains invalid characters. + /// Thrown when an unexpected + /// enum value is encountered. /// Thrown when: /// /// No settings database file could be found at the location of @@ -131,9 +106,9 @@ /// /// Thrown when an error occurs while performing the calculation. public virtual void Calculate(StructuresCalculation calculation, - IAssessmentSection assessmentSection, - TFailureMechanism failureMechanism, - string hydraulicBoundaryDatabaseFilePath) + IAssessmentSection assessmentSection, + TFailureMechanism failureMechanism, + string hydraulicBoundaryDatabaseFilePath) { if (calculation == null) { @@ -147,6 +122,68 @@ { throw new ArgumentNullException(nameof(failureMechanism)); } + + string calculationName = calculation.Name; + + TCalculationInput input = CreateInput(calculation, failureMechanism, hydraulicBoundaryDatabaseFilePath); + + string hlcdDirectory = Path.GetDirectoryName(hydraulicBoundaryDatabaseFilePath); } + + /// + /// Creates the input for a structures calculation. + /// + /// The calculation to create the input for. + /// The that holds the information about + /// the contribution and the general inputs used in the calculation. + /// The path to the hydraulic boundary database file. + /// A . + /// Thrown when the + /// contains invalid characters. + /// Thrown when an unexpected + /// enum value is encountered. + /// 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. + /// + /// + protected abstract TCalculationInput CreateInput(StructuresCalculation calculation, + TFailureMechanism failureMechanism, + string hydraulicBoundaryDatabaseFilePath); + + private static string[] ValidateInput(TStructureInput input, IAssessmentSection assessmentSection) + { + var validationResults = new List(); + + string validationProblem = HydraulicDatabaseHelper.ValidatePathForCalculation(assessmentSection.HydraulicBoundaryDatabase.FilePath); + if (!string.IsNullOrEmpty(validationProblem)) + { + validationResults.Add(validationProblem); + return validationResults.ToArray(); + } + + if (input.HydraulicBoundaryLocation == null) + { + validationResults.Add(Resources.CalculationService_ValidateInput_No_hydraulic_boundary_location_selected); + } + + if (input.Structure == null) + { + validationResults.Add(Resources.StructuresCalculationService_ValidateInput_No_Structure_selected); + } + else + { + IEnumerable validationRules = new TStructureValidationRules().GetValidationRules(input); + + foreach (ValidationRule validationRule in validationRules) + { + validationResults.AddRange(validationRule.Validate()); + } + } + return validationResults.ToArray(); + } } } \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/Structures/StructuresCalculationServiceBaseTest.cs =================================================================== diff -u -r5a66def262d2740442baf3a2719fa50e4e09b7d3 -r57204fccf6a575312ab30225ff37aa5bf969eaef --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/Structures/StructuresCalculationServiceBaseTest.cs (.../StructuresCalculationServiceBaseTest.cs) (revision 5a66def262d2740442baf3a2719fa50e4e09b7d3) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/Structures/StructuresCalculationServiceBaseTest.cs (.../StructuresCalculationServiceBaseTest.cs) (revision 57204fccf6a575312ab30225ff37aa5bf969eaef) @@ -28,9 +28,11 @@ using Rhino.Mocks; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Common.Data.Structures; using Ringtoets.Common.Data.TestUtil; using Ringtoets.Common.Service.Structures; using Ringtoets.Common.Service.TestUtil; +using Ringtoets.HydraRing.Calculation.Data.Input; namespace Ringtoets.Common.Service.Test.Structures { @@ -374,8 +376,14 @@ } private class TestStructuresCalculationService : StructuresCalculationServiceBase {} + TestStructuresInput, TestStructure, TestFailureMechanism, ExceedanceProbabilityCalculationInput> + { + protected override ExceedanceProbabilityCalculationInput CreateInput(StructuresCalculation calculation, + TestFailureMechanism failureMechanism, + string hydraulicBoundaryDatabaseFilePath) + { + return null; + } + } } } \ No newline at end of file Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Service/HeightStructuresCalculationService.cs =================================================================== diff -u -r5a66def262d2740442baf3a2719fa50e4e09b7d3 -r57204fccf6a575312ab30225ff37aa5bf969eaef --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Service/HeightStructuresCalculationService.cs (.../HeightStructuresCalculationService.cs) (revision 5a66def262d2740442baf3a2719fa50e4e09b7d3) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Service/HeightStructuresCalculationService.cs (.../HeightStructuresCalculationService.cs) (revision 57204fccf6a575312ab30225ff37aa5bf969eaef) @@ -41,7 +41,7 @@ /// Service that provides methods for performing Hydra-Ring calculations for height structures. /// public class HeightStructuresCalculationService : StructuresCalculationServiceBase + HeightStructure, HeightStructuresFailureMechanism, StructuresOvertoppingCalculationInput> { private static readonly ILog log = LogManager.GetLogger(typeof(HeightStructuresCalculationService)); @@ -87,7 +87,7 @@ string calculationName = calculation.Name; - StructuresOvertoppingCalculationInput input = CreateInput(calculation, failureMechanism.GeneralInput, hydraulicBoundaryDatabaseFilePath); + StructuresOvertoppingCalculationInput input = CreateInput(calculation, failureMechanism, hydraulicBoundaryDatabaseFilePath); string hlcdDirectory = Path.GetDirectoryName(hydraulicBoundaryDatabaseFilePath); calculator = HydraRingCalculatorFactory.Instance.CreateStructuresOvertoppingCalculator(hlcdDirectory); @@ -150,28 +150,12 @@ } } - /// - /// Creates the input for a structures overtopping calculation. - /// - /// The calculation to create the input for. - /// The general input to use in the calculation. - /// The path to the hydraulic boundary database file. - /// A . - /// 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 StructuresOvertoppingCalculationInput CreateInput( - StructuresCalculation calculation, - GeneralHeightStructuresInput generalInput, - string hydraulicBoundaryDatabaseFilePath) + protected override StructuresOvertoppingCalculationInput CreateInput(StructuresCalculation calculation, + HeightStructuresFailureMechanism failureMechanism, + string hydraulicBoundaryDatabaseFilePath) { + GeneralHeightStructuresInput generalInput = failureMechanism.GeneralInput; + var structuresOvertoppingCalculationInput = new StructuresOvertoppingCalculationInput( calculation.InputParameters.HydraulicBoundaryLocation.Id, calculation.InputParameters.StructureNormalOrientation, Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Service.Test/HeightStructuresCalculationServiceTest.cs =================================================================== diff -u -r5a66def262d2740442baf3a2719fa50e4e09b7d3 -r57204fccf6a575312ab30225ff37aa5bf969eaef --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Service.Test/HeightStructuresCalculationServiceTest.cs (.../HeightStructuresCalculationServiceTest.cs) (revision 5a66def262d2740442baf3a2719fa50e4e09b7d3) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Service.Test/HeightStructuresCalculationServiceTest.cs (.../HeightStructuresCalculationServiceTest.cs) (revision 57204fccf6a575312ab30225ff37aa5bf969eaef) @@ -60,7 +60,7 @@ // Assert Assert.IsInstanceOf>(service); + HeightStructure, HeightStructuresFailureMechanism, StructuresOvertoppingCalculationInput>>(service); } [Test] Index: Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Service/StabilityPointStructuresCalculationService.cs =================================================================== diff -u -r5a66def262d2740442baf3a2719fa50e4e09b7d3 -r57204fccf6a575312ab30225ff37aa5bf969eaef --- Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Service/StabilityPointStructuresCalculationService.cs (.../StabilityPointStructuresCalculationService.cs) (revision 5a66def262d2740442baf3a2719fa50e4e09b7d3) +++ Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Service/StabilityPointStructuresCalculationService.cs (.../StabilityPointStructuresCalculationService.cs) (revision 57204fccf6a575312ab30225ff37aa5bf969eaef) @@ -45,14 +45,24 @@ public class StabilityPointStructuresCalculationService : StructuresCalculationServiceBase + StabilityPointStructuresFailureMechanism, + StructuresStabilityPointCalculationInput> { private static readonly ILog log = LogManager.GetLogger(typeof(StabilityPointStructuresCalculationService)); private bool canceled; private IStructuresStabilityPointCalculator calculator; /// + /// Cancels any ongoing structures stability point calculation. + /// + public void Cancel() + { + calculator?.Cancel(); + canceled = true; + } + + /// /// Performs a stability point structures calculation based on the supplied and sets /// if the calculation was successful. Error and status information is /// logged during the execution of the operation. @@ -80,17 +90,17 @@ /// /// Thrown when an error occurs while performing the calculation. public override void Calculate(StructuresCalculation calculation, - IAssessmentSection assessmentSection, - StabilityPointStructuresFailureMechanism failureMechanism, - string hydraulicBoundaryDatabaseFilePath) + IAssessmentSection assessmentSection, + StabilityPointStructuresFailureMechanism failureMechanism, + string hydraulicBoundaryDatabaseFilePath) { base.Calculate(calculation, assessmentSection, failureMechanism, hydraulicBoundaryDatabaseFilePath); string calculationName = calculation.Name; - StructuresStabilityPointCalculationInput input = CreateStructuresStabilityPointCalculationInput(calculation, - failureMechanism, - hydraulicBoundaryDatabaseFilePath); + StructuresStabilityPointCalculationInput input = CreateInput(calculation, + failureMechanism, + hydraulicBoundaryDatabaseFilePath); string hlcdDirectory = Path.GetDirectoryName(hydraulicBoundaryDatabaseFilePath); calculator = HydraRingCalculatorFactory.Instance.CreateStructuresStabilityPointCalculator(hlcdDirectory); @@ -152,41 +162,10 @@ } } - /// - /// Cancels any ongoing structures stability point calculation. - /// - public void Cancel() + protected override StructuresStabilityPointCalculationInput CreateInput(StructuresCalculation calculation, + StabilityPointStructuresFailureMechanism failureMechanism, + string hydraulicBoundaryDatabaseFilePath) { - calculator?.Cancel(); - canceled = true; - } - - /// - /// Creates the input for a structures stability point calculation. - /// - /// The calculation to create the input for. - /// The failure mechanism that contains input to use in the calculation. - /// The path to the hydraulic boundary database file. - /// A . - /// 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. - /// - /// Thrown when: - /// - /// is an invalid . - /// is an invalid . - /// - private StructuresStabilityPointCalculationInput CreateStructuresStabilityPointCalculationInput( - StructuresCalculation calculation, - StabilityPointStructuresFailureMechanism failureMechanism, - string hydraulicBoundaryDatabaseFilePath) - { StructuresStabilityPointCalculationInput input; switch (calculation.InputParameters.InflowModelType) { @@ -205,7 +184,7 @@ break; default: throw new InvalidEnumArgumentException(nameof(calculation), - (int) calculation.InputParameters.LoadSchematizationType, + (int)calculation.InputParameters.LoadSchematizationType, typeof(LoadSchematizationType)); } break; @@ -224,13 +203,13 @@ break; default: throw new InvalidEnumArgumentException(nameof(calculation), - (int) calculation.InputParameters.LoadSchematizationType, + (int)calculation.InputParameters.LoadSchematizationType, typeof(LoadSchematizationType)); } break; default: throw new InvalidEnumArgumentException(nameof(calculation), - (int) calculation.InputParameters.InflowModelType, + (int)calculation.InputParameters.InflowModelType, typeof(StabilityPointStructureInflowModelType)); } Index: Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Service.Test/StabilityPointStructuresCalculationServiceTest.cs =================================================================== diff -u -r5a66def262d2740442baf3a2719fa50e4e09b7d3 -r57204fccf6a575312ab30225ff37aa5bf969eaef --- Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Service.Test/StabilityPointStructuresCalculationServiceTest.cs (.../StabilityPointStructuresCalculationServiceTest.cs) (revision 5a66def262d2740442baf3a2719fa50e4e09b7d3) +++ Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Service.Test/StabilityPointStructuresCalculationServiceTest.cs (.../StabilityPointStructuresCalculationServiceTest.cs) (revision 57204fccf6a575312ab30225ff37aa5bf969eaef) @@ -61,7 +61,8 @@ Assert.IsInstanceOf>(service); + StabilityPointStructuresFailureMechanism, + StructuresStabilityPointCalculationInput>>(service); } [Test]