Index: Ringtoets/Common/src/Ringtoets.Common.Service/DesignWaterLevelCalculationService.cs =================================================================== diff -u -r9a6b8bd8e680c7b847ad548bad1c5a8c2d33b143 -rf8c28b3b04cdabb62ea37772efcb1f4ebbbf2b9e --- Ringtoets/Common/src/Ringtoets.Common.Service/DesignWaterLevelCalculationService.cs (.../DesignWaterLevelCalculationService.cs) (revision 9a6b8bd8e680c7b847ad548bad1c5a8c2d33b143) +++ Ringtoets/Common/src/Ringtoets.Common.Service/DesignWaterLevelCalculationService.cs (.../DesignWaterLevelCalculationService.cs) (revision f8c28b3b04cdabb62ea37772efcb1f4ebbbf2b9e) @@ -20,9 +20,7 @@ // All rights reserved. using System; -using System.Collections.Generic; using System.IO; -using System.Linq; using Core.Common.Base.IO; using Core.Common.Utils; using log4net; @@ -51,33 +49,58 @@ private bool canceled; /// - /// Performs validation over the values on the given . + /// Performs validation on the given and . /// Error and status information is logged during the execution of the operation. /// /// The file path of the hydraulic boundary database file which to validate. + /// The preprocessor directory to validate. /// True if there were no validation errors; False otherwise. - public static bool Validate(string hydraulicBoundaryDatabaseFilePath) + public static bool Validate(string hydraulicBoundaryDatabaseFilePath, string preprocessorDirectory) { + var isValid = true; + CalculationServiceHelper.LogValidationBegin(); - string[] validationProblems = ValidateInput(hydraulicBoundaryDatabaseFilePath); + string databaseFilePathValidationProblem = HydraulicBoundaryDatabaseHelper.ValidatePathForCalculation(hydraulicBoundaryDatabaseFilePath); + if (!string.IsNullOrEmpty(databaseFilePathValidationProblem)) + { + CalculationServiceHelper.LogMessagesAsError(Resources.Hydraulic_boundary_database_connection_failed_0_, + new[] + { + databaseFilePathValidationProblem + }); - CalculationServiceHelper.LogMessagesAsError(Resources.Hydraulic_boundary_database_connection_failed_0_, - validationProblems); + isValid = false; + } + string preprocessorDirectoryValidationProblem = HydraulicBoundaryDatabaseHelper.ValidatePreprocessorDirectory(preprocessorDirectory); + if (!string.IsNullOrEmpty(preprocessorDirectoryValidationProblem)) + { + CalculationServiceHelper.LogMessagesAsError(new[] + { + preprocessorDirectoryValidationProblem + }); + + isValid = false; + } + CalculationServiceHelper.LogValidationEnd(); - return !validationProblems.Any(); + return isValid; } /// /// Performs a calculation for the design water level. /// /// The design water level calculation to use. /// The path which points to the hydraulic boundary database file. + /// The preprocessor directory. /// The norm of the assessment section. /// The object which is used to build log messages. - /// Thrown when + /// Preprocessing is disabled when + /// equals . + /// Thrown when , + /// or /// is null. /// Thrown when /// @@ -94,6 +117,7 @@ /// Thrown when an error occurs while performing the calculation. public void Calculate(IHydraulicBoundaryWrapperCalculation designWaterLevelCalculation, string hydraulicBoundaryDatabaseFilePath, + string preprocessorDirectory, double norm, ICalculationMessageProvider messageProvider) { @@ -105,14 +129,15 @@ CalculationServiceHelper.LogCalculationBegin(); - calculator = HydraRingCalculatorFactory.Instance.CreateDesignWaterLevelCalculator(hlcdDirectory); + calculator = HydraRingCalculatorFactory.Instance.CreateDesignWaterLevelCalculator(hlcdDirectory, preprocessorDirectory); var exceptionThrown = false; try { PerformCalculation(designWaterLevelCalculation, hydraulicBoundaryDatabaseFilePath, + !string.IsNullOrEmpty(preprocessorDirectory), norm, messageProvider); } @@ -164,6 +189,7 @@ /// /// The design water level calculation to use. /// The path which points to the hydraulic boundary database file. + /// Indicator whether to use the preprocessor in the calculation. /// The norm of the assessment section. /// The object which is used to build log messages. /// Thrown when: @@ -176,10 +202,11 @@ /// Thrown when an error occurs while performing the calculation. private void PerformCalculation(IHydraulicBoundaryWrapperCalculation designWaterLevelCalculation, string hydraulicBoundaryDatabaseFilePath, + bool usePreprocessor, double norm, ICalculationMessageProvider messageProvider) { - AssessmentLevelCalculationInput calculationInput = CreateInput(designWaterLevelCalculation, norm, hydraulicBoundaryDatabaseFilePath); + AssessmentLevelCalculationInput calculationInput = CreateInput(designWaterLevelCalculation, norm, hydraulicBoundaryDatabaseFilePath, usePreprocessor); calculator.Calculate(calculationInput); @@ -279,6 +306,7 @@ /// The norm to use during the calculation. /// The file path to the hydraulic /// boundary database. + /// Indicator whether to use the preprocessor in the calculation. /// An . /// Thrown when the /// contains invalid characters. @@ -292,27 +320,14 @@ /// private static AssessmentLevelCalculationInput CreateInput(IHydraulicBoundaryWrapperCalculation designWaterLevelCalculation, double norm, - string hydraulicBoundaryDatabaseFilePath) + string hydraulicBoundaryDatabaseFilePath, + bool usePreprocessor) { var assessmentLevelCalculationInput = new AssessmentLevelCalculationInput(1, designWaterLevelCalculation.Id, norm); - HydraRingSettingsDatabaseHelper.AssignSettingsFromDatabase(assessmentLevelCalculationInput, hydraulicBoundaryDatabaseFilePath); + HydraRingSettingsDatabaseHelper.AssignSettingsFromDatabase(assessmentLevelCalculationInput, hydraulicBoundaryDatabaseFilePath, usePreprocessor); return assessmentLevelCalculationInput; } - - private static string[] ValidateInput(string hydraulicBoundaryDatabaseFilePath) - { - var validationResult = new List(); - - string validationProblem = HydraulicDatabaseHelper.ValidatePathForCalculation(hydraulicBoundaryDatabaseFilePath); - - if (!string.IsNullOrEmpty(validationProblem)) - { - validationResult.Add(validationProblem); - } - - return validationResult.ToArray(); - } } } \ No newline at end of file