Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Service/ClosingStructuresCalculationService.cs =================================================================== diff -u -re39274536935505756861bab61ab2e379162b33e -r3e9eb63e09c270127a0db49f2dea3da5ff3a3639 --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Service/ClosingStructuresCalculationService.cs (.../ClosingStructuresCalculationService.cs) (revision e39274536935505756861bab61ab2e379162b33e) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Service/ClosingStructuresCalculationService.cs (.../ClosingStructuresCalculationService.cs) (revision 3e9eb63e09c270127a0db49f2dea3da5ff3a3639) @@ -123,7 +123,7 @@ finally { var lastErrorFileContent = calculator.LastErrorFileContent; - bool errorOccurred = ErrorOccurred(exceptionThrown, lastErrorFileContent); + bool errorOccurred = CalculationServiceHelper.ErrorOccurred(canceled, exceptionThrown, lastErrorFileContent); if (errorOccurred) { log.ErrorFormat(Resources.ClosingStructuresCalculationService_Calculate_Error_in_closing_structures_0_calculation_click_details_for_last_error_1, @@ -171,11 +171,6 @@ return !messages.Any(); } - private bool ErrorOccurred(bool exceptionThrown, string lastErrorContent) - { - return !canceled && !exceptionThrown && !string.IsNullOrEmpty(lastErrorContent); - } - private static StructuresClosureCalculationInput CreateStructuresClosureCalculationInput( StructuresCalculation calculation, ClosingStructuresFailureMechanism failureMechanism, Index: Ringtoets/Common/src/Ringtoets.Common.Service/CalculationServiceHelper.cs =================================================================== diff -u -re69acb9595f7bf1d202ddd1fb51934b66768b75d -r3e9eb63e09c270127a0db49f2dea3da5ff3a3639 --- Ringtoets/Common/src/Ringtoets.Common.Service/CalculationServiceHelper.cs (.../CalculationServiceHelper.cs) (revision e69acb9595f7bf1d202ddd1fb51934b66768b75d) +++ Ringtoets/Common/src/Ringtoets.Common.Service/CalculationServiceHelper.cs (.../CalculationServiceHelper.cs) (revision 3e9eb63e09c270127a0db49f2dea3da5ff3a3639) @@ -95,5 +95,18 @@ log.Info(string.Format(Resources.Calculation_Subject_0_ended_Time_1_, name, DateTimeService.CurrentTimeAsString)); } + + /// + /// Determines whether an error has occurred during the calculation. + /// + /// The canceled state of the calculation. + /// Indicator if there is already an exception thrown in the calculation. + /// The contents of the last error file. + /// true when a calculation isn't canceled, has not already thrown an exception and + /// is set. false otherwise. + public static bool ErrorOccurred(bool canceled, bool exceptionThrown, string lastErrorFileContent) + { + return !canceled && !exceptionThrown && !string.IsNullOrEmpty(lastErrorFileContent); + } } } \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Service/DesignWaterLevelCalculationService.cs =================================================================== diff -u -re39274536935505756861bab61ab2e379162b33e -r3e9eb63e09c270127a0db49f2dea3da5ff3a3639 --- Ringtoets/Common/src/Ringtoets.Common.Service/DesignWaterLevelCalculationService.cs (.../DesignWaterLevelCalculationService.cs) (revision e39274536935505756861bab61ab2e379162b33e) +++ Ringtoets/Common/src/Ringtoets.Common.Service/DesignWaterLevelCalculationService.cs (.../DesignWaterLevelCalculationService.cs) (revision 3e9eb63e09c270127a0db49f2dea3da5ff3a3639) @@ -120,7 +120,7 @@ finally { var lastErrorFileContent = calculator.LastErrorFileContent; - bool errorOccurred = ErrorOccurred(exceptionThrown, lastErrorFileContent); + bool errorOccurred = CalculationServiceHelper.ErrorOccurred(canceled, exceptionThrown, lastErrorFileContent); if (errorOccurred) { log.Error(messageProvider.GetCalculationFailedMessage(hydraulicBoundaryLocation.Name, lastErrorFileContent)); @@ -148,11 +148,6 @@ } } - private bool ErrorOccurred(bool exceptionThrown, string lastErrorFileContent) - { - return !canceled && !exceptionThrown && !string.IsNullOrEmpty(lastErrorFileContent); - } - private AssessmentLevelCalculationInput CreateInput(HydraulicBoundaryLocation hydraulicBoundaryLocation, double norm, string hydraulicBoundaryDatabaseFilePath) { var assessmentLevelCalculationInput = new AssessmentLevelCalculationInput(1, hydraulicBoundaryLocation.Id, norm); Index: Ringtoets/Common/src/Ringtoets.Common.Service/WaveHeightCalculationService.cs =================================================================== diff -u -re39274536935505756861bab61ab2e379162b33e -r3e9eb63e09c270127a0db49f2dea3da5ff3a3639 --- Ringtoets/Common/src/Ringtoets.Common.Service/WaveHeightCalculationService.cs (.../WaveHeightCalculationService.cs) (revision e39274536935505756861bab61ab2e379162b33e) +++ Ringtoets/Common/src/Ringtoets.Common.Service/WaveHeightCalculationService.cs (.../WaveHeightCalculationService.cs) (revision 3e9eb63e09c270127a0db49f2dea3da5ff3a3639) @@ -121,7 +121,7 @@ finally { var lastErrorFileContent = calculator.LastErrorFileContent; - bool errorOccurred = ErrorOccurred(exceptionThrown, lastErrorFileContent); + bool errorOccurred = CalculationServiceHelper.ErrorOccurred(canceled, exceptionThrown, lastErrorFileContent); if (errorOccurred) { log.Error(messageProvider.GetCalculationFailedMessage(hydraulicBoundaryLocation.Name, lastErrorFileContent)); @@ -149,11 +149,6 @@ } } - private bool ErrorOccurred(bool exceptionThrown, string lastErrorFileContent) - { - return !canceled && !exceptionThrown && !string.IsNullOrEmpty(lastErrorFileContent); - } - private WaveHeightCalculationInput CreateInput(HydraulicBoundaryLocation hydraulicBoundaryLocation, double norm, string hydraulicBoundaryDatabaseFilePath) { var waveHeightCalculationInput = new WaveHeightCalculationInput(1, hydraulicBoundaryLocation.Id, norm); Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/CalculationServiceHelperTest.cs =================================================================== diff -u -re69acb9595f7bf1d202ddd1fb51934b66768b75d -r3e9eb63e09c270127a0db49f2dea3da5ff3a3639 --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/CalculationServiceHelperTest.cs (.../CalculationServiceHelperTest.cs) (revision e69acb9595f7bf1d202ddd1fb51934b66768b75d) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/CalculationServiceHelperTest.cs (.../CalculationServiceHelperTest.cs) (revision 3e9eb63e09c270127a0db49f2dea3da5ff3a3639) @@ -138,6 +138,44 @@ }); } + [Test] + public void ErrorOccurred_CalculationNotCanceledOrExceptionThrownLastErrorSet_ReturnTrue() + { + // Call + bool errorOccurred = CalculationServiceHelper.ErrorOccurred(false, false, "An error has occurred."); + + // Assert + Assert.IsTrue(errorOccurred); + } + + [Test] + [TestCase(null)] + [TestCase("")] + public void ErrorOccurred_CalculationNotCanceledOrExceptionThrownLastErrorNotSet_ReturnFalse(string errorContent) + { + // Call + bool errorOccurred = CalculationServiceHelper.ErrorOccurred(false, false, errorContent); + + // Assert + Assert.IsFalse(errorOccurred); + } + + [Test] + [TestCase(true, true, "An error has occurred.")] + [TestCase(true, false, "An error has occurred.")] + [TestCase(false, true, "An error has occurred.")] + [TestCase(true, true, "")] + [TestCase(true, false, "")] + [TestCase(false, true, "")] + public void ErrorOccurred_LastErrorSetCalculationCanceldOrExceptionThrown_ReturnFalse(bool canceled, bool exceptionThrown, string errorContent) + { + // Call + bool errorOccurred = CalculationServiceHelper.ErrorOccurred(canceled, exceptionThrown, errorContent); + + // Assert + Assert.IsFalse(errorOccurred); + } + private static void AssertLogTime(string message, DateTime dateTime) { string[] logMessageArray = message.Split(':'); Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/GrassCoverErosionInwardsCalculationService.cs =================================================================== diff -u -re39274536935505756861bab61ab2e379162b33e -r3e9eb63e09c270127a0db49f2dea3da5ff3a3639 --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/GrassCoverErosionInwardsCalculationService.cs (.../GrassCoverErosionInwardsCalculationService.cs) (revision e39274536935505756861bab61ab2e379162b33e) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/GrassCoverErosionInwardsCalculationService.cs (.../GrassCoverErosionInwardsCalculationService.cs) (revision 3e9eb63e09c270127a0db49f2dea3da5ff3a3639) @@ -190,7 +190,7 @@ finally { var lastErrorFileContent = overtoppingCalculator.LastErrorFileContent; - bool errorOccurred = ErrorOccurred(exceptionThrown, lastErrorFileContent); + bool errorOccurred = CalculationServiceHelper.ErrorOccurred(canceled, exceptionThrown, lastErrorFileContent); if (errorOccurred) { log.ErrorFormat(Resources.GrassCoverErosionInwardsCalculationService_Calculate_Error_in_grass_cover_erosion_inwards_0_calculation_click_details_for_last_error_1, calculationName, lastErrorFileContent); @@ -235,7 +235,7 @@ finally { var lastErrorFileContent = dikeHeightCalculator.LastErrorFileContent; - if (ErrorOccurred(exceptionThrown, lastErrorFileContent)) + if (CalculationServiceHelper.ErrorOccurred(canceled, exceptionThrown, lastErrorFileContent)) { log.ErrorFormat(Resources.GrassCoverErosionInwardsCalculationService_Calculate_Error_in_hbn_grass_cover_erosion_inwards_0_calculation_click_details_for_last_error_1, calculationName, lastErrorFileContent); } @@ -245,11 +245,6 @@ } } - private bool ErrorOccurred(bool exceptionThrown, string lastErrorFileContent) - { - return !canceled && !exceptionThrown && !string.IsNullOrEmpty(lastErrorFileContent); - } - private static OvertoppingCalculationInput CreateOvertoppingInput(GrassCoverErosionInwardsCalculation calculation, FailureMechanismSection failureMechanismSection, GeneralGrassCoverErosionInwardsInput generalInput, Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Service/HeightStructuresCalculationService.cs =================================================================== diff -u -re39274536935505756861bab61ab2e379162b33e -r3e9eb63e09c270127a0db49f2dea3da5ff3a3639 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Service/HeightStructuresCalculationService.cs (.../HeightStructuresCalculationService.cs) (revision e39274536935505756861bab61ab2e379162b33e) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Service/HeightStructuresCalculationService.cs (.../HeightStructuresCalculationService.cs) (revision 3e9eb63e09c270127a0db49f2dea3da5ff3a3639) @@ -147,7 +147,7 @@ finally { var lastErrorFileContent = calculator.LastErrorFileContent; - bool errorOccurred = ErrorOccurred(exceptionThrown, lastErrorFileContent); + bool errorOccurred = CalculationServiceHelper.ErrorOccurred(canceled, exceptionThrown, lastErrorFileContent); if (errorOccurred) { log.ErrorFormat(Resources.HeightStructuresCalculationService_Calculate_Error_in_height_structures_0_calculation_click_details_for_last_error_1, @@ -164,11 +164,6 @@ } } - private bool ErrorOccurred(bool exceptionThrown, string lastErrorFileContent) - { - return !canceled && !exceptionThrown && !string.IsNullOrEmpty(lastErrorFileContent); - } - private static StructuresOvertoppingCalculationInput CreateInput( StructuresCalculation calculation, FailureMechanismSection failureMechanismSection, Index: Ringtoets/Revetment/src/Ringtoets.Revetment.Service/WaveConditionsCalculationServiceBase.cs =================================================================== diff -u -re39274536935505756861bab61ab2e379162b33e -r3e9eb63e09c270127a0db49f2dea3da5ff3a3639 --- Ringtoets/Revetment/src/Ringtoets.Revetment.Service/WaveConditionsCalculationServiceBase.cs (.../WaveConditionsCalculationServiceBase.cs) (revision e39274536935505756861bab61ab2e379162b33e) +++ Ringtoets/Revetment/src/Ringtoets.Revetment.Service/WaveConditionsCalculationServiceBase.cs (.../WaveConditionsCalculationServiceBase.cs) (revision 3e9eb63e09c270127a0db49f2dea3da5ff3a3639) @@ -258,7 +258,7 @@ finally { var lastErrorFileContent = calculator.LastErrorFileContent; - bool errorOccurred = ErrorOccurred(exceptionThrown, lastErrorFileContent); + bool errorOccurred = CalculationServiceHelper.ErrorOccurred(Canceled, exceptionThrown, lastErrorFileContent); if (errorOccurred) { log.ErrorFormat(CultureInfo.CurrentCulture, @@ -277,11 +277,6 @@ } } - private bool ErrorOccurred(bool exceptionThrown, string lastErrorFileContent) - { - return !Canceled && !exceptionThrown && !string.IsNullOrEmpty(lastErrorFileContent); - } - private static WaveConditionsCosineCalculationInput CreateInput(RoundedDouble waterLevel, RoundedDouble a, RoundedDouble b, Index: Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Service/StabilityPointStructuresCalculationService.cs =================================================================== diff -u -re39274536935505756861bab61ab2e379162b33e -r3e9eb63e09c270127a0db49f2dea3da5ff3a3639 --- Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Service/StabilityPointStructuresCalculationService.cs (.../StabilityPointStructuresCalculationService.cs) (revision e39274536935505756861bab61ab2e379162b33e) +++ Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Service/StabilityPointStructuresCalculationService.cs (.../StabilityPointStructuresCalculationService.cs) (revision 3e9eb63e09c270127a0db49f2dea3da5ff3a3639) @@ -143,7 +143,7 @@ finally { var lastErrorFileContent = calculator.LastErrorFileContent; - bool errorOccurred = ErrorOccurred(exceptionThrown, lastErrorFileContent); + bool errorOccurred = CalculationServiceHelper.ErrorOccurred(canceled, exceptionThrown, lastErrorFileContent); if (errorOccurred) { log.ErrorFormat(Resources.StabilityPointStructuresCalculationService_Calculate_Error_in_stabilityPoint_structures_0_calculation_click_details_for_last_error_1, @@ -173,11 +173,6 @@ canceled = true; } - private bool ErrorOccurred(bool exceptionThrown, string lastErrorFileContent) - { - return !canceled && !exceptionThrown && !string.IsNullOrEmpty(lastErrorFileContent); - } - private StructuresStabilityPointCalculationInput CreateStructuresStabilityPointCalculationInput( StructuresCalculation calculation, StabilityPointStructuresFailureMechanism failureMechanism,