Index: Ringtoets/Common/src/Ringtoets.Common.Service/CalculationServiceHelper.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.Service/CalculationServiceHelper.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.Service/CalculationServiceHelper.cs (revision 49d90fb457184cd520ada77ee07774405985abd5) @@ -0,0 +1,140 @@ +// 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; +using System.Collections.Generic; +using log4net; +using Ringtoets.Common.Service.Properties; + +namespace Ringtoets.Common.Service +{ + /// + /// This class defines helper methods for performing calculations. + /// + public static class CalculationServiceHelper + { + private static readonly ILog calculationServiceHelperLogger = LogManager.GetLogger(typeof(CalculationServiceHelper)); + + /// + /// Template method for performing validation. + /// + /// The name of the calculation. + /// The method used to perform the validation. + /// False if contains validation errors; True otherwise. + public static bool PerformValidation(string name, Func> validationFunc) + { + LogValidationBeginTime(name); + + var inputValidationResults = validationFunc(); + + if (inputValidationResults.Count > 0) + { + LogMessagesAsError(Resources.Error_in_validation_0, inputValidationResults.ToArray()); + } + + LogValidationEndTime(name); + + return inputValidationResults.Count == 0; + } + + /// + /// Template method for performing calculations. + /// + /// The output type. + /// The name of the calculation. + /// The method used to perform the calculation. + /// The error message to show when the output is null. + /// on a successful calculation, null otherwise. + public static T PerformCalculation(string name, Func calculationFunc, string errorMessage) + { + LogCalculationBeginTime(name); + + try + { + var output = calculationFunc(); + + if (output == null) + { + LogMessagesAsError(errorMessage, name); + } + + return output; + } + finally + { + LogCalculationEndTime(name); + } + } + + /// + /// Logs messages as errors. + /// + /// The format for the message. + /// The messages to log. + public static void LogMessagesAsError(string format, params string[] errorMessages) + { + foreach (var errorMessage in errorMessages) + { + calculationServiceHelperLogger.ErrorFormat(format, errorMessage); + } + } + + /// + /// Logs the begin time of the validation. + /// + /// The name used for the log message. + public static void LogValidationBeginTime(string name) + { + calculationServiceHelperLogger.Info(string.Format(Resources.Validation_Subject_0_started_Time_1_, + name, DateTimeService.CurrentTimeAsString)); + } + + /// + /// Logs the end time of the validation. + /// + /// The name used for the log message. + public static void LogValidationEndTime(string name) + { + calculationServiceHelperLogger.Info(string.Format(Resources.Validation_Subject_0_ended_Time_1_, + name, DateTimeService.CurrentTimeAsString)); + } + + /// + /// Logs the begin time of the calculation. + /// + /// The name used for the log message. + public static void LogCalculationBeginTime(string name) + { + calculationServiceHelperLogger.Info(string.Format(Resources.Calculation_Subject_0_started_Time_1_, + name, DateTimeService.CurrentTimeAsString)); + } + + /// + /// Logs the end time of the calculation. + /// + /// The name used for the log message. + public static void LogCalculationEndTime(string name) + { + calculationServiceHelperLogger.Info(string.Format(Resources.Calculation_Subject_0_ended_Time_1_, + name, DateTimeService.CurrentTimeAsString)); + } + } +} \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Service/Ringtoets.Common.Service.csproj =================================================================== diff -u -re568165b751acf8d72cdf0d128f76d7792dadb56 -r49d90fb457184cd520ada77ee07774405985abd5 --- Ringtoets/Common/src/Ringtoets.Common.Service/Ringtoets.Common.Service.csproj (.../Ringtoets.Common.Service.csproj) (revision e568165b751acf8d72cdf0d128f76d7792dadb56) +++ Ringtoets/Common/src/Ringtoets.Common.Service/Ringtoets.Common.Service.csproj (.../Ringtoets.Common.Service.csproj) (revision 49d90fb457184cd520ada77ee07774405985abd5) @@ -32,6 +32,10 @@ AllRules.ruleset + + ..\..\..\..\packages\log4net.2.0.4\lib\net40-full\log4net.dll + True + ..\..\..\..\packages\MathNet.Numerics.3.8.0\lib\net40\MathNet.Numerics.dll @@ -42,6 +46,7 @@ Properties\GlobalAssembly.cs + Index: Ringtoets/Common/src/Ringtoets.Common.Service/packages.config =================================================================== diff -u -r678dc8c8dbb01fd889a082ae88c9f9d42f597a10 -r49d90fb457184cd520ada77ee07774405985abd5 --- Ringtoets/Common/src/Ringtoets.Common.Service/packages.config (.../packages.config) (revision 678dc8c8dbb01fd889a082ae88c9f9d42f597a10) +++ Ringtoets/Common/src/Ringtoets.Common.Service/packages.config (.../packages.config) (revision 49d90fb457184cd520ada77ee07774405985abd5) @@ -23,5 +23,6 @@ All rights reserved. --> + \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/CalculationServiceHelperTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/CalculationServiceHelperTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/CalculationServiceHelperTest.cs (revision 49d90fb457184cd520ada77ee07774405985abd5) @@ -0,0 +1,222 @@ +// 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; +using System.Collections.Generic; +using System.Linq; +using Core.Common.TestUtil; +using NUnit.Framework; + +namespace Ringtoets.Common.Service.Test +{ + [TestFixture] + public class CalculationServiceHelperTest + { + [Test] + public void PerformValidation_ValidationFuncReturnsMessages_WritesLogMessagesAndReturnsFalse() + { + // Setup + string name = "Test name"; + List errorMessages = new List(); + errorMessages.Add("Error message 1"); + + // Call + bool valid = false; + Action call = () => valid = CalculationServiceHelper.PerformValidation(name, () => errorMessages); + + // Assert + TestHelper.AssertLogMessages(call, messages => + { + var msgs = messages.ToArray(); + Assert.AreEqual(3, msgs.Length); + StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", name), msgs[0]); + StringAssert.StartsWith(string.Format("Validatie mislukt: {0}", errorMessages[0]), msgs[1]); + StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", name), msgs[2]); + }); + Assert.IsFalse(valid); + } + + [Test] + public void PerformValidation_ValidationFuncReturnsEmtpyList_WritesStartAndEndLogMessagesAndReturnsTrue() + { + // Setup + string name = "Test name"; + List errorMessages = new List(); + + // Call + bool valid = false; + Action call = () => valid = CalculationServiceHelper.PerformValidation(name, () => errorMessages); + + // Assert + TestHelper.AssertLogMessages(call, messages => + { + var msgs = messages.ToArray(); + Assert.AreEqual(2, msgs.Length); + StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", name), msgs[0]); + StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", name), msgs[1]); + }); + Assert.IsTrue(valid); + } + + [Test] + public void PerformCalculation_CalculationFuncReturnsNull_WritesStartAndEndAndErrorLogMessagesAndReturnsNull() + { + // Setup + string name = "Test name"; + string errorMessage = "There was an error: {0}"; + + object output = null; + + // Call + Action call = () => output = CalculationServiceHelper.PerformCalculation(name, () => null, errorMessage); + + // Assert + TestHelper.AssertLogMessages(call, messages => + { + var msgs = messages.ToArray(); + Assert.AreEqual(3, msgs.Length); + StringAssert.StartsWith(string.Format("Berekening van '{0}' gestart om: ", name), msgs[0]); + StringAssert.StartsWith(string.Format(errorMessage, name), msgs[1]); + StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", name), msgs[2]); + }); + Assert.IsNull(output); + } + + [Test] + public void PerformCalculation_CalculationFuncReturnsOutput_WritesStartAndEndLogMessagesAndReturnsOutput() + { + // Setup + string name = "Test name"; + double outputValue = 4.0; + + double output = double.NaN; + + // Call + Action call = () => output = CalculationServiceHelper.PerformCalculation(name, () => outputValue, string.Empty); + + // Assert + TestHelper.AssertLogMessages(call, messages => + { + var msgs = messages.ToArray(); + Assert.AreEqual(2, msgs.Length); + StringAssert.StartsWith(string.Format("Berekening van '{0}' gestart om: ", name), msgs[0]); + StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", name), msgs[1]); + }); + Assert.AreEqual(outputValue, output); + } + + [Test] + public void LogMessagesAsError_Always_LogsMessagesInGivenFormat() + { + // Setup + var format = "Message: {0}"; + string[] errorMessages = new[] + { + "Test 1", + "Test 2" + }; + + // Call + Action call = () => CalculationServiceHelper.LogMessagesAsError(format, errorMessages); + + // Assert + TestHelper.AssertLogMessages(call, messages => + { + var msgs = messages.ToArray(); + Assert.AreEqual(2, msgs.Length); + StringAssert.StartsWith(string.Format(format, errorMessages[0]), msgs[0]); + StringAssert.StartsWith(string.Format(format, errorMessages[1]), msgs[1]); + }); + } + + [Test] + public void LogValidationBeginTime_Always_LogsValidationBeginTime() + { + // Setup + var name = "Test name"; + + // Call + Action call = () => CalculationServiceHelper.LogValidationBeginTime(name); + + // Assert + TestHelper.AssertLogMessages(call, messages => + { + var msgs = messages.ToArray(); + Assert.AreEqual(1, msgs.Length); + StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om:", name), msgs[0]); + }); + } + + [Test] + public void LogValidationEndTime_Always_LogsValidationEndTime() + { + // Setup + var name = "Test name"; + + // Call + Action call = () => CalculationServiceHelper.LogValidationEndTime(name); + + // Assert + TestHelper.AssertLogMessages(call, messages => + { + var msgs = messages.ToArray(); + Assert.AreEqual(1, msgs.Length); + StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om:", name), msgs[0]); + }); + } + + [Test] + public void LogCalculationBeginTime_Always_LogsCalculationBeginTime() + { + // Setup + var name = "Test name"; + + // Call + Action call = () => CalculationServiceHelper.LogCalculationBeginTime(name); + + // Assert + TestHelper.AssertLogMessages(call, messages => + { + var msgs = messages.ToArray(); + Assert.AreEqual(1, msgs.Length); + StringAssert.StartsWith(string.Format("Berekening van '{0}' gestart om:", name), msgs[0]); + }); + } + + [Test] + public void LogCalculationEndTime_Always_LogsCalculationEndTime() + { + // Setup + var name = "Test name"; + + // Call + Action call = () => CalculationServiceHelper.LogCalculationEndTime(name); + + // Assert + TestHelper.AssertLogMessages(call, messages => + { + var msgs = messages.ToArray(); + Assert.AreEqual(1, msgs.Length); + StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om:", name), msgs[0]); + }); + } + } +} Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/Ringtoets.Common.Service.Test.csproj =================================================================== diff -u -re568165b751acf8d72cdf0d128f76d7792dadb56 -r49d90fb457184cd520ada77ee07774405985abd5 --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/Ringtoets.Common.Service.Test.csproj (.../Ringtoets.Common.Service.Test.csproj) (revision e568165b751acf8d72cdf0d128f76d7792dadb56) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/Ringtoets.Common.Service.Test.csproj (.../Ringtoets.Common.Service.Test.csproj) (revision 49d90fb457184cd520ada77ee07774405985abd5) @@ -46,6 +46,7 @@ + @@ -61,6 +62,10 @@ {3bbfd65b-b277-4e50-ae6d-bd24c3434609} Core.Common.Base + + {D749EE4C-CE50-4C17-BF01-9A953028C126} + Core.Common.TestUtil + {d4200f43-3f72-4f42-af0a-8ced416a38ec} Ringtoets.Common.Data Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/GrassCoverErosionInwardsCalculationService.cs =================================================================== diff -u -r0a51f20ac93373a43f79bb4c6327bce1d46545c6 -r49d90fb457184cd520ada77ee07774405985abd5 --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/GrassCoverErosionInwardsCalculationService.cs (.../GrassCoverErosionInwardsCalculationService.cs) (revision 0a51f20ac93373a43f79bb4c6327bce1d46545c6) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/GrassCoverErosionInwardsCalculationService.cs (.../GrassCoverErosionInwardsCalculationService.cs) (revision 49d90fb457184cd520ada77ee07774405985abd5) @@ -22,7 +22,6 @@ using System.Collections.Generic; using System.Linq; using Core.Common.Base.Properties; -using log4net; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Service; @@ -41,8 +40,6 @@ /// internal static class GrassCoverErosionInwardsCalculationService { - private static readonly ILog grassCoverErosionInwardsCalculationLogger = LogManager.GetLogger(typeof(GrassCoverErosionInwardsCalculationService)); - /// /// Performs validation over the values on the given . Error and status information is logged during /// the execution of the operation. @@ -52,19 +49,7 @@ /// False if contains validation errors; True otherwise. internal static bool Validate(GrassCoverErosionInwardsCalculation calculation, IAssessmentSection assessmentSection) { - grassCoverErosionInwardsCalculationLogger.Info(string.Format(RingtoetsCommonServiceResources.Validation_Subject_0_started_Time_1_, - calculation.Name, DateTimeService.CurrentTimeAsString)); - - var inputValidationResults = ValidateInput(calculation.InputParameters, assessmentSection); - - if (inputValidationResults.Count > 0) - { - LogMessagesAsError(RingtoetsCommonServiceResources.Error_in_validation_0, inputValidationResults.ToArray()); - } - - LogValidationEndTime(calculation); - - return inputValidationResults.Count == 0; + return CalculationServiceHelper.PerformValidation(calculation.Name, () => ValidateInput(calculation.InputParameters, assessmentSection)); } /// @@ -81,26 +66,11 @@ string hlcdDirectory, FailureMechanismSection failureMechanismSection, string ringId, GeneralGrassCoverErosionInwardsInput generalInput) { - grassCoverErosionInwardsCalculationLogger.Info(string.Format(RingtoetsCommonServiceResources.Calculation_Subject_0_started_Time_1_, - calculation.Name, DateTimeService.CurrentTimeAsString)); + var input = CreateInput(calculation, failureMechanismSection, generalInput); - try - { - var input = CreateInput(calculation, failureMechanismSection, generalInput); - var output = HydraRingCalculationService.PerformCalculation(hlcdDirectory, ringId, HydraRingTimeIntegrationSchemeType.FBC, HydraRingUncertaintiesType.All, input); - - if (output == null) - { - grassCoverErosionInwardsCalculationLogger.ErrorFormat(Resources.GrassCoverErosionInwardsCalculationService_Calculate_Error_in_grass_cover_erosion_inwards_0_calculation, calculation.Name); - } - - return output; - } - finally - { - grassCoverErosionInwardsCalculationLogger.Info(string.Format(RingtoetsCommonServiceResources.Calculation_Subject_0_ended_Time_1_, - calculation.Name, DateTimeService.CurrentTimeAsString)); - } + return CalculationServiceHelper.PerformCalculation(calculation.Name, + () => HydraRingCalculationService.PerformCalculation(hlcdDirectory, ringId, HydraRingTimeIntegrationSchemeType.FBC, HydraRingUncertaintiesType.All, input), + Resources.GrassCoverErosionInwardsCalculationService_Calculate_Error_in_grass_cover_erosion_inwards_0_calculation); } private static OvertoppingCalculationInput CreateInput(GrassCoverErosionInwardsCalculation calculation, FailureMechanismSection failureMechanismSection, GeneralGrassCoverErosionInwardsInput generalInput) @@ -176,19 +146,5 @@ return validationResult; } - - private static void LogMessagesAsError(string format, params string[] errorMessages) - { - foreach (var errorMessage in errorMessages) - { - grassCoverErosionInwardsCalculationLogger.ErrorFormat(format, errorMessage); - } - } - - private static void LogValidationEndTime(GrassCoverErosionInwardsCalculation calculation) - { - grassCoverErosionInwardsCalculationLogger.Info(string.Format(RingtoetsCommonServiceResources.Validation_Subject_0_ended_Time_1_, - calculation.Name, DateTimeService.CurrentTimeAsString)); - } } } \ No newline at end of file Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Service/HeightStructuresCalculationService.cs =================================================================== diff -u -r0a51f20ac93373a43f79bb4c6327bce1d46545c6 -r49d90fb457184cd520ada77ee07774405985abd5 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Service/HeightStructuresCalculationService.cs (.../HeightStructuresCalculationService.cs) (revision 0a51f20ac93373a43f79bb4c6327bce1d46545c6) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Service/HeightStructuresCalculationService.cs (.../HeightStructuresCalculationService.cs) (revision 49d90fb457184cd520ada77ee07774405985abd5) @@ -20,7 +20,6 @@ // All rights reserved. using System.Collections.Generic; -using log4net; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Data.Probabilistics; @@ -40,8 +39,6 @@ /// internal static class HeightStructuresCalculationService { - private static readonly ILog heightStructuresCalculationLogger = LogManager.GetLogger(typeof(HeightStructuresCalculationService)); - /// /// Performs validation over the values on the given . Error and status information is logged during /// the execution of the operation. @@ -51,19 +48,7 @@ /// False if contains validation errors; True otherwise. internal static bool Validate(HeightStructuresCalculation calculation, IAssessmentSection assessmentSection) { - heightStructuresCalculationLogger.Info(string.Format(RingtoetsCommonServiceResources.Validation_Subject_0_started_Time_1_, - calculation.Name, DateTimeService.CurrentTimeAsString)); - - var inputValidationResults = ValidateInput(calculation.InputParameters, assessmentSection); - - if (inputValidationResults.Count > 0) - { - LogMessagesAsError(RingtoetsCommonServiceResources.Error_in_validation_0, inputValidationResults.ToArray()); - } - - LogValidationEndTime(calculation); - - return inputValidationResults.Count == 0; + return CalculationServiceHelper.PerformValidation(calculation.Name, () => ValidateInput(calculation.InputParameters, assessmentSection)); } /// @@ -80,26 +65,10 @@ string hlcdDirectory, FailureMechanismSection failureMechanismSection, string ringId, GeneralHeightStructuresInput generalInput) { - heightStructuresCalculationLogger.Info(string.Format(RingtoetsCommonServiceResources.Calculation_Subject_0_started_Time_1_, - calculation.Name, DateTimeService.CurrentTimeAsString)); - - try - { - var input = CreateInput(calculation, failureMechanismSection, generalInput); - var output = HydraRingCalculationService.PerformCalculation(hlcdDirectory, ringId, HydraRingTimeIntegrationSchemeType.FBC, HydraRingUncertaintiesType.All, input); - - if (output == null) - { - LogMessagesAsError(Resources.HeightStructuresCalculationService_Calculate_Error_in_height_structures_0_calculation, calculation.Name); - } - - return output; - } - finally - { - heightStructuresCalculationLogger.Info(string.Format(RingtoetsCommonServiceResources.Calculation_Subject_0_ended_Time_1_, - calculation.Name, DateTimeService.CurrentTimeAsString)); - } + var input = CreateInput(calculation, failureMechanismSection, generalInput); + return CalculationServiceHelper.PerformCalculation(calculation.Name, + () => HydraRingCalculationService.PerformCalculation(hlcdDirectory, ringId, HydraRingTimeIntegrationSchemeType.FBC, HydraRingUncertaintiesType.All, input), + Resources.HeightStructuresCalculationService_Calculate_Error_in_height_structures_0_calculation); } private static StructuresOvertoppingCalculationInput CreateInput(HeightStructuresCalculation calculation, FailureMechanismSection failureMechanismSection, GeneralHeightStructuresInput generalInput) @@ -142,19 +111,5 @@ return validationResult; } - - private static void LogMessagesAsError(string format, params string[] errorMessages) - { - foreach (var errorMessage in errorMessages) - { - heightStructuresCalculationLogger.ErrorFormat(format, errorMessage); - } - } - - private static void LogValidationEndTime(HeightStructuresCalculation calculation) - { - heightStructuresCalculationLogger.Info(string.Format(RingtoetsCommonServiceResources.Validation_Subject_0_ended_Time_1_, - calculation.Name, DateTimeService.CurrentTimeAsString)); - } } } \ No newline at end of file Index: Ringtoets/Integration/src/Ringtoets.Integration.Service/DesignWaterLevelCalculationService.cs =================================================================== diff -u -r0a51f20ac93373a43f79bb4c6327bce1d46545c6 -r49d90fb457184cd520ada77ee07774405985abd5 --- Ringtoets/Integration/src/Ringtoets.Integration.Service/DesignWaterLevelCalculationService.cs (.../DesignWaterLevelCalculationService.cs) (revision 0a51f20ac93373a43f79bb4c6327bce1d46545c6) +++ Ringtoets/Integration/src/Ringtoets.Integration.Service/DesignWaterLevelCalculationService.cs (.../DesignWaterLevelCalculationService.cs) (revision 49d90fb457184cd520ada77ee07774405985abd5) @@ -20,7 +20,6 @@ // All rights reserved. using System.IO; -using log4net; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Service; using Ringtoets.HydraRing.Calculation.Data; @@ -41,8 +40,6 @@ /// internal static class DesignWaterLevelCalculationService { - private static readonly ILog designWaterLevelCalculationLogger = LogManager.GetLogger(typeof(DesignWaterLevelCalculationService)); - /// /// Performs validation over the values on the given . Error information is logged during /// the execution of the operation. @@ -52,19 +49,18 @@ /// False if contains validation errors; True otherwise. internal static bool Validate(HydraulicBoundaryDatabase hydraulicBoundaryDatabase, HydraulicBoundaryLocation hydraulicBoundaryLocation) { - designWaterLevelCalculationLogger.Info(string.Format(RingtoetsCommonServiceResources.Validation_Subject_0_started_Time_1_, - hydraulicBoundaryLocation.Id, DateTimeService.CurrentTimeAsString)); + CalculationServiceHelper.LogValidationBeginTime(hydraulicBoundaryLocation.Id.ToString()); var validationProblem = HydraulicDatabaseHelper.ValidatePathForCalculation(hydraulicBoundaryDatabase.FilePath); var hasErrors = string.IsNullOrEmpty(validationProblem); if (!hasErrors) { - LogMessagesAsError(RingtoetsCommonFormsResources.Hydraulic_boundary_database_connection_failed_0_, - validationProblem); + CalculationServiceHelper.LogMessagesAsError(RingtoetsCommonFormsResources.Hydraulic_boundary_database_connection_failed_0_, + validationProblem); } - LogValidationEndTime(hydraulicBoundaryLocation); + CalculationServiceHelper.LogValidationEndTime(hydraulicBoundaryLocation.Id.ToString()); return hasErrors; } @@ -81,47 +77,17 @@ internal static TargetProbabilityCalculationOutput Calculate(IAssessmentSection assessmentSection, HydraulicBoundaryDatabase hydraulicBoundaryDatabase, HydraulicBoundaryLocation hydraulicBoundaryLocation, string ringId) { - designWaterLevelCalculationLogger.Info(string.Format(RingtoetsCommonServiceResources.Calculation_Subject_0_started_Time_1_, - hydraulicBoundaryLocation.Id, DateTimeService.CurrentTimeAsString)); + var hlcdDirectory = Path.GetDirectoryName(hydraulicBoundaryDatabase.FilePath); + var input = CreateInput(assessmentSection, hydraulicBoundaryLocation); - try - { - var hlcdDirectory = Path.GetDirectoryName(hydraulicBoundaryDatabase.FilePath); - var input = CreateInput(assessmentSection, hydraulicBoundaryLocation); - - var output = HydraRingCalculationService.PerformCalculation(hlcdDirectory, ringId, HydraRingTimeIntegrationSchemeType.FBC, HydraRingUncertaintiesType.All, input); - - if (output == null) - { - LogMessagesAsError(Resources.DesignWaterLevelCalculationService_Calculate_Error_in_design_water_level_0_calculation, hydraulicBoundaryLocation.Id.ToString()); - } - - return output; - } - finally - { - designWaterLevelCalculationLogger.Info(string.Format(RingtoetsCommonServiceResources.Calculation_Subject_0_ended_Time_1_, - hydraulicBoundaryLocation.Id, DateTimeService.CurrentTimeAsString)); - } + return CalculationServiceHelper.PerformCalculation(hydraulicBoundaryLocation.Id.ToString(), + () => HydraRingCalculationService.PerformCalculation(hlcdDirectory, ringId, HydraRingTimeIntegrationSchemeType.FBC, HydraRingUncertaintiesType.All, input), + Resources.DesignWaterLevelCalculationService_Calculate_Error_in_design_water_level_0_calculation); } private static AssessmentLevelCalculationInput CreateInput(IAssessmentSection assessmentSection, HydraulicBoundaryLocation hydraulicBoundaryLocation) { return new AssessmentLevelCalculationInput((int) hydraulicBoundaryLocation.Id, assessmentSection.FailureMechanismContribution.Norm); } - - private static void LogMessagesAsError(string format, params string[] errorMessages) - { - foreach (var errorMessage in errorMessages) - { - designWaterLevelCalculationLogger.ErrorFormat(format, errorMessage); - } - } - - private static void LogValidationEndTime(HydraulicBoundaryLocation hydraulicBoundaryLocation) - { - designWaterLevelCalculationLogger.Info(string.Format(RingtoetsCommonServiceResources.Validation_Subject_0_ended_Time_1_, - hydraulicBoundaryLocation.Id, DateTimeService.CurrentTimeAsString)); - } } } \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.Service.Test/Ringtoets.Integration.Service.Test.csproj =================================================================== diff -u -r0a51f20ac93373a43f79bb4c6327bce1d46545c6 -r49d90fb457184cd520ada77ee07774405985abd5 --- Ringtoets/Integration/test/Ringtoets.Integration.Service.Test/Ringtoets.Integration.Service.Test.csproj (.../Ringtoets.Integration.Service.Test.csproj) (revision 0a51f20ac93373a43f79bb4c6327bce1d46545c6) +++ Ringtoets/Integration/test/Ringtoets.Integration.Service.Test/Ringtoets.Integration.Service.Test.csproj (.../Ringtoets.Integration.Service.Test.csproj) (revision 49d90fb457184cd520ada77ee07774405985abd5) @@ -50,6 +50,10 @@ + + ..\..\..\..\packages\System.Data.SQLite.Core.1.0.99.0\lib\net40\System.Data.SQLite.dll + True + @@ -97,6 +101,13 @@ + + + + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + +