Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/HeightStructuresPlugin.cs
===================================================================
diff -u -rd499bba7f0abdb8481bfe1ffc619414116a13121 -rb2306061789f5e34a6f0994552b4431d01d220f0
--- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/HeightStructuresPlugin.cs (.../HeightStructuresPlugin.cs) (revision d499bba7f0abdb8481bfe1ffc619414116a13121)
+++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/HeightStructuresPlugin.cs (.../HeightStructuresPlugin.cs) (revision b2306061789f5e34a6f0994552b4431d01d220f0)
@@ -182,7 +182,7 @@
{
foreach (var calculation in heightStructuresCalculations)
{
- HeightStructuresCalculationService.Validate(calculation, assessmentSection);
+ new HeightStructuresCalculationService().Validate(calculation, assessmentSection);
}
}
@@ -465,7 +465,7 @@
return builder.AddValidateCalculationItem(
context,
- c => HeightStructuresCalculationService.Validate(c.WrappedData, c.AssessmentSection),
+ c => new HeightStructuresCalculationService().Validate(c.WrappedData, c.AssessmentSection),
ValidateAllDataAvailableAndGetErrorMessageForCalculation)
.AddPerformCalculationItem(calculation, context, Calculate, ValidateAllDataAvailableAndGetErrorMessageForCalculation)
.AddClearCalculationOutputItem(calculation)
Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Service/HeightStructuresCalculationActivity.cs
===================================================================
diff -u -re3f9dffa91a0def0b6e6bc7dfabef74cc64745c5 -rb2306061789f5e34a6f0994552b4431d01d220f0
--- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Service/HeightStructuresCalculationActivity.cs (.../HeightStructuresCalculationActivity.cs) (revision e3f9dffa91a0def0b6e6bc7dfabef74cc64745c5)
+++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Service/HeightStructuresCalculationActivity.cs (.../HeightStructuresCalculationActivity.cs) (revision b2306061789f5e34a6f0994552b4431d01d220f0)
@@ -33,12 +33,13 @@
///
/// for running a height structures calculation.
///
- public class HeightStructuresCalculationActivity : HydraRingActivity
+ public class HeightStructuresCalculationActivity : HydraRingActivityBase
{
private readonly HeightStructuresCalculation calculation;
private readonly string hlcdDirectory;
private readonly HeightStructuresFailureMechanism failureMechanism;
private readonly IAssessmentSection assessmentSection;
+ private readonly HeightStructuresCalculationService calculationService;
///
/// Creates a new instance of .
@@ -73,31 +74,38 @@
this.failureMechanism = failureMechanism;
this.assessmentSection = assessmentSection;
+ calculationService = new HeightStructuresCalculationService();
+
Name = calculation.Name;
}
- protected override void OnRun()
+ protected override bool Validate()
{
+ return calculationService.Validate(calculation, assessmentSection);
+ }
+
+ protected override void PerformCalculation()
+ {
+ HeightStructuresDataSynchronizationService.ClearCalculationOutput(calculation);
+
var failureMechanismSection = failureMechanism.Sections.First(); // TODO: Obtain dike section based on cross section of structure with reference line
- PerformRun(() => HeightStructuresCalculationService.Validate(calculation, assessmentSection),
- () => HeightStructuresDataSynchronizationService.ClearCalculationOutput(calculation),
- () => HeightStructuresCalculationService.Calculate(calculation,
- hlcdDirectory,
- failureMechanismSection,
- assessmentSection.Id,
- failureMechanism.GeneralInput));
+ calculationService.Calculate(calculation,
+ assessmentSection,
+ failureMechanismSection,
+ failureMechanism.GeneralInput,
+ failureMechanism.Contribution,
+ hlcdDirectory);
+
}
+ protected override void OnCancel()
+ {
+ calculationService.Cancel();
+ }
+
protected override void OnFinish()
{
- PerformFinish(() =>
- {
- calculation.Output = ProbabilityAssessmentService.Calculate(assessmentSection.FailureMechanismContribution.Norm,
- failureMechanism.Contribution,
- failureMechanism.GeneralInput.N,
- Output.Beta);
- });
calculation.NotifyObservers();
}
}
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)
Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/TreeNodeInfos/HeightStructuresCalculationContextTreeNodeInfoTest.cs
===================================================================
diff -u -rd689ea05c1014eb4d51b927e11eb6c48255f0a47 -rb2306061789f5e34a6f0994552b4431d01d220f0
--- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/TreeNodeInfos/HeightStructuresCalculationContextTreeNodeInfoTest.cs (.../HeightStructuresCalculationContextTreeNodeInfoTest.cs) (revision d689ea05c1014eb4d51b927e11eb6c48255f0a47)
+++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/TreeNodeInfos/HeightStructuresCalculationContextTreeNodeInfoTest.cs (.../HeightStructuresCalculationContextTreeNodeInfoTest.cs) (revision b2306061789f5e34a6f0994552b4431d01d220f0)
@@ -638,8 +638,8 @@
StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", calculation.Name), msgs[0]);
StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", calculation.Name), msgs[1]);
StringAssert.StartsWith(string.Format("Berekening van '{0}' gestart om: ", calculation.Name), msgs[2]);
- StringAssert.StartsWith("Hydra-Ring berekeningsverslag. Klik op details voor meer informatie.", msgs[3]);
- StringAssert.StartsWith(string.Format("De berekening voor hoogte kunstwerk '{0}' is niet gelukt.", calculation.Name), msgs[4]);
+ StringAssert.StartsWith(string.Format("De berekening voor hoogte kunstwerk '{0}' is niet gelukt.", calculation.Name), msgs[3]);
+ StringAssert.StartsWith("Hoogte kunstwerken berekeningsverslag. Klik op details voor meer informatie.", msgs[4]);
StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", calculation.Name), msgs[5]);
StringAssert.StartsWith(string.Format("Uitvoeren van '{0}' is mislukt.", calculation.Name), msgs[6]);
});
Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/TreeNodeInfos/HeightStructuresCalculationGroupContextTreeNodeInfoTest.cs
===================================================================
diff -u -r82daf7501673e736db81576d6cf2cad2b4450e21 -rb2306061789f5e34a6f0994552b4431d01d220f0
--- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/TreeNodeInfos/HeightStructuresCalculationGroupContextTreeNodeInfoTest.cs (.../HeightStructuresCalculationGroupContextTreeNodeInfoTest.cs) (revision 82daf7501673e736db81576d6cf2cad2b4450e21)
+++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/TreeNodeInfos/HeightStructuresCalculationGroupContextTreeNodeInfoTest.cs (.../HeightStructuresCalculationGroupContextTreeNodeInfoTest.cs) (revision b2306061789f5e34a6f0994552b4431d01d220f0)
@@ -821,14 +821,14 @@
StringAssert.StartsWith("Validatie van 'A' gestart om: ", messageList[0]);
StringAssert.StartsWith("Validatie van 'A' beëindigd om: ", messageList[1]);
StringAssert.StartsWith("Berekening van 'A' gestart om: ", messageList[2]);
- StringAssert.StartsWith("Hydra-Ring berekeningsverslag. Klik op details voor meer informatie.", messageList[3]);
- Assert.AreEqual("De berekening voor hoogte kunstwerk 'A' is niet gelukt.", messageList[4]);
+ Assert.AreEqual("De berekening voor hoogte kunstwerk 'A' is niet gelukt.", messageList[3]);
+ StringAssert.StartsWith("Hoogte kunstwerken berekeningsverslag. Klik op details voor meer informatie.", messageList[4]);
StringAssert.StartsWith("Berekening van 'A' beëindigd om: ", messageList[5]);
StringAssert.StartsWith("Validatie van 'B' gestart om: ", messageList[6]);
StringAssert.StartsWith("Validatie van 'B' beëindigd om: ", messageList[7]);
StringAssert.StartsWith("Berekening van 'B' gestart om: ", messageList[8]);
- StringAssert.StartsWith("Hydra-Ring berekeningsverslag. Klik op details voor meer informatie.", messageList[9]);
- Assert.AreEqual("De berekening voor hoogte kunstwerk 'B' is niet gelukt.", messageList[10]);
+ Assert.AreEqual("De berekening voor hoogte kunstwerk 'B' is niet gelukt.", messageList[9]);
+ StringAssert.StartsWith("Hoogte kunstwerken berekeningsverslag. Klik op details voor meer informatie.", messageList[10]);
StringAssert.StartsWith("Berekening van 'B' beëindigd om: ", messageList[11]);
Assert.AreEqual("Uitvoeren van 'A' is mislukt.", messageList[12]);
Assert.AreEqual("Uitvoeren van 'B' is mislukt.", messageList[13]);
Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/TreeNodeInfos/HeightStructuresFailureMechanismContextTreeNodeInfoTest.cs
===================================================================
diff -u -rdd72cf407b7d0e9284d101bb2e2854e569b1a29a -rb2306061789f5e34a6f0994552b4431d01d220f0
--- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/TreeNodeInfos/HeightStructuresFailureMechanismContextTreeNodeInfoTest.cs (.../HeightStructuresFailureMechanismContextTreeNodeInfoTest.cs) (revision dd72cf407b7d0e9284d101bb2e2854e569b1a29a)
+++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/TreeNodeInfos/HeightStructuresFailureMechanismContextTreeNodeInfoTest.cs (.../HeightStructuresFailureMechanismContextTreeNodeInfoTest.cs) (revision b2306061789f5e34a6f0994552b4431d01d220f0)
@@ -775,14 +775,14 @@
StringAssert.StartsWith("Validatie van 'A' gestart om: ", messageList[0]);
StringAssert.StartsWith("Validatie van 'A' beëindigd om: ", messageList[1]);
StringAssert.StartsWith("Berekening van 'A' gestart om: ", messageList[2]);
- StringAssert.StartsWith("Hydra-Ring berekeningsverslag. Klik op details voor meer informatie.", messageList[3]);
- Assert.AreEqual("De berekening voor hoogte kunstwerk 'A' is niet gelukt.", messageList[4]);
+ Assert.AreEqual("De berekening voor hoogte kunstwerk 'A' is niet gelukt.", messageList[3]);
+ StringAssert.StartsWith("Hoogte kunstwerken berekeningsverslag. Klik op details voor meer informatie.", messageList[4]);
StringAssert.StartsWith("Berekening van 'A' beëindigd om: ", messageList[5]);
StringAssert.StartsWith("Validatie van 'B' gestart om: ", messageList[6]);
StringAssert.StartsWith("Validatie van 'B' beëindigd om: ", messageList[7]);
StringAssert.StartsWith("Berekening van 'B' gestart om: ", messageList[8]);
- StringAssert.StartsWith("Hydra-Ring berekeningsverslag. Klik op details voor meer informatie.", messageList[9]);
- Assert.AreEqual("De berekening voor hoogte kunstwerk 'B' is niet gelukt.", messageList[10]);
+ Assert.AreEqual("De berekening voor hoogte kunstwerk 'B' is niet gelukt.", messageList[9]);
+ StringAssert.StartsWith("Hoogte kunstwerken berekeningsverslag. Klik op details voor meer informatie.", messageList[10]);
StringAssert.StartsWith("Berekening van 'B' beëindigd om: ", messageList[11]);
Assert.AreEqual("Uitvoeren van 'A' is mislukt.", messageList[12]);
Assert.AreEqual("Uitvoeren van 'B' is mislukt.", messageList[13]);
Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Integration.Test/HeightStructuresCalculationActivityIntegrationTest.cs
===================================================================
diff -u -rf27092df1f897798c4a0b24f6fc91f49c9f294ce -rb2306061789f5e34a6f0994552b4431d01d220f0
--- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Integration.Test/HeightStructuresCalculationActivityIntegrationTest.cs (.../HeightStructuresCalculationActivityIntegrationTest.cs) (revision f27092df1f897798c4a0b24f6fc91f49c9f294ce)
+++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Integration.Test/HeightStructuresCalculationActivityIntegrationTest.cs (.../HeightStructuresCalculationActivityIntegrationTest.cs) (revision b2306061789f5e34a6f0994552b4431d01d220f0)
@@ -161,8 +161,8 @@
StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", calculation.Name), msgs[0]);
StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", calculation.Name), msgs[1]);
StringAssert.StartsWith(string.Format("Berekening van '{0}' gestart om: ", calculation.Name), msgs[2]);
- StringAssert.StartsWith("Hydra-Ring berekeningsverslag. Klik op details voor meer informatie.", msgs[3]);
StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", calculation.Name), msgs[4]);
+ StringAssert.StartsWith("Hoogte kunstwerken berekeningsverslag. Klik op details voor meer informatie.", msgs[3]);
});
Assert.AreEqual(ActivityState.Executed, activity.State);
}
@@ -208,8 +208,8 @@
StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", calculation.Name), msgs[0]);
StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", calculation.Name), msgs[1]);
StringAssert.StartsWith(string.Format("Berekening van '{0}' gestart om: ", calculation.Name), msgs[2]);
- StringAssert.StartsWith("Hydra-Ring berekeningsverslag. Klik op details voor meer informatie.", msgs[3]);
- StringAssert.StartsWith(string.Format("De berekening voor hoogte kunstwerk '{0}' is niet gelukt.", calculation.Name), msgs[4]);
+ StringAssert.StartsWith(string.Format("De berekening voor hoogte kunstwerk '{0}' is niet gelukt.", calculation.Name), msgs[3]);
+ StringAssert.StartsWith("Hoogte kunstwerken berekeningsverslag. Klik op details voor meer informatie.", msgs[4]);
StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", calculation.Name), msgs[5]);
});
Assert.AreEqual(ActivityState.Failed, activity.State);
Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Integration.Test/HeightStructuresCalculationServiceIntegrationTest.cs
===================================================================
diff -u -rf27092df1f897798c4a0b24f6fc91f49c9f294ce -rb2306061789f5e34a6f0994552b4431d01d220f0
--- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Integration.Test/HeightStructuresCalculationServiceIntegrationTest.cs (.../HeightStructuresCalculationServiceIntegrationTest.cs) (revision f27092df1f897798c4a0b24f6fc91f49c9f294ce)
+++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Integration.Test/HeightStructuresCalculationServiceIntegrationTest.cs (.../HeightStructuresCalculationServiceIntegrationTest.cs) (revision b2306061789f5e34a6f0994552b4431d01d220f0)
@@ -57,7 +57,7 @@
// Call
bool isValid = false;
- Action call = () => isValid = HeightStructuresCalculationService.Validate(calculation, assessmentSection);
+ Action call = () => isValid = new HeightStructuresCalculationService().Validate(calculation, assessmentSection);
// Assert
TestHelper.AssertLogMessages(call, messages =>
@@ -96,7 +96,7 @@
// Call
bool isValid = false;
- Action call = () => isValid = HeightStructuresCalculationService.Validate(calculation, assessmentSection);
+ Action call = () => isValid = new HeightStructuresCalculationService().Validate(calculation, assessmentSection);
// Assert
TestHelper.AssertLogMessages(call, messages =>
@@ -130,7 +130,7 @@
// Call
bool isValid = false;
- Action call = () => isValid = HeightStructuresCalculationService.Validate(calculation, assessmentSection);
+ Action call = () => isValid = new HeightStructuresCalculationService().Validate(calculation, assessmentSection);
// Assert
TestHelper.AssertLogMessages(call, messages =>
@@ -165,25 +165,29 @@
};
var failureMechanismSection = assessmentSection.HeightStructures.Sections.First();
- ExceedanceProbabilityCalculationOutput output = null;
// Call
- Action call = () => output = HeightStructuresCalculationService.Calculate(calculation, testDataPath, failureMechanismSection, failureMechanismSection.Name, assessmentSection.HeightStructures.GeneralInput);
+ Action call = () => new HeightStructuresCalculationService().Calculate(calculation,
+ assessmentSection,
+ failureMechanismSection,
+ assessmentSection.HeightStructures.GeneralInput,
+ assessmentSection.HeightStructures.Contribution,
+ testDataPath);
// Assert
TestHelper.AssertLogMessages(call, messages =>
{
var msgs = messages.ToArray();
Assert.AreEqual(3, msgs.Length);
StringAssert.StartsWith(string.Format("Berekening van '{0}' gestart om: ", calculation.Name), msgs[0]);
- StringAssert.StartsWith("Hydra-Ring berekeningsverslag. Klik op details voor meer informatie.", msgs[1]);
+ StringAssert.StartsWith("Hoogte kunstwerken berekeningsverslag. Klik op details voor meer informatie.", msgs[1]);
StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", calculation.Name), msgs[2]);
});
- Assert.IsNotNull(output);
+ Assert.IsNotNull(calculation.Output);
}
[Test]
- public void Calculate_InvalidCalculation_LogStartAndEndAndErrorMessageAndReturnNull()
+ public void Calculate_InvalidCalculation_LogStartAndEndAndErrorMessageAndThrowsException()
{
// Setup
var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike);
@@ -204,22 +208,38 @@
};
var failureMechanismSection = assessmentSection.HeightStructures.Sections.First();
- ExceedanceProbabilityCalculationOutput output = null;
+ var exception = false;
// Call
- Action call = () => output = HeightStructuresCalculationService.Calculate(calculation, testDataPath, failureMechanismSection, failureMechanismSection.Name, assessmentSection.HeightStructures.GeneralInput);
+ Action call = () =>
+ {
+ try
+ {
+ new HeightStructuresCalculationService().Calculate(calculation,
+ assessmentSection,
+ failureMechanismSection,
+ assessmentSection.HeightStructures.GeneralInput,
+ assessmentSection.HeightStructures.Contribution,
+ testDataPath);
+ }
+ catch
+ {
+ exception = true;
+ }
+ };
// Assert
TestHelper.AssertLogMessages(call, messages =>
{
var msgs = messages.ToArray();
Assert.AreEqual(4, msgs.Length);
StringAssert.StartsWith(string.Format("Berekening van '{0}' gestart om: ", calculation.Name), msgs[0]);
- StringAssert.StartsWith("Hydra-Ring berekeningsverslag. Klik op details voor meer informatie.", msgs[1]);
- StringAssert.StartsWith(string.Format("De berekening voor hoogte kunstwerk '{0}' is niet gelukt.", calculation.Name), msgs[2]);
+ StringAssert.StartsWith(string.Format("De berekening voor hoogte kunstwerk '{0}' is niet gelukt.", calculation.Name), msgs[1]);
+ StringAssert.StartsWith("Hoogte kunstwerken berekeningsverslag. Klik op details voor meer informatie.", msgs[2]);
StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", calculation.Name), msgs[3]);
});
- Assert.IsNull(output);
+ Assert.IsNull(calculation.Output);
+ Assert.IsTrue(exception);
}
private void ImportHydraulicBoundaryDatabase(AssessmentSection assessmentSection)
Index: Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Calculator/Factory/HydraRingCalculatorFactory.cs
===================================================================
diff -u -r1b0460d5f81926d0366ab10e4b0e9f6d75809c71 -rb2306061789f5e34a6f0994552b4431d01d220f0
--- Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Calculator/Factory/HydraRingCalculatorFactory.cs (.../HydraRingCalculatorFactory.cs) (revision 1b0460d5f81926d0366ab10e4b0e9f6d75809c71)
+++ Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Calculator/Factory/HydraRingCalculatorFactory.cs (.../HydraRingCalculatorFactory.cs) (revision b2306061789f5e34a6f0994552b4431d01d220f0)
@@ -72,5 +72,10 @@
{
return new WaveHeightCalculator(hlcdDirectory, ringId);
}
+
+ public IStructuresOvertoppingCalculator CreateStructuresOvertoppingCalculator(string hlcdDirectory, string ringId)
+ {
+ return new StructuresOvertoppingCalculator(hlcdDirectory, ringId);
+ }
}
}
\ No newline at end of file
Index: Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Calculator/Factory/IHydraRingCalculatorFactory.cs
===================================================================
diff -u -r1b0460d5f81926d0366ab10e4b0e9f6d75809c71 -rb2306061789f5e34a6f0994552b4431d01d220f0
--- Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Calculator/Factory/IHydraRingCalculatorFactory.cs (.../IHydraRingCalculatorFactory.cs) (revision 1b0460d5f81926d0366ab10e4b0e9f6d75809c71)
+++ Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Calculator/Factory/IHydraRingCalculatorFactory.cs (.../IHydraRingCalculatorFactory.cs) (revision b2306061789f5e34a6f0994552b4431d01d220f0)
@@ -66,5 +66,13 @@
/// The id of the traject which is used in the calculation.
/// A new .
IWaveHeightCalculator CreateWaveHeightCalculator(string hlcdDirectory, string ringId);
+
+ ///
+ /// Creates a calculator for performing an overtopping calculation for structures.
+ ///
+ /// The directory where the hydraulic database can be found.
+ /// The id of the traject which is used in the calculation.
+ /// A new .
+ IStructuresOvertoppingCalculator CreateStructuresOvertoppingCalculator(string hlcdDirectory, string ringId);
}
}
\ No newline at end of file
Index: Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Calculator/IOvertoppingCalculator.cs
===================================================================
diff -u -r1b0460d5f81926d0366ab10e4b0e9f6d75809c71 -rb2306061789f5e34a6f0994552b4431d01d220f0
--- Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Calculator/IOvertoppingCalculator.cs (.../IOvertoppingCalculator.cs) (revision 1b0460d5f81926d0366ab10e4b0e9f6d75809c71)
+++ Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Calculator/IOvertoppingCalculator.cs (.../IOvertoppingCalculator.cs) (revision b2306061789f5e34a6f0994552b4431d01d220f0)
@@ -27,8 +27,8 @@
/// Interface for a calculator which calculates probability of failure by overtopping or overflow
/// and the associated wave height.
///
- public interface IOvertoppingCalculator {
-
+ public interface IOvertoppingCalculator
+ {
///
/// Gets the probability of failure.
///
Index: Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Calculator/IStructuresOvertoppingCalculator.cs
===================================================================
diff -u
--- Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Calculator/IStructuresOvertoppingCalculator.cs (revision 0)
+++ Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Calculator/IStructuresOvertoppingCalculator.cs (revision b2306061789f5e34a6f0994552b4431d01d220f0)
@@ -0,0 +1,50 @@
+// Copyright (C) Stichting Deltares 2016. All rights reserved.
+//
+// This file is part of Ringtoets.
+//
+// Ringtoets is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+using Ringtoets.HydraRing.Calculation.Data.Input.Structures;
+
+namespace Ringtoets.HydraRing.Calculation.Calculator
+{
+ public interface IStructuresOvertoppingCalculator
+ {
+ ///
+ /// Gets the probability of failure.
+ ///
+ double ExceedanceProbabilityBeta { get; }
+
+ ///
+ /// Gets the content of the output file generated during the Hydra-Ring calculation.
+ ///
+ string OutputFileContent { get; }
+
+ ///
+ /// Performs the actual calculation by running the Hydra-Ring executable.
+ ///
+ /// The which contains all the necessary input
+ /// for the calculation.
+ void Calculate(StructuresOvertoppingCalculationInput input);
+
+ ///
+ /// Cancels any currently running Hydra-Ring calculation.
+ ///
+ void Cancel();
+ }
+}
\ No newline at end of file
Index: Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Calculator/StructuresOvertoppingCalculator.cs
===================================================================
diff -u
--- Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Calculator/StructuresOvertoppingCalculator.cs (revision 0)
+++ Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Calculator/StructuresOvertoppingCalculator.cs (revision b2306061789f5e34a6f0994552b4431d01d220f0)
@@ -0,0 +1,69 @@
+// Copyright (C) Stichting Deltares 2016. All rights reserved.
+//
+// This file is part of Ringtoets.
+//
+// Ringtoets is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+using System.Collections.Generic;
+using Ringtoets.HydraRing.Calculation.Data;
+using Ringtoets.HydraRing.Calculation.Data.Input.Structures;
+using Ringtoets.HydraRing.Calculation.Parsers;
+
+namespace Ringtoets.HydraRing.Calculation.Calculator
+{
+ public class StructuresOvertoppingCalculator : HydraRingCalculatorBase, IStructuresOvertoppingCalculator
+ {
+ private readonly string hlcdDirectory;
+ private readonly string ringId;
+ private readonly ExceedanceProbabilityCalculationParser exceedanceProbabilityCalculationParser;
+
+ ///
+ /// Create a new instance of .
+ ///
+ /// The directory in which the Hydraulic Boundary Database can be found.
+ /// The id of the traject which is used in the calculation.
+ internal StructuresOvertoppingCalculator(string hlcdDirectory, string ringId)
+ {
+ this.hlcdDirectory = hlcdDirectory;
+ this.ringId = ringId;
+ exceedanceProbabilityCalculationParser = new ExceedanceProbabilityCalculationParser();
+
+ ExceedanceProbabilityBeta = double.NaN;
+ }
+
+ public double ExceedanceProbabilityBeta { get; set; }
+
+ public void Calculate(StructuresOvertoppingCalculationInput input)
+ {
+ Calculate(hlcdDirectory, ringId, HydraRingUncertaintiesType.All, input);
+ }
+
+ protected override IEnumerable GetParsers()
+ {
+ yield return exceedanceProbabilityCalculationParser;
+ }
+
+ protected override void SetOutputs()
+ {
+ if (exceedanceProbabilityCalculationParser.Output != null)
+ {
+ ExceedanceProbabilityBeta = exceedanceProbabilityCalculationParser.Output.Beta;
+ }
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Ringtoets.HydraRing.Calculation.csproj
===================================================================
diff -u -r1b0460d5f81926d0366ab10e4b0e9f6d75809c71 -rb2306061789f5e34a6f0994552b4431d01d220f0
--- Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Ringtoets.HydraRing.Calculation.csproj (.../Ringtoets.HydraRing.Calculation.csproj) (revision 1b0460d5f81926d0366ab10e4b0e9f6d75809c71)
+++ Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Ringtoets.HydraRing.Calculation.csproj (.../Ringtoets.HydraRing.Calculation.csproj) (revision b2306061789f5e34a6f0994552b4431d01d220f0)
@@ -52,8 +52,10 @@
+
+
Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.TestUtil/Calculator/TestHydraRingCalculatorFactory.cs
===================================================================
diff -u -r02670d8c9fceeaea5f829937a2eb269f3488c6b1 -rb2306061789f5e34a6f0994552b4431d01d220f0
--- Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.TestUtil/Calculator/TestHydraRingCalculatorFactory.cs (.../TestHydraRingCalculatorFactory.cs) (revision 02670d8c9fceeaea5f829937a2eb269f3488c6b1)
+++ Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.TestUtil/Calculator/TestHydraRingCalculatorFactory.cs (.../TestHydraRingCalculatorFactory.cs) (revision b2306061789f5e34a6f0994552b4431d01d220f0)
@@ -24,6 +24,7 @@
using Ringtoets.HydraRing.Calculation.Calculator.Factory;
using Ringtoets.HydraRing.Calculation.Data.Input.Hydraulics;
using Ringtoets.HydraRing.Calculation.Data.Input.Overtopping;
+using Ringtoets.HydraRing.Calculation.Data.Input.Structures;
using Ringtoets.HydraRing.Calculation.Data.Input.WaveConditions;
using Ringtoets.HydraRing.Calculation.Parsers;
@@ -36,6 +37,7 @@
public readonly TestOvertoppingCalculator OvertoppingCalculator = new TestOvertoppingCalculator();
public readonly TestWaveConditionsCosineCalculator WaveConditionsCosineCalculator = new TestWaveConditionsCosineCalculator();
public readonly TestWaveHeightCalculator WaveHeightCalculator = new TestWaveHeightCalculator();
+ public readonly TestStructuresOvertoppingCalculator StructuresOvertoppingCalculator = new TestStructuresOvertoppingCalculator();
public IDesignWaterLevelCalculator CreateDesignWaterLevelCalculator(string hlcdDirectory, string ringId)
{
@@ -71,6 +73,13 @@
WaveHeightCalculator.RingId = ringId;
return WaveHeightCalculator;
}
+
+ public IStructuresOvertoppingCalculator CreateStructuresOvertoppingCalculator(string hlcdDirectory, string ringId)
+ {
+ StructuresOvertoppingCalculator.HydraulicBoundaryDatabaseDirectory = hlcdDirectory;
+ StructuresOvertoppingCalculator.RingId = ringId;
+ return StructuresOvertoppingCalculator;
+ }
}
public class TestWaveHeightCalculator : TestHydraRingCalculator, IWaveHeightCalculator
@@ -107,6 +116,11 @@
public string OutputFileContent { get; set; }
}
+ public class TestStructuresOvertoppingCalculator : TestHydraRingCalculator, IStructuresOvertoppingCalculator {
+ public double ExceedanceProbabilityBeta { get; set; }
+ public string OutputFileContent { get; set; }
+ }
+
public class TestHydraRingCalculator
{
public bool IsCanceled = false;