Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Service/ClosingStructuresCalculationService.cs =================================================================== diff -u -r45762d43270b997ca89d8f8ec73f7b895b52bd6a -rfa05755175660f1738a1c3bf82fb4505b93ffa1f --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Service/ClosingStructuresCalculationService.cs (.../ClosingStructuresCalculationService.cs) (revision 45762d43270b997ca89d8f8ec73f7b895b52bd6a) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Service/ClosingStructuresCalculationService.cs (.../ClosingStructuresCalculationService.cs) (revision fa05755175660f1738a1c3bf82fb4505b93ffa1f) @@ -19,10 +19,7 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. -using System; using System.ComponentModel; -using System.IO; -using Core.Common.Base.IO; using log4net; using Ringtoets.ClosingStructures.Data; using Ringtoets.ClosingStructures.Service.Properties; @@ -32,7 +29,6 @@ using Ringtoets.Common.Service; using Ringtoets.Common.Service.Structures; using Ringtoets.HydraRing.Calculation.Calculator; -using Ringtoets.HydraRing.Calculation.Calculator.Factory; using Ringtoets.HydraRing.Calculation.Data.Input.Structures; using Ringtoets.HydraRing.Calculation.Exceptions; @@ -46,67 +42,43 @@ { private static readonly ILog log = LogManager.GetLogger(typeof(ClosingStructuresCalculationService)); - private IStructuresCalculator calculator; - private bool canceled; - - /// - /// Cancels any ongoing structures closure calculation. - /// - public void Cancel() + protected override StructuresClosureCalculationInput CreateInput(StructuresCalculation calculation, ClosingStructuresFailureMechanism failureMechanism, string hydraulicBoundaryDatabaseFilePath) { - calculator?.Cancel(); - canceled = true; + StructuresClosureCalculationInput input; + switch (calculation.InputParameters.InflowModelType) + { + case ClosingStructureInflowModelType.VerticalWall: + input = CreateClosureVerticalWallCalculationInput(calculation, failureMechanism.GeneralInput); + break; + case ClosingStructureInflowModelType.LowSill: + input = CreateLowSillCalculationInput(calculation, failureMechanism.GeneralInput); + break; + case ClosingStructureInflowModelType.FloodedCulvert: + input = CreateFloodedCulvertCalculationInput(calculation, failureMechanism.GeneralInput); + break; + default: + throw new InvalidEnumArgumentException(nameof(calculation), + (int) calculation.InputParameters.InflowModelType, + typeof(ClosingStructureInflowModelType)); + } + + HydraRingSettingsDatabaseHelper.AssignSettingsFromDatabase(input, hydraulicBoundaryDatabaseFilePath); + return input; } - /// - /// 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. - /// - /// The that holds all the information required to perform the calculation. - /// 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 - /// . - /// Thrown when an error occurs while performing the calculation. - public override void Calculate(StructuresCalculation calculation, - IAssessmentSection assessmentSection, - ClosingStructuresFailureMechanism failureMechanism, - string hydraulicBoundaryDatabaseFilePath) + protected override void PerformCalculation(IStructuresCalculator calculator, + StructuresClosureCalculationInput input, + StructuresCalculation calculation, + IAssessmentSection assessmentSection, + ClosingStructuresFailureMechanism failureMechanism) { - base.Calculate(calculation, assessmentSection, failureMechanism, hydraulicBoundaryDatabaseFilePath); - - string calculationName = calculation.Name; - - StructuresClosureCalculationInput input = CreateInput(calculation, - failureMechanism, - hydraulicBoundaryDatabaseFilePath); - - string hlcdDirectory = Path.GetDirectoryName(hydraulicBoundaryDatabaseFilePath); - calculator = HydraRingCalculatorFactory.Instance.CreateStructuresCalculator(hlcdDirectory); - - CalculationServiceHelper.LogCalculationBegin(); - var exceptionThrown = false; try { calculator.Calculate(input); - if (!canceled && string.IsNullOrEmpty(calculator.LastErrorFileContent)) + if (!Canceled && string.IsNullOrEmpty(calculator.LastErrorFileContent)) { ProbabilityAssessmentOutput probabilityAssessmentOutput = ProbabilityAssessmentService.Calculate(assessmentSection.FailureMechanismContribution.Norm, @@ -118,18 +90,18 @@ } catch (HydraRingCalculationException) { - if (!canceled) + if (!Canceled) { string lastErrorFileContent = calculator.LastErrorFileContent; if (string.IsNullOrEmpty(lastErrorFileContent)) { log.ErrorFormat(Resources.ClosingStructuresCalculationService_Calculate_Error_in_ClosingStructuresCalculation_0_no_error_report, - calculationName); + calculation.Name); } else { log.ErrorFormat(Resources.ClosingStructuresCalculationService_Calculate_Error_in_ClosingStructuresCalculation_0_click_details_for_last_error_report_1, - calculationName, lastErrorFileContent); + calculation.Name, lastErrorFileContent); } exceptionThrown = true; @@ -139,11 +111,11 @@ finally { string lastErrorFileContent = calculator.LastErrorFileContent; - bool errorOccurred = CalculationServiceHelper.HasErrorOccurred(canceled, exceptionThrown, lastErrorFileContent); + bool errorOccurred = CalculationServiceHelper.HasErrorOccurred(Canceled, exceptionThrown, lastErrorFileContent); if (errorOccurred) { log.ErrorFormat(Resources.ClosingStructuresCalculationService_Calculate_Error_in_ClosingStructuresCalculation_0_click_details_for_last_error_report_1, - calculationName, lastErrorFileContent); + calculation.Name, lastErrorFileContent); } log.InfoFormat(Resources.ClosingStructuresCalculationService_Calculate_Calculation_temporary_directory_can_be_found_on_location_0, @@ -157,30 +129,6 @@ } } - protected override StructuresClosureCalculationInput CreateInput(StructuresCalculation calculation, ClosingStructuresFailureMechanism failureMechanism, string hydraulicBoundaryDatabaseFilePath) - { - StructuresClosureCalculationInput input; - switch (calculation.InputParameters.InflowModelType) - { - case ClosingStructureInflowModelType.VerticalWall: - input = CreateClosureVerticalWallCalculationInput(calculation, failureMechanism.GeneralInput); - break; - case ClosingStructureInflowModelType.LowSill: - input = CreateLowSillCalculationInput(calculation, failureMechanism.GeneralInput); - break; - case ClosingStructureInflowModelType.FloodedCulvert: - input = CreateFloodedCulvertCalculationInput(calculation, failureMechanism.GeneralInput); - break; - default: - throw new InvalidEnumArgumentException(nameof(calculation), - (int) calculation.InputParameters.InflowModelType, - typeof(ClosingStructureInflowModelType)); - } - - HydraRingSettingsDatabaseHelper.AssignSettingsFromDatabase(input, hydraulicBoundaryDatabaseFilePath); - return input; - } - private static StructuresClosureVerticalWallCalculationInput CreateClosureVerticalWallCalculationInput( StructuresCalculation calculation, GeneralClosingStructuresInput generalInput)