Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Service/HeightStructuresCalculationService.cs =================================================================== diff -u -r1b0460d5f81926d0366ab10e4b0e9f6d75809c71 -rb2306061789f5e34a6f0994552b4431d01d220f0 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Service/HeightStructuresCalculationService.cs (.../HeightStructuresCalculationService.cs) (revision 1b0460d5f81926d0366ab10e4b0e9f6d75809c71) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Service/HeightStructuresCalculationService.cs (.../HeightStructuresCalculationService.cs) (revision b2306061789f5e34a6f0994552b4431d01d220f0) @@ -20,13 +20,16 @@ // All rights reserved. using System.Collections.Generic; +using Core.Common.Base.IO; using log4net; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Data.Probabilistics; using Ringtoets.Common.Service; using Ringtoets.HeightStructures.Data; using Ringtoets.HeightStructures.Service.Properties; +using Ringtoets.HydraRing.Calculation.Calculator; +using Ringtoets.HydraRing.Calculation.Calculator.Factory; using Ringtoets.HydraRing.Calculation.Data; using Ringtoets.HydraRing.Calculation.Data.Input.Structures; using Ringtoets.HydraRing.Calculation.Data.Output; @@ -40,18 +43,21 @@ /// /// Service that provides methods for performing Hydra-Ring calculations for height structures calculations. /// - public static class HeightStructuresCalculationService + public class HeightStructuresCalculationService { private static readonly ILog log = LogManager.GetLogger(typeof(HeightStructuresCalculationService)); + private IStructuresOvertoppingCalculator calculator; + private bool canceled; + /// /// Performs validation over the values on the given . Error and status information is logged during /// the execution of the operation. /// /// The for which to validate the values. /// The for which to validate the values. /// Truec> if has no validation errors; Falsec> otherwise. - public static bool Validate(HeightStructuresCalculation calculation, IAssessmentSection assessmentSection) + public bool Validate(HeightStructuresCalculation calculation, IAssessmentSection assessmentSection) { return CalculationServiceHelper.PerformValidation(calculation.Name, () => ValidateInput(calculation.InputParameters, assessmentSection)); } @@ -61,44 +67,61 @@ /// 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 directory of the HLCD file that should be used for performing the calculation. + /// The that holds information about the norm used in the calculation. /// The to create input with. - /// The id of the ring to perform the calculation for. /// The to create the input with for the calculation. + /// The amount of contribution for this failure mechanism in the assessment section. + /// The directory of the HLCD file that should be used for performing the calculation. /// A on a successful calculation, null otherwise. - internal static ExceedanceProbabilityCalculationOutput Calculate(HeightStructuresCalculation calculation, - string hlcdDirectory, FailureMechanismSection failureMechanismSection, - string ringId, GeneralHeightStructuresInput generalInput) + internal void Calculate(HeightStructuresCalculation calculation, + IAssessmentSection assessmentSection, + FailureMechanismSection failureMechanismSection, + GeneralHeightStructuresInput generalInput, + double failureMechanismContribution, + string hlcdDirectory) { + var calculationName = calculation.Name; + StructuresOvertoppingCalculationInput input = CreateInput(calculation, failureMechanismSection, generalInput); - var exceedanceProbabilityCalculationParser = new ExceedanceProbabilityCalculationParser(); - CalculationServiceHelper.PerformCalculation( - calculation.Name, - () => - { - HydraRingCalculationService.Instance.PerformCalculation( - hlcdDirectory, - ringId, - HydraRingUncertaintiesType.All, - input, - new[] - { - exceedanceProbabilityCalculationParser - }); + calculator = HydraRingCalculatorFactory.Instance.CreateStructuresOvertoppingCalculator(hlcdDirectory, assessmentSection.Id); - VerifyOutput(exceedanceProbabilityCalculationParser.Output, calculation.Name); - }); + CalculationServiceHelper.LogCalculationBeginTime(calculationName); - return exceedanceProbabilityCalculationParser.Output; + try + { + calculator.Calculate(input); + + if (!canceled) + { + calculation.Output = ProbabilityAssessmentService.Calculate(assessmentSection.FailureMechanismContribution.Norm, + failureMechanismContribution, + generalInput.N, + calculator.ExceedanceProbabilityBeta); + } + } + catch (HydraRingFileParserException) + { + if (!canceled) + { + log.ErrorFormat(Resources.HeightStructuresCalculationService_Calculate_Error_in_height_structures_0_calculation, calculationName); + throw; + } + } + finally + { + log.InfoFormat("Hoogte kunstwerken berekeningsverslag. Klik op details voor meer informatie.\n{0}", calculator.OutputFileContent); + CalculationServiceHelper.LogCalculationEndTime(calculationName); + } } - private static void VerifyOutput(ExceedanceProbabilityCalculationOutput output, string name) + public void Cancel() { - if (output == null) + if (calculator != null) { - log.ErrorFormat(Resources.HeightStructuresCalculationService_Calculate_Error_in_height_structures_0_calculation, name); + calculator.Cancel(); } + canceled = true; } private static StructuresOvertoppingCalculationInput CreateInput(HeightStructuresCalculation calculation, FailureMechanismSection failureMechanismSection, GeneralHeightStructuresInput generalInput)