Index: Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.CalculatedInput/WaternetCalculationException.cs
===================================================================
diff -u -r7c01a77639cfd510d494ac41556a3c7a6735db8e -rd2c7d08b8a0b896ce33582cd9e67efe2a59d06da
--- Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.CalculatedInput/WaternetCalculationException.cs (.../WaternetCalculationException.cs) (revision 7c01a77639cfd510d494ac41556a3c7a6735db8e)
+++ Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.CalculatedInput/WaternetCalculationException.cs (.../WaternetCalculationException.cs) (revision d2c7d08b8a0b896ce33582cd9e67efe2a59d06da)
@@ -1,4 +1,25 @@
-using System;
+// Copyright (C) Stichting Deltares 2019. All rights reserved.
+//
+// This file is part of Riskeer.
+//
+// Riskeer 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;
using System.Runtime.Serialization;
namespace Riskeer.MacroStabilityInwards.CalculatedInput
Index: Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Service/MacroStabilityInwardsCalculationService.cs
===================================================================
diff -u -r81032dec3576239e5c912e62f05a61c50e108ac6 -rd2c7d08b8a0b896ce33582cd9e67efe2a59d06da
--- Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Service/MacroStabilityInwardsCalculationService.cs (.../MacroStabilityInwardsCalculationService.cs) (revision 81032dec3576239e5c912e62f05a61c50e108ac6)
+++ Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Service/MacroStabilityInwardsCalculationService.cs (.../MacroStabilityInwardsCalculationService.cs) (revision d2c7d08b8a0b896ce33582cd9e67efe2a59d06da)
@@ -20,6 +20,7 @@
// All rights reserved.
using System;
+using System.Collections.Generic;
using System.Linq;
using Core.Common.Base.Data;
using log4net;
@@ -75,50 +76,43 @@
return false;
}
- MacroStabilityInwardsKernelMessage[] waternetExtremeKernelMessages;
- MacroStabilityInwardsKernelMessage[] waternetDailyKernelMessages;
+ IEnumerable waternetExtremeKernelMessages;
+ IEnumerable waternetDailyKernelMessages;
try
{
- log.Info(Resources.MacroStabilityInwardsCalculationService_Validate_Waternet_extreme_validation_started);
- waternetExtremeKernelMessages = WaternetCalculationService.ValidateExtreme(calculation.InputParameters, normativeAssessmentLevel).ToArray();
- LogKernelMessages(waternetExtremeKernelMessages);
-
- log.Info(Resources.MacroStabilityInwardsCalculationService_Validate_Waternet_daily_validation_started);
- waternetDailyKernelMessages = WaternetCalculationService.ValidateDaily(calculation.InputParameters).ToArray();
- LogKernelMessages(waternetDailyKernelMessages);
+ waternetExtremeKernelMessages = ValidateWaternet(() => WaternetCalculationService.ValidateExtreme(calculation.InputParameters, normativeAssessmentLevel),
+ Resources.MacroStabilityInwardsCalculationService_Validate_Waternet_extreme_validation_started);
+ waternetDailyKernelMessages = ValidateWaternet(() => WaternetCalculationService.ValidateDaily(calculation.InputParameters),
+ Resources.MacroStabilityInwardsCalculationService_Validate_Waternet_daily_validation_started);
}
catch (WaternetCalculationException e)
{
- CalculationServiceHelper.LogExceptionAsError(Resources.MacroStabilityInwardsCalculationService_Validate_Error_in_MacroStabilityInwards_validation, e);
- CalculationServiceHelper.LogValidationEnd();
+ HandleExceptionOnValidation(e);
return false;
}
- MacroStabilityInwardsKernelMessage[] kernelMessages =
- {};
+ IEnumerable kernelMessages = Enumerable.Empty();
if (!waternetExtremeKernelMessages.Any() && !waternetDailyKernelMessages.Any())
{
- UpliftVanCalculatorInput upliftVanCalculatorInput = CreateInputFromData(calculation.InputParameters, normativeAssessmentLevel);
- IUpliftVanCalculator calculator = MacroStabilityInwardsCalculatorFactory.Instance.CreateUpliftVanCalculator(upliftVanCalculatorInput, MacroStabilityInwardsKernelWrapperFactory.Instance);
+ IUpliftVanCalculator calculator = GetCalculator(calculation, normativeAssessmentLevel);
try
{
kernelMessages = calculator.Validate().ToArray();
}
catch (UpliftVanCalculatorException e)
{
- CalculationServiceHelper.LogExceptionAsError(Resources.MacroStabilityInwardsCalculationService_Validate_Error_in_MacroStabilityInwards_validation, e);
- CalculationServiceHelper.LogValidationEnd();
+ HandleExceptionOnValidation(e);
return false;
}
+
+ LogKernelMessages(kernelMessages);
}
- LogKernelMessages(kernelMessages);
-
CalculationServiceHelper.LogValidationEnd();
return kernelMessages.Concat(waternetDailyKernelMessages)
@@ -149,9 +143,7 @@
try
{
- IUpliftVanCalculator calculator = MacroStabilityInwardsCalculatorFactory.Instance.CreateUpliftVanCalculator(
- CreateInputFromData(calculation.InputParameters, normativeAssessmentLevel),
- MacroStabilityInwardsKernelWrapperFactory.Instance);
+ IUpliftVanCalculator calculator = GetCalculator(calculation, normativeAssessmentLevel);
macroStabilityInwardsResult = calculator.Calculate();
}
@@ -196,14 +188,35 @@
CalculationServiceHelper.LogCalculationEnd();
}
- private static void LogKernelMessages(MacroStabilityInwardsKernelMessage[] kernelMessages)
+ private static IUpliftVanCalculator GetCalculator(MacroStabilityInwardsCalculation calculation, RoundedDouble normativeAssessmentLevel)
{
+ UpliftVanCalculatorInput upliftVanCalculatorInput = CreateInputFromData(calculation.InputParameters, normativeAssessmentLevel);
+ IUpliftVanCalculator calculator = MacroStabilityInwardsCalculatorFactory.Instance.CreateUpliftVanCalculator(upliftVanCalculatorInput, MacroStabilityInwardsKernelWrapperFactory.Instance);
+ return calculator;
+ }
+
+ private static IEnumerable ValidateWaternet(Func> validateWaternetFunc, string logMessage)
+ {
+ log.Info(logMessage);
+ IEnumerable waternetKernelMessages = validateWaternetFunc();
+ LogKernelMessages(waternetKernelMessages);
+ return waternetKernelMessages;
+ }
+
+ private static void LogKernelMessages(IEnumerable kernelMessages)
+ {
CalculationServiceHelper.LogMessagesAsError(kernelMessages.Where(msg => msg.Type == MacroStabilityInwardsKernelMessageType.Error)
.Select(msg => msg.Message).ToArray());
CalculationServiceHelper.LogMessagesAsWarning(kernelMessages.Where(msg => msg.Type == MacroStabilityInwardsKernelMessageType.Warning)
.Select(msg => msg.Message).ToArray());
}
+ private static void HandleExceptionOnValidation(Exception e)
+ {
+ CalculationServiceHelper.LogExceptionAsError(Resources.MacroStabilityInwardsCalculationService_Validate_Error_in_MacroStabilityInwards_validation, e);
+ CalculationServiceHelper.LogValidationEnd();
+ }
+
private static UpliftVanCalculatorInput CreateInputFromData(MacroStabilityInwardsInput inputParameters, RoundedDouble normativeAssessmentLevel)
{
RoundedDouble effectiveAssessmentLevel = inputParameters.UseAssessmentLevelManualInput
Index: Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.CalculatedInput.Test/WaternetCalculationExceptionTest.cs
===================================================================
diff -u -r7c01a77639cfd510d494ac41556a3c7a6735db8e -rd2c7d08b8a0b896ce33582cd9e67efe2a59d06da
--- Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.CalculatedInput.Test/WaternetCalculationExceptionTest.cs (.../WaternetCalculationExceptionTest.cs) (revision 7c01a77639cfd510d494ac41556a3c7a6735db8e)
+++ Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.CalculatedInput.Test/WaternetCalculationExceptionTest.cs (.../WaternetCalculationExceptionTest.cs) (revision d2c7d08b8a0b896ce33582cd9e67efe2a59d06da)
@@ -1,4 +1,25 @@
-using System;
+// Copyright (C) Stichting Deltares 2019. All rights reserved.
+//
+// This file is part of Riskeer.
+//
+// Riskeer 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;
using Core.Common.TestUtil;
using NUnit.Framework;
Index: Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.CalculatedInput.Test/WaternetCalculationServiceTest.cs
===================================================================
diff -u -r81032dec3576239e5c912e62f05a61c50e108ac6 -rd2c7d08b8a0b896ce33582cd9e67efe2a59d06da
--- Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.CalculatedInput.Test/WaternetCalculationServiceTest.cs (.../WaternetCalculationServiceTest.cs) (revision 81032dec3576239e5c912e62f05a61c50e108ac6)
+++ Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.CalculatedInput.Test/WaternetCalculationServiceTest.cs (.../WaternetCalculationServiceTest.cs) (revision d2c7d08b8a0b896ce33582cd9e67efe2a59d06da)
@@ -161,7 +161,7 @@
WaternetCalculationService.ValidateDaily(input);
// Assert
- var factory = (TestMacroStabilityInwardsCalculatorFactory)MacroStabilityInwardsCalculatorFactory.Instance;
+ var factory = (TestMacroStabilityInwardsCalculatorFactory) MacroStabilityInwardsCalculatorFactory.Instance;
WaternetCalculatorInput actualInput = factory.LastCreatedWaternetCalculator.Input;
CalculatorInputAssert.AssertPhreaticLineOffsets(input.LocationInputDaily, actualInput.PhreaticLineOffsets);
@@ -179,7 +179,7 @@
// Setup
using (new MacroStabilityInwardsCalculatorFactoryConfig())
{
- var calculatorFactory = (TestMacroStabilityInwardsCalculatorFactory)MacroStabilityInwardsCalculatorFactory.Instance;
+ var calculatorFactory = (TestMacroStabilityInwardsCalculatorFactory) MacroStabilityInwardsCalculatorFactory.Instance;
WaternetCalculatorStub calculator = calculatorFactory.LastCreatedWaternetCalculator;
calculator.ReturnValidationError = true;
calculator.ReturnValidationWarning = true;
@@ -212,7 +212,7 @@
// Setup
using (new MacroStabilityInwardsCalculatorFactoryConfig())
{
- var calculatorFactory = (TestMacroStabilityInwardsCalculatorFactory)MacroStabilityInwardsCalculatorFactory.Instance;
+ var calculatorFactory = (TestMacroStabilityInwardsCalculatorFactory) MacroStabilityInwardsCalculatorFactory.Instance;
calculatorFactory.LastCreatedWaternetCalculator.ThrowExceptionOnValidate = true;
// Call
Index: Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.Service.Test/MacroStabilityInwardsCalculationServiceTest.cs
===================================================================
diff -u -r85f426aa7f7fcc6216c54f1cada6828dcefea862 -rd2c7d08b8a0b896ce33582cd9e67efe2a59d06da
--- Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.Service.Test/MacroStabilityInwardsCalculationServiceTest.cs (.../MacroStabilityInwardsCalculationServiceTest.cs) (revision 85f426aa7f7fcc6216c54f1cada6828dcefea862)
+++ Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.Service.Test/MacroStabilityInwardsCalculationServiceTest.cs (.../MacroStabilityInwardsCalculationServiceTest.cs) (revision d2c7d08b8a0b896ce33582cd9e67efe2a59d06da)
@@ -218,7 +218,7 @@
var isValid = true;
using (new MacroStabilityInwardsCalculatorFactoryConfig())
{
- var calculator = (TestMacroStabilityInwardsCalculatorFactory)MacroStabilityInwardsCalculatorFactory.Instance;
+ var calculator = (TestMacroStabilityInwardsCalculatorFactory) MacroStabilityInwardsCalculatorFactory.Instance;
calculator.LastCreatedWaternetCalculator.ReturnValidationError = true;
// Call
@@ -247,7 +247,7 @@
var isValid = false;
using (new MacroStabilityInwardsCalculatorFactoryConfig())
{
- var calculator = (TestMacroStabilityInwardsCalculatorFactory)MacroStabilityInwardsCalculatorFactory.Instance;
+ var calculator = (TestMacroStabilityInwardsCalculatorFactory) MacroStabilityInwardsCalculatorFactory.Instance;
calculator.LastCreatedWaternetCalculator.ReturnValidationWarning = true;
// Call
@@ -276,7 +276,7 @@
var isValid = true;
using (new MacroStabilityInwardsCalculatorFactoryConfig())
{
- var calculator = (TestMacroStabilityInwardsCalculatorFactory)MacroStabilityInwardsCalculatorFactory.Instance;
+ var calculator = (TestMacroStabilityInwardsCalculatorFactory) MacroStabilityInwardsCalculatorFactory.Instance;
calculator.LastCreatedWaternetCalculator.ReturnValidationWarning = true;
calculator.LastCreatedWaternetCalculator.ReturnValidationError = true;