private static bool LogAnyErrors(ProbabilisticPipingCalculation calculation, PipingFailureMechanism failureMechanism, IAssessmentSection assessmentSection) { string[] messages = ValidateHydraulicBoundaryDatabase(assessmentSection).ToArray(); if (messages.Length == 0) { messages = ValidateFailureMechanismHasSections(failureMechanism).ToArray(); } if (messages.Length == 0) { messages = ValidateInput(calculation.InputParameters, failureMechanism.GeneralInput).ToArray(); } if (messages.Length == 0) { messages = ValidateCalculationInMultipleSections(calculation, failureMechanism).ToArray(); } if (messages.Length > 0) { CalculationServiceHelper.LogMessagesAsError(messages); return(true); } return(false); }
/// <summary> /// Performs validation over the given input parameters. Error and status information is logged /// during the execution of the operation. /// </summary> /// <param name="waveConditionsInput">The input of the calculation.</param> /// <param name="assessmentLevel">The assessment level to use for determining water levels.</param> /// <param name="hydraulicBoundaryDatabase">The hydraulic boundary database to validate.</param> /// <returns><c>true</c> if there were no validation errors; <c>false</c> otherwise.</returns> /// <exception cref="ArgumentNullException">Thrown when <paramref name="waveConditionsInput"/> or /// <paramref name="hydraulicBoundaryDatabase"/> is <c>null</c>.</exception> public static bool Validate(WaveConditionsInput waveConditionsInput, RoundedDouble assessmentLevel, HydraulicBoundaryDatabase hydraulicBoundaryDatabase) { if (waveConditionsInput == null) { throw new ArgumentNullException(nameof(waveConditionsInput)); } if (hydraulicBoundaryDatabase == null) { throw new ArgumentNullException(nameof(hydraulicBoundaryDatabase)); } CalculationServiceHelper.LogValidationBegin(); string[] messages = ValidateInput(hydraulicBoundaryDatabase, waveConditionsInput, assessmentLevel); CalculationServiceHelper.LogMessagesAsError(messages); CalculationServiceHelper.LogValidationEnd(); return(!messages.Any()); }
/// <summary> /// Performs validation over the values on the given <paramref name="calculation"/>. Error and status information is logged during /// the execution of the operation. /// </summary> /// <param name="calculation">The <see cref="ProbabilisticPipingCalculation"/> for which to validate the values.</param> /// <param name="failureMechanism">The <see cref="PipingFailureMechanism"/> for which to validate the values.</param> /// <param name="assessmentSection">The <see cref="IAssessmentSection"/> for which to validate the values.</param> /// <returns><c>true</c> if <paramref name="calculation"/> has no validation errors; <c>false</c> otherwise.</returns> /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception> public static bool Validate(ProbabilisticPipingCalculation calculation, PipingFailureMechanism failureMechanism, IAssessmentSection assessmentSection) { if (calculation == null) { throw new ArgumentNullException(nameof(calculation)); } if (failureMechanism == null) { throw new ArgumentNullException(nameof(failureMechanism)); } if (assessmentSection == null) { throw new ArgumentNullException(nameof(assessmentSection)); } CalculationServiceHelper.LogValidationBegin(); LogAnyWarnings(calculation); bool hasErrors = LogAnyErrors(calculation, failureMechanism, assessmentSection); CalculationServiceHelper.LogValidationEnd(); return(!hasErrors); }
private static void LogKernelMessages(IEnumerable <MacroStabilityInwardsKernelMessage> 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()); }
public void HasErrorOccurred_CalculationNotCanceledOrExceptionThrownLastErrorNotSet_ReturnFalse(string errorContent) { // Call bool errorOccurred = CalculationServiceHelper.HasErrorOccurred(false, false, errorContent); // Assert Assert.IsFalse(errorOccurred); }
public void HasErrorOccurred_LastErrorSetCalculationCanceledOrExceptionThrown_ReturnFalse(bool canceled, bool exceptionThrown, string errorContent) { // Call bool errorOccurred = CalculationServiceHelper.HasErrorOccurred(canceled, exceptionThrown, errorContent); // Assert Assert.IsFalse(errorOccurred); }
public void HasErrorOccurred_CalculationNotCanceledOrExceptionThrownLastErrorSet_ReturnTrue() { // Call bool errorOccurred = CalculationServiceHelper.HasErrorOccurred(false, false, "An error has occurred."); // Assert Assert.IsTrue(errorOccurred); }
/// <summary> /// Performs a piping calculation based on the supplied <see cref="ProbabilisticPipingCalculation"/> and sets <see cref="ProbabilisticPipingCalculation.Output"/> /// if the calculation was successful. Error and status information is logged during the execution of the operation. /// </summary> /// <param name="calculation">The <see cref="ProbabilisticPipingCalculation"/> that holds all the information required to perform the calculation.</param> /// <param name="generalInput">The <see cref="GeneralPipingInput"/> to derive values from during the calculation.</param> /// <param name="calculationSettings">The <see cref="HydraulicBoundaryCalculationSettings"/> with the /// hydraulic boundary calculation settings.</param> /// <param name="sectionLength">The length of the section the calculation belongs to.</param> /// <remarks>Preprocessing is disabled when the preprocessor directory equals <see cref="string.Empty"/>.</remarks> /// <exception cref="ArgumentNullException">Thrown when <paramref name="calculation"/>, <paramref name="generalInput"/> /// or <paramref name="calculationSettings"/> is <c>null</c>.</exception> /// <exception cref="ArgumentException">Thrown when the hydraulic boundary database file path /// contains invalid characters.</exception> /// <exception cref="CriticalFileReadException">Thrown when: /// <list type="bullet"> /// <item>No settings database file could be found at the location of the hydraulic boundary database file path /// with the same name.</item> /// <item>Unable to open settings database file.</item> /// <item>Unable to read required data from database file.</item> /// </list></exception> /// <exception cref="HydraRingFileParserException">Thrown when an error occurs during parsing of the Hydra-Ring output.</exception> /// <exception cref="HydraRingCalculationException">Thrown when an error occurs during the calculation.</exception> internal void Calculate(ProbabilisticPipingCalculation calculation, GeneralPipingInput generalInput, HydraulicBoundaryCalculationSettings calculationSettings, double sectionLength) { if (calculation == null) { throw new ArgumentNullException(nameof(calculation)); } if (generalInput == null) { throw new ArgumentNullException(nameof(generalInput)); } if (calculationSettings == null) { throw new ArgumentNullException(nameof(calculationSettings)); } string hydraulicBoundaryDatabaseFilePath = calculationSettings.HydraulicBoundaryDatabaseFilePath; bool usePreprocessor = !string.IsNullOrEmpty(calculationSettings.PreprocessorDirectory); HydraRingCalculationSettings hydraRingCalculationSettings = HydraRingCalculationSettingsFactory.CreateSettings(calculationSettings); profileSpecificCalculator = HydraRingCalculatorFactory.Instance.CreatePipingCalculator( hydraRingCalculationSettings); sectionSpecificCalculator = HydraRingCalculatorFactory.Instance.CreatePipingCalculator( hydraRingCalculationSettings); CalculationServiceHelper.LogCalculationBegin(); try { IPartialProbabilisticPipingOutput profileSpecificOutput = CalculateProfileSpecific( calculation, generalInput, hydraulicBoundaryDatabaseFilePath, usePreprocessor); if (canceled) { return; } IPartialProbabilisticPipingOutput sectionSpecificOutput = CalculateSectionSpecific( calculation, generalInput, sectionLength, hydraulicBoundaryDatabaseFilePath, usePreprocessor); if (canceled) { return; } calculation.Output = new ProbabilisticPipingOutput(sectionSpecificOutput, profileSpecificOutput); } finally { CalculationServiceHelper.LogCalculationEnd(); profileSpecificCalculator = null; sectionSpecificCalculator = null; } }
public void LogMessagesAsWarning_WarningMessagesNull_ThrowsArgumentNullException() { // Call TestDelegate call = () => CalculationServiceHelper.LogMessagesAsWarning(null); // Assert var exception = Assert.Throws <ArgumentNullException>(call); Assert.AreEqual("warningMessages", exception.ParamName); }
public void LogExceptionAsError_ExceptionNull_ThrowsArgumentNullException() { // Call TestDelegate call = () => CalculationServiceHelper.LogExceptionAsError("message", null); // Assert var exception = Assert.Throws <ArgumentNullException>(call); Assert.AreEqual("exception", exception.ParamName); }
public void LogMessagesAsErrorWithoutFormat_ErrorMessagesNull_ThrowsArgumentNullException() { // Call TestDelegate call = () => CalculationServiceHelper.LogMessagesAsError(null); // Assert var exception = Assert.Throws <ArgumentNullException>(call); Assert.AreEqual("errorMessages", exception.ParamName); }
private static void LogAnyWarnings(SemiProbabilisticPipingCalculation calculation) { CalculationServiceHelper.LogMessagesAsWarning(PipingCalculationValidationHelper.GetValidationWarnings(calculation.InputParameters).ToArray()); RoundedDouble diameter70Value = SemiProbabilisticPipingDesignVariableFactory.GetDiameter70(calculation.InputParameters).GetDesignValue(); if (!double.IsNaN(diameter70Value) && (diameter70Value < 6.3e-5 || diameter70Value > 0.5e-3)) { CalculationServiceHelper.LogMessagesAsWarning(new[] { string.Format(Resources.SemiProbabilisticPipingCalculationService_GetInputWarnings_Specified_DiameterD70_value_0_not_in_valid_range_of_model, diameter70Value) }); } }
/// <summary> /// Performs a wave conditions calculation for the wave impact on asphalt failure mechanism based on the supplied /// <see cref="WaveImpactAsphaltCoverWaveConditionsCalculation"/> and sets /// <see cref="WaveImpactAsphaltCoverWaveConditionsCalculation.Output"/> if the calculation was successful. /// Error and status information is logged during the execution of the operation. /// </summary> /// <param name="calculation">The <see cref="WaveImpactAsphaltCoverWaveConditionsCalculation"/> that holds all the information required to perform the calculation.</param> /// <param name="assessmentSection">The <see cref="IAssessmentSection"/> that holds information about the target probability used in the calculation.</param> /// <param name="generalWaveConditionsInput">Calculation input parameters that apply to all <see cref="WaveImpactAsphaltCoverWaveConditionsCalculation"/> instances.</param> /// <exception cref="ArgumentNullException">Thrown when <paramref name="calculation"/>, <paramref name="assessmentSection"/> /// or <paramref name="generalWaveConditionsInput"/> is <c>null</c>.</exception> /// <exception cref="ArgumentException">Thrown when the hydraulic boundary database file path contains invalid characters.</exception> /// <exception cref="CriticalFileReadException">Thrown when: /// <list type="bullet"> /// <item>No settings database file could be found at the location of hydraulic boundary database file path /// with the same name.</item> /// <item>Unable to open settings database file.</item> /// <item>Unable to read required data from database file.</item> /// </list> /// </exception> /// <exception cref="ArgumentOutOfRangeException">Thrown when the target probability or /// calculated probability falls outside the [0.0, 1.0] range and is not <see cref="double.NaN"/>.</exception> /// <exception cref="HydraRingFileParserException">Thrown when an error occurs during parsing of the Hydra-Ring output.</exception> /// <exception cref="HydraRingCalculationException">Thrown when an error occurs during the calculation.</exception> public void Calculate(WaveImpactAsphaltCoverWaveConditionsCalculation calculation, IAssessmentSection assessmentSection, GeneralWaveConditionsInput generalWaveConditionsInput) { if (calculation == null) { throw new ArgumentNullException(nameof(calculation)); } if (assessmentSection == null) { throw new ArgumentNullException(nameof(assessmentSection)); } if (generalWaveConditionsInput == null) { throw new ArgumentNullException(nameof(generalWaveConditionsInput)); } CalculationServiceHelper.LogCalculationBegin(); RoundedDouble a = generalWaveConditionsInput.A; RoundedDouble b = generalWaveConditionsInput.B; RoundedDouble c = generalWaveConditionsInput.C; double targetProbability = WaveConditionsInputHelper.GetTargetProbability(calculation.InputParameters, assessmentSection); RoundedDouble assessmentLevel = WaveConditionsInputHelper.GetAssessmentLevel(calculation.InputParameters, assessmentSection); CurrentCalculationType = Resources.WaveImpactAsphaltCover_DisplayName; TotalWaterLevelCalculations = calculation.InputParameters.GetWaterLevels(assessmentLevel).Count(); try { IEnumerable <WaveConditionsOutput> outputs = CalculateWaveConditions(calculation.InputParameters, assessmentLevel, a, b, c, targetProbability, assessmentSection.HydraulicBoundaryDatabase); if (!Canceled) { calculation.Output = new WaveImpactAsphaltCoverWaveConditionsOutput(outputs); } } finally { CalculationServiceHelper.LogCalculationEnd(); } }
/// <summary> /// Performs a piping calculation based on the supplied <see cref="SemiProbabilisticPipingCalculation"/> and sets /// <see cref="SemiProbabilisticPipingCalculation.Output"/> if the calculation was successful. Error and status /// information is logged during the execution of the operation. /// </summary> /// <param name="calculation">The <see cref="SemiProbabilisticPipingCalculation"/> to base the input for the calculation upon.</param> /// <param name="generalInput">The <see cref="GeneralPipingInput"/> to derive values from during the calculation.</param> /// <param name="normativeAssessmentLevel">The normative assessment level to use in case the manual assessment level is not applicable.</param> /// <exception cref="ArgumentNullException">Thrown when <paramref name="calculation"/> or <paramref name="generalInput"/> is <c>null</c>.</exception> /// <exception cref="PipingCalculatorException">Thrown when an unexpected error occurred during the calculation.</exception> /// <remarks>Consider calling <see cref="Validate"/> first to see if calculation is possible.</remarks> public static void Calculate(SemiProbabilisticPipingCalculation calculation, GeneralPipingInput generalInput, RoundedDouble normativeAssessmentLevel) { if (calculation == null) { throw new ArgumentNullException(nameof(calculation)); } if (generalInput == null) { throw new ArgumentNullException(nameof(generalInput)); } CalculationServiceHelper.LogCalculationBegin(); try { PipingCalculatorResult pipingResult = new PipingCalculator(CreateInputFromData(calculation.InputParameters, generalInput, normativeAssessmentLevel), PipingSubCalculatorFactory.Instance).Calculate(); calculation.Output = new SemiProbabilisticPipingOutput(new SemiProbabilisticPipingOutput.ConstructionProperties { UpliftFactorOfSafety = pipingResult.UpliftFactorOfSafety, HeaveFactorOfSafety = pipingResult.HeaveFactorOfSafety, SellmeijerFactorOfSafety = pipingResult.SellmeijerFactorOfSafety, UpliftEffectiveStress = pipingResult.UpliftEffectiveStress, HeaveGradient = pipingResult.HeaveGradient, SellmeijerCreepCoefficient = pipingResult.SellmeijerCreepCoefficient, SellmeijerCriticalFall = pipingResult.SellmeijerCriticalFall, SellmeijerReducedFall = pipingResult.SellmeijerReducedFall }); } catch (PipingCalculatorException e) { CalculationServiceHelper.LogExceptionAsError(RiskeerCommonServiceResources.CalculationService_Calculate_unexpected_error, e); throw; } finally { CalculationServiceHelper.LogCalculationEnd(); } }
/// <summary> /// Performs validation over the values on the given <paramref name="calculation"/>. Error and status information is logged during /// the execution of the operation. /// </summary> /// <param name="calculation">The <see cref="GrassCoverErosionInwardsCalculation"/> for which to validate the values.</param> /// <param name="assessmentSection">The <see cref="IAssessmentSection"/> for which to validate the values.</param> /// <returns><c>true</c> if <paramref name="calculation"/> has no validation errors; <c>false</c> otherwise.</returns> public static bool Validate(GrassCoverErosionInwardsCalculation calculation, IAssessmentSection assessmentSection) { CalculationServiceHelper.LogValidationBegin(); string[] hydraulicBoundaryDatabaseMessages = ValidateHydraulicBoundaryDatabase(assessmentSection).ToArray(); CalculationServiceHelper.LogMessagesAsError(hydraulicBoundaryDatabaseMessages); if (hydraulicBoundaryDatabaseMessages.Any()) { CalculationServiceHelper.LogValidationEnd(); return(false); } string[] messages = ValidateInput(calculation.InputParameters).ToArray(); CalculationServiceHelper.LogMessagesAsError(messages); CalculationServiceHelper.LogValidationEnd(); return(!messages.Any()); }
public void LogExceptionAsError_WithParameters_LogMessageAndException() { // Setup const string message = "Message"; var exception = new Exception(); // Call Action call = () => CalculationServiceHelper.LogExceptionAsError(message, exception); // Assert TestHelper.AssertLogMessagesWithLevelAndLoggedExceptions(call, tuples => { Tuple <string, Level, Exception> tuple = tuples.Single(); Assert.AreEqual(message, tuple.Item1); Assert.AreEqual(Level.Error, tuple.Item2); Assert.AreSame(exception, tuple.Item3); }); }
/// <summary> /// Performs validation over the values on the given <paramref name="calculation"/>. Error and status information is logged during /// the execution of the operation. /// </summary> /// <param name="calculation">The <see cref="StructuresCalculation{T}"/> for which to validate the values.</param> /// <param name="assessmentSection">The <see cref="IAssessmentSection"/> for which to validate the values.</param> /// <returns><c>true</c> if <paramref name="calculation"/> has no validation errors; <c>false</c> otherwise.</returns> /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception> /// <exception cref="InvalidEnumArgumentException">Thrown when an invalid enum value is encountered.</exception> /// <exception cref="NotSupportedException">Thrown when an unsupported enum value is encountered.</exception> public static bool Validate(StructuresCalculation <TStructureInput> calculation, IAssessmentSection assessmentSection) { if (calculation == null) { throw new ArgumentNullException(nameof(calculation)); } if (assessmentSection == null) { throw new ArgumentNullException(nameof(assessmentSection)); } CalculationServiceHelper.LogValidationBegin(); string[] messages = ValidateInput(calculation.InputParameters, assessmentSection); CalculationServiceHelper.LogMessagesAsError(messages); CalculationServiceHelper.LogValidationEnd(); return(!messages.Any()); }
public void LogMessagesAsErrorWithoutFormat_WithErrorMessages_LogsMessagesAsErrors() { // Setup var errorMessages = new[] { "Test 1", "Test 2" }; // Call Action call = () => CalculationServiceHelper.LogMessagesAsError(errorMessages); // Assert TestHelper.AssertLogMessagesWithLevelAreGenerated(call, new[] { Tuple.Create(errorMessages[0], LogLevelConstant.Error), Tuple.Create(errorMessages[1], LogLevelConstant.Error) }, 2); }
public void LogMessagesAsWarning_WithWarningMessages_LogsMessagesAsWarnings() { // Setup var warningMessages = new[] { "Test 1", "Test 2" }; // Call Action call = () => CalculationServiceHelper.LogMessagesAsWarning(warningMessages); // Assert TestHelper.AssertLogMessagesWithLevelAreGenerated(call, new[] { Tuple.Create(warningMessages[0], LogLevelConstant.Warn), Tuple.Create(warningMessages[1], LogLevelConstant.Warn) }, 2); }
public void LogMessagesAsErrorWithFormat_WithFormatAndErrorMessages_LogsMessagesAsErrorsInGivenFormat() { // Setup const string format = "Message: {0}"; var errorMessages = new[] { "Test 1", "Test 2" }; // Call Action call = () => CalculationServiceHelper.LogMessagesAsError(format, errorMessages); // Assert TestHelper.AssertLogMessagesWithLevelAreGenerated(call, new[] { Tuple.Create(string.Format(format, errorMessages[0]), LogLevelConstant.Error), Tuple.Create(string.Format(format, errorMessages[1]), LogLevelConstant.Error) }, 2); }
private static bool LogAnyErrors(SemiProbabilisticPipingCalculation calculation, GeneralPipingInput generalInput, RoundedDouble normativeAssessmentLevel) { string[] messages = ValidateInput(calculation.InputParameters, generalInput, normativeAssessmentLevel).ToArray(); if (messages.Length > 0) { CalculationServiceHelper.LogMessagesAsError(messages); return(true); } messages = new PipingCalculator(CreateInputFromData(calculation.InputParameters, generalInput, normativeAssessmentLevel), PipingSubCalculatorFactory.Instance).Validate().ToArray(); if (messages.Length > 0) { CalculationServiceHelper.LogMessagesAsError(messages); return(true); } return(false); }
/// <summary> /// Performs validation over the values on the given <paramref name="calculation"/>. Error and status information is logged during /// the execution of the operation. /// </summary> /// <param name="calculation">The <see cref="SemiProbabilisticPipingCalculation"/> for which to validate the values.</param> /// <param name="generalInput">The <see cref="GeneralPipingInput"/> to derive values from during the validation.</param> /// <param name="normativeAssessmentLevel">The normative assessment level to use in case the manual assessment level is not applicable.</param> /// <returns><c>false</c> if <paramref name="calculation"/> contains validation errors; <c>true</c> otherwise.</returns> /// <exception cref="ArgumentNullException">Thrown when <paramref name="calculation"/> or <paramref name="generalInput"/> is <c>null</c>.</exception> public static bool Validate(SemiProbabilisticPipingCalculation calculation, GeneralPipingInput generalInput, RoundedDouble normativeAssessmentLevel) { if (calculation == null) { throw new ArgumentNullException(nameof(calculation)); } if (generalInput == null) { throw new ArgumentNullException(nameof(generalInput)); } CalculationServiceHelper.LogValidationBegin(); LogAnyWarnings(calculation); bool hasErrors = LogAnyErrors(calculation, generalInput, normativeAssessmentLevel); CalculationServiceHelper.LogValidationEnd(); return(!hasErrors); }
/// <summary> /// Performs a structures calculation based on the supplied <see cref="StructuresCalculation{T}"/> and sets <see cref="StructuresCalculation{T}.Output"/> /// if the calculation was successful. Error and status information is logged during the execution of the operation. /// </summary> /// <param name="calculation">The <see cref="StructuresCalculation{T}"/> that holds all the information required to perform the calculation.</param> /// <param name="generalInput">General calculation parameters that are the same across all calculations.</param> /// <param name="calculationSettings">The <see cref="HydraulicBoundaryCalculationSettings"/> with the /// hydraulic boundary calculation settings.</param> /// <remarks>Preprocessing is disabled when the preprocessor directory equals <see cref="string.Empty"/>.</remarks> /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception> /// <exception cref="ArgumentException">Thrown when the hydraulic boundary database file path /// contains invalid characters.</exception> /// <exception cref="InvalidEnumArgumentException">Thrown when an unexpected /// enum value is encountered.</exception> /// <exception cref="CriticalFileReadException">Thrown when: /// <list type="bullet"> /// <item>No settings database file could be found at the location of the hydraulic boundary database file path /// with the same name.</item> /// <item>Unable to open settings database file.</item> /// <item>Unable to read required data from database file.</item> /// </list></exception> /// <exception cref="HydraRingCalculationException">Thrown when an error occurs while performing the calculation.</exception> public void Calculate(StructuresCalculation <TStructureInput> calculation, TGeneralInput generalInput, HydraulicBoundaryCalculationSettings calculationSettings) { if (calculation == null) { throw new ArgumentNullException(nameof(calculation)); } if (generalInput == null) { throw new ArgumentNullException(nameof(generalInput)); } if (calculationSettings == null) { throw new ArgumentNullException(nameof(calculationSettings)); } TCalculationInput input = CreateInput(calculation.InputParameters, generalInput, calculationSettings.HydraulicBoundaryDatabaseFilePath, !string.IsNullOrEmpty(calculationSettings.PreprocessorDirectory)); calculator = HydraRingCalculatorFactory.Instance.CreateStructuresCalculator <TCalculationInput>( HydraRingCalculationSettingsFactory.CreateSettings(calculationSettings)); string calculationName = calculation.Name; CalculationServiceHelper.LogCalculationBegin(); var exceptionThrown = false; try { PerformCalculation(calculation, input); } catch (HydraRingCalculationException) { if (!canceled) { string lastErrorFileContent = calculator.LastErrorFileContent; string message = string.IsNullOrEmpty(lastErrorFileContent) ? messageProvider.GetCalculationFailedMessage(calculationName) : messageProvider.GetCalculationFailedWithErrorReportMessage(calculationName, lastErrorFileContent); log.Error(message); exceptionThrown = true; throw; } } finally { string lastErrorFileContent = calculator.LastErrorFileContent; bool errorOccurred = CalculationServiceHelper.HasErrorOccurred(canceled, exceptionThrown, lastErrorFileContent); if (errorOccurred) { log.Error(messageProvider.GetCalculationFailedWithErrorReportMessage(calculationName, lastErrorFileContent)); } log.Info(messageProvider.GetCalculationPerformedMessage(calculator.OutputDirectory)); CalculationServiceHelper.LogCalculationEnd(); if (errorOccurred) { throw new HydraRingCalculationException(lastErrorFileContent); } } }
/// <summary> /// Performs a grass cover erosion inwards calculation. /// </summary> /// <param name="performCalculation">The action that performs the calculation.</param> /// <param name="getLastErrorFileContent">The function for obtaining the last error file content.</param> /// <param name="getOutputDirectory">The function for obtaining the output directory.</param> /// <param name="calculationName">The name of the calculation to perform.</param> /// <param name="stepName">The name of the step to perform.</param> /// <exception cref="HydraRingCalculationException">Thrown when an error occurs while performing the calculation.</exception> private void PerformCalculation(Action performCalculation, Func <string> getLastErrorFileContent, Func <string> getOutputDirectory, string calculationName, string stepName) { var exceptionThrown = false; try { performCalculation(); } catch (HydraRingCalculationException) { if (!canceled) { string lastErrorFileContent = getLastErrorFileContent(); if (string.IsNullOrEmpty(lastErrorFileContent)) { log.ErrorFormat( Resources.GrassCoverErosionInwardsCalculationService_Calculate_Error_in_calculation_of_type_0_for_calculation_with_name_1_no_error_report, stepName, calculationName); } else { log.ErrorFormat( Resources.GrassCoverErosionInwardsCalculationService_Calculate_Error_in_calculation_of_type_0_for_calculation_with_name_1_click_details_for_last_error_report_2, stepName, calculationName, lastErrorFileContent); } exceptionThrown = true; throw; } } finally { string lastErrorFileContent = getLastErrorFileContent(); bool errorOccurred = CalculationServiceHelper.HasErrorOccurred(canceled, exceptionThrown, lastErrorFileContent); if (errorOccurred) { log.ErrorFormat( Resources.GrassCoverErosionInwardsCalculationService_Calculate_Error_in_calculation_of_type_0_for_calculation_with_name_1_click_details_for_last_error_report_2, stepName, calculationName, lastErrorFileContent); } log.InfoFormat( Resources.GrassCoverErosionInwardsCalculationService_Calculate_Calculation_of_type_0_performed_in_temporary_directory_1, stepName, getOutputDirectory()); if (errorOccurred) { throw new HydraRingCalculationException(lastErrorFileContent); } } }
/// <summary> /// Performs a grass cover erosion inwards calculation based on the supplied <see cref="GrassCoverErosionInwardsCalculation"/> /// and sets <see cref="GrassCoverErosionInwardsCalculation.Output"/> if the calculation was successful. Error and status /// information is logged during the execution of the operation. /// </summary> /// <param name="calculation">The <see cref="GrassCoverErosionInwardsCalculation"/> that holds all the information required to perform the calculation.</param> /// <param name="assessmentSection">The <see cref="IAssessmentSection"/> that holds information about the target probability used in the calculation.</param> /// <param name="generalInput">Calculation input parameters that apply to all <see cref="GrassCoverErosionInwardsCalculation"/> instances.</param> /// <exception cref="ArgumentNullException">Thrown when one of the following parameters is <c>null</c>: /// <list type="bullet"> /// <item><paramref name="calculation"/></item> /// <item><paramref name="assessmentSection"/></item> /// <item><paramref name="generalInput"/></item> /// </list></exception> /// <exception cref="ArgumentException">Thrown when the hydraulic boundary database file path contains invalid characters.</exception> /// <exception cref="CriticalFileReadException">Thrown when: /// <list type="bullet"> /// <item>No settings database file could be found at the location of the hydraulic boundary database file path /// with the same name.</item> /// <item>Unable to open settings database file.</item> /// <item>Unable to read required data from database file.</item> /// </list> /// </exception> /// <exception cref="SecurityException">Thrown when the temporary working directory can't be accessed due to missing permissions.</exception> /// <exception cref="IOException">Thrown when the specified path is not valid, the network name is not known /// or an I/O error occurred while opening the file.</exception> /// <exception cref="UnauthorizedAccessException">Thrown when the directory can't be created due to missing /// the required permissions.</exception> /// <exception cref="NotSupportedException">Thrown when <see cref="HydraRingCalculationInput.FailureMechanismType"/> /// is not the same with already added input.</exception> /// <exception cref="Win32Exception">Thrown when there was an error in opening the associated file /// or the wait setting could not be accessed.</exception> /// <exception cref="HydraRingFileParserException">Thrown when an error occurs during parsing of the Hydra-Ring output.</exception> /// <exception cref="HydraRingCalculationException">Thrown when an error occurs during the calculation.</exception> internal void Calculate(GrassCoverErosionInwardsCalculation calculation, IAssessmentSection assessmentSection, GeneralGrassCoverErosionInwardsInput generalInput) { if (calculation == null) { throw new ArgumentNullException(nameof(calculation)); } if (assessmentSection == null) { throw new ArgumentNullException(nameof(assessmentSection)); } if (generalInput == null) { throw new ArgumentNullException(nameof(generalInput)); } HydraulicBoundaryCalculationSettings calculationSettings = HydraulicBoundaryCalculationSettingsFactory.CreateSettings(assessmentSection.HydraulicBoundaryDatabase); int numberOfCalculators = CreateCalculators(calculation, calculationSettings); string hydraulicBoundaryDatabaseFilePath = calculationSettings.HydraulicBoundaryDatabaseFilePath; bool usePreprocessor = !string.IsNullOrEmpty(calculationSettings.PreprocessorDirectory); CalculationServiceHelper.LogCalculationBegin(); try { OvertoppingOutput overtoppingOutput = CalculateOvertopping(calculation, generalInput, hydraulicBoundaryDatabaseFilePath, usePreprocessor, numberOfCalculators); if (canceled) { return; } DikeHeightOutput dikeHeightOutput = CalculateDikeHeight(calculation, generalInput, hydraulicBoundaryDatabaseFilePath, usePreprocessor, numberOfCalculators); if (canceled) { return; } OvertoppingRateOutput overtoppingRateOutput = CalculateOvertoppingRate(calculation, generalInput, hydraulicBoundaryDatabaseFilePath, usePreprocessor, numberOfCalculators); if (canceled) { return; } calculation.Output = new GrassCoverErosionInwardsOutput( overtoppingOutput, dikeHeightOutput, overtoppingRateOutput); } finally { CalculationServiceHelper.LogCalculationEnd(); overtoppingCalculator = null; dikeHeightCalculator = null; overtoppingRateCalculator = null; } }
/// <summary> /// Performs a wave conditions calculation for the stability of stone revetment failure mechanism based on the supplied /// <see cref="StabilityStoneCoverWaveConditionsCalculation"/> and sets /// <see cref="StabilityStoneCoverWaveConditionsCalculation.Output"/> if the calculation was successful. /// Error and status information is logged during the execution of the operation. /// </summary> /// <param name="calculation">The <see cref="StabilityStoneCoverWaveConditionsCalculation"/> that holds all the information required to perform the calculation.</param> /// <param name="assessmentSection">The <see cref="IAssessmentSection"/> that holds information about the target probability used in the calculation.</param> /// <param name="generalWaveConditionsInput">Calculation input parameters that apply to all <see cref="StabilityStoneCoverWaveConditionsCalculation"/> instances.</param> /// <exception cref="ArgumentNullException">Thrown when <paramref name="calculation"/>, <paramref name="assessmentSection"/> /// or <paramref name="generalWaveConditionsInput"/> is <c>null</c>.</exception> /// <exception cref="ArgumentException">Thrown when the hydraulic boundary database file path contains invalid characters.</exception> /// <exception cref="CriticalFileReadException">Thrown when: /// <list type="bullet"> /// <item>No settings database file could be found at the location of the hydraulic boundary database file path /// with the same name.</item> /// <item>Unable to open settings database file.</item> /// <item>Unable to read required data from database file.</item> /// </list> /// </exception> /// <exception cref="ArgumentOutOfRangeException">Thrown when the target probability or /// calculated probability falls outside the [0.0, 1.0] range and is not <see cref="double.NaN"/>.</exception> /// <exception cref="HydraRingFileParserException">Thrown when an error occurs during parsing of the Hydra-Ring output.</exception> /// <exception cref="HydraRingCalculationException">Thrown when an error occurs during the calculation.</exception> public void Calculate(StabilityStoneCoverWaveConditionsCalculation calculation, IAssessmentSection assessmentSection, GeneralStabilityStoneCoverWaveConditionsInput generalWaveConditionsInput) { if (calculation == null) { throw new ArgumentNullException(nameof(calculation)); } if (assessmentSection == null) { throw new ArgumentNullException(nameof(assessmentSection)); } if (generalWaveConditionsInput == null) { throw new ArgumentNullException(nameof(generalWaveConditionsInput)); } StabilityStoneCoverWaveConditionsInput calculationInput = calculation.InputParameters; StabilityStoneCoverWaveConditionsCalculationType calculationType = calculationInput.CalculationType; if (!Enum.IsDefined(typeof(StabilityStoneCoverWaveConditionsCalculationType), calculationType)) { throw new InvalidEnumArgumentException(nameof(calculationType), (int)calculationType, typeof(StabilityStoneCoverWaveConditionsCalculationType)); } CalculationServiceHelper.LogCalculationBegin(); double targetProbability = WaveConditionsInputHelper.GetTargetProbability(calculationInput, assessmentSection); RoundedDouble assessmentLevel = WaveConditionsInputHelper.GetAssessmentLevel(calculationInput, assessmentSection); int waterLevelCount = calculationInput.GetWaterLevels(assessmentLevel).Count(); TotalWaterLevelCalculations = calculationType == StabilityStoneCoverWaveConditionsCalculationType.Both ? waterLevelCount * 2 : waterLevelCount; try { IEnumerable <WaveConditionsOutput> blocksOutputs = null; if (calculationType == StabilityStoneCoverWaveConditionsCalculationType.Both || calculationType == StabilityStoneCoverWaveConditionsCalculationType.Blocks) { CurrentCalculationType = Resources.StabilityStoneCoverWaveConditions_Blocks_DisplayName; blocksOutputs = CalculateBlocks(calculation, assessmentSection, assessmentLevel, generalWaveConditionsInput.GeneralBlocksWaveConditionsInput, targetProbability); } if (Canceled) { return; } IEnumerable <WaveConditionsOutput> columnsOutputs = null; if (calculationType == StabilityStoneCoverWaveConditionsCalculationType.Both || calculationType == StabilityStoneCoverWaveConditionsCalculationType.Columns) { CurrentCalculationType = Resources.StabilityStoneCoverWaveConditions_Columns_DisplayName; columnsOutputs = CalculateColumns(calculation, assessmentSection, assessmentLevel, generalWaveConditionsInput.GeneralColumnsWaveConditionsInput, targetProbability); } if (!Canceled) { calculation.Output = CreateOutput(calculationType, blocksOutputs, columnsOutputs); } } finally { CalculationServiceHelper.LogCalculationEnd(); } }
/// <summary> /// Performs validation over the values on the given <paramref name="calculation"/>. Error and status information is logged during /// the execution of the operation. /// </summary> /// <param name="calculation">The <see cref="MacroStabilityInwardsCalculation"/> for which to validate the values.</param> /// <param name="generalInput">General calculation parameters that are the same across all calculations.</param> /// <param name="normativeAssessmentLevel">The normative assessment level to use in case the manual assessment level is not applicable.</param> /// <returns><c>false</c> if <paramref name="calculation"/> contains validation errors; <c>true</c> otherwise.</returns> /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception> public static bool Validate(MacroStabilityInwardsCalculation calculation, GeneralMacroStabilityInwardsInput generalInput, RoundedDouble normativeAssessmentLevel) { if (calculation == null) { throw new ArgumentNullException(nameof(calculation)); } if (generalInput == null) { throw new ArgumentNullException(nameof(generalInput)); } CalculationServiceHelper.LogValidationBegin(); string[] inputValidationResults = MacroStabilityInwardsInputValidator.Validate(calculation.InputParameters, normativeAssessmentLevel).ToArray(); if (inputValidationResults.Length > 0) { CalculationServiceHelper.LogMessagesAsError(inputValidationResults); CalculationServiceHelper.LogValidationEnd(); return(false); } IEnumerable <MacroStabilityInwardsKernelMessage> waternetExtremeKernelMessages; IEnumerable <MacroStabilityInwardsKernelMessage> waternetDailyKernelMessages; try { waternetExtremeKernelMessages = ValidateWaternet(() => WaternetCalculationService.ValidateExtreme( calculation.InputParameters, generalInput, GetEffectiveAssessmentLevel(calculation.InputParameters, normativeAssessmentLevel)), Resources.MacroStabilityInwardsCalculationService_Validate_Waternet_extreme_validation_started); waternetDailyKernelMessages = ValidateWaternet(() => WaternetCalculationService.ValidateDaily(calculation.InputParameters, generalInput), Resources.MacroStabilityInwardsCalculationService_Validate_Waternet_daily_validation_started); } catch (WaternetCalculationException e) { HandleExceptionOnValidation(e); return(false); } IEnumerable <MacroStabilityInwardsKernelMessage> kernelMessages = Enumerable.Empty <MacroStabilityInwardsKernelMessage>(); if (!waternetExtremeKernelMessages.Any() && !waternetDailyKernelMessages.Any()) { IUpliftVanCalculator calculator = GetCalculator(calculation, generalInput, normativeAssessmentLevel); try { kernelMessages = calculator.Validate().ToArray(); } catch (UpliftVanCalculatorException e) { HandleExceptionOnValidation(e); return(false); } LogKernelMessages(kernelMessages); } CalculationServiceHelper.LogValidationEnd(); return(kernelMessages.Concat(waternetDailyKernelMessages) .Concat(waternetExtremeKernelMessages) .All(r => r.Type != MacroStabilityInwardsKernelMessageType.Error)); }
/// <summary> /// Performs a wave conditions calculation for the grass cover erosion outwards failure mechanism based on the supplied /// <see cref="GrassCoverErosionOutwardsWaveConditionsCalculation"/> and sets /// <see cref="GrassCoverErosionOutwardsWaveConditionsCalculation.Output"/> if the calculation was successful. /// Error and status information is logged during the execution of the operation. /// </summary> /// <param name="calculation">The <see cref="GrassCoverErosionOutwardsWaveConditionsCalculation"/> that holds all the information required to perform the calculation.</param> /// <param name="failureMechanism">The grass cover erosion outwards failure mechanism, which contains general parameters that apply to all /// <see cref="GrassCoverErosionOutwardsWaveConditionsCalculation"/> instances.</param> /// <param name="assessmentSection">The <see cref="IAssessmentSection"/> that holds information about the target probability used in the calculation.</param> /// <exception cref="ArgumentNullException">Thrown when <paramref name="calculation"/>, <paramref name="failureMechanism"/> /// or <paramref name="assessmentSection"/> is <c>null</c>.</exception> /// <exception cref="ArgumentException">Thrown when: /// <list type="bullet"> /// <item>the hydraulic boundary database file path contains invalid characters.</item> /// <item><paramref name="failureMechanism"/> has no (0) contribution.</item> /// </list></exception> /// <exception cref="InvalidEnumArgumentException">Thrown when an unexpected /// enum value is encountered.</exception> /// <exception cref="CriticalFileReadException">Thrown when: /// <list type="bullet"> /// <item>No settings database file could be found at the location of the hydraulic boundary database file path /// with the same name.</item> /// <item>Unable to open settings database file.</item> /// <item>Unable to read required data from database file.</item> /// </list> /// </exception> /// <exception cref="ArgumentOutOfRangeException">Thrown when the target probability or /// calculated probability falls outside the [0.0, 1.0] range and is not <see cref="double.NaN"/>.</exception> /// <exception cref="HydraRingFileParserException">Thrown when an error occurs during parsing of the Hydra-Ring output.</exception> /// <exception cref="HydraRingCalculationException">Thrown when an error occurs during the calculation.</exception> /// <exception cref="NotSupportedException">Thrown when <see cref="GrassCoverErosionOutwardsWaveConditionsCalculationType"/> /// is a valid value, but unsupported.</exception> public void Calculate(GrassCoverErosionOutwardsWaveConditionsCalculation calculation, GrassCoverErosionOutwardsFailureMechanism failureMechanism, IAssessmentSection assessmentSection) { if (calculation == null) { throw new ArgumentNullException(nameof(calculation)); } if (failureMechanism == null) { throw new ArgumentNullException(nameof(failureMechanism)); } if (assessmentSection == null) { throw new ArgumentNullException(nameof(assessmentSection)); } GrassCoverErosionOutwardsWaveConditionsInput calculationInput = calculation.InputParameters; GrassCoverErosionOutwardsWaveConditionsCalculationType calculationType = calculationInput.CalculationType; if (!Enum.IsDefined(typeof(GrassCoverErosionOutwardsWaveConditionsCalculationType), calculationType)) { throw new InvalidEnumArgumentException(nameof(calculationType), (int)calculationType, typeof(GrassCoverErosionOutwardsWaveConditionsCalculationType)); } CalculationServiceHelper.LogCalculationBegin(); RoundedDouble assessmentLevel = WaveConditionsInputHelper.GetAssessmentLevel(calculationInput, assessmentSection); double targetProbability = WaveConditionsInputHelper.GetTargetProbability(calculationInput, assessmentSection); HydraulicBoundaryDatabase hydraulicBoundaryDatabase = assessmentSection.HydraulicBoundaryDatabase; DetermineTotalWaterLevelCalculations(calculationInput, assessmentLevel); try { IEnumerable <WaveConditionsOutput> waveRunUpOutput = null; if (ShouldCalculateWaveRunUp(calculationType)) { CurrentCalculationType = Resources.GrassCoverErosionOutwardsWaveConditions_WaveRunUp_DisplayName; waveRunUpOutput = CalculateWaveRunUp(calculation, failureMechanism, hydraulicBoundaryDatabase, assessmentLevel, targetProbability); } if (Canceled) { return; } IEnumerable <WaveConditionsOutput> waveImpactOutput = null; if (ShouldCalculateWaveImpact(calculationType)) { CurrentCalculationType = Resources.GrassCoverErosionOutwardsWaveConditions_WaveImpact_DisplayName; waveImpactOutput = CalculateWaveImpact(calculation, failureMechanism, hydraulicBoundaryDatabase, assessmentLevel, targetProbability); } IEnumerable <WaveConditionsOutput> waveImpactWithWaveDirectionOutput = null; if (ShouldCalculateWaveImpactWithWaveDirection(calculationType)) { CurrentCalculationType = Resources.GrassCoverErosionOutwardsWaveConditions_WaveImpactWithWaveDirection_DisplayName; waveImpactWithWaveDirectionOutput = CalculateWaveImpactWithWaveDirection(calculation, failureMechanism, hydraulicBoundaryDatabase, assessmentLevel, targetProbability); } if (!Canceled) { calculation.Output = CreateOutput(calculationType, waveRunUpOutput, waveImpactOutput, waveImpactWithWaveDirectionOutput); } } finally { CalculationServiceHelper.LogCalculationEnd(); } }
/// <summary> /// Performs the provided <see cref="DuneLocationCalculation"/> and sets its output if the calculation is successful. /// Error and status information is logged during the execution of the operation. /// </summary> /// <param name="duneLocationCalculation">The <see cref="DuneLocationCalculation"/> to perform.</param> /// <param name="targetProbability">The target probability to use during the calculation.</param> /// <param name="calculationSettings">The <see cref="HydraulicBoundaryCalculationSettings"/> with the /// hydraulic boundary calculation settings.</param> /// <param name="messageProvider">The object which is used to build log messages.</param> /// <remarks>Preprocessing is disabled when the preprocessor directory equals <see cref="string.Empty"/>.</remarks> /// <exception cref="ArgumentNullException">Thrown when <paramref name="duneLocationCalculation"/>, /// <paramref name="calculationSettings"/> or <paramref name="messageProvider"/> is <c>null</c>.</exception> /// <exception cref="ArgumentException">Thrown when: /// <list type="bullet"> /// <item>The hydraulic boundary location database file path contains invalid characters.</item> /// <item>The contribution of the failure mechanism is zero.</item> /// <item>The target probability or the calculated probability falls outside the [0.0, 1.0] /// range and is not <see cref="double.NaN"/>.</item> /// </list></exception> /// <exception cref="CriticalFileReadException">Thrown when: /// <list type="bullet"> /// <item>No settings database file could be found at the location of the hydraulic boundary database /// with the same name.</item> /// <item>Unable to open settings database file.</item> /// <item>Unable to read required data from database file.</item> /// </list></exception> /// <exception cref="HydraRingCalculationException">Thrown when an error occurs while performing /// the calculation.</exception> public void Calculate(DuneLocationCalculation duneLocationCalculation, double targetProbability, HydraulicBoundaryCalculationSettings calculationSettings, ICalculationMessageProvider messageProvider) { if (duneLocationCalculation == null) { throw new ArgumentNullException(nameof(duneLocationCalculation)); } if (calculationSettings == null) { throw new ArgumentNullException(nameof(calculationSettings)); } if (messageProvider == null) { throw new ArgumentNullException(nameof(messageProvider)); } DuneLocation duneLocation = duneLocationCalculation.DuneLocation; string duneLocationName = duneLocation.Name; CalculationServiceHelper.LogCalculationBegin(); HydraRingCalculationSettings hydraRingCalculationSettings = HydraRingCalculationSettingsFactory.CreateSettings(calculationSettings); calculator = HydraRingCalculatorFactory.Instance.CreateDunesBoundaryConditionsCalculator(hydraRingCalculationSettings); var exceptionThrown = false; try { DunesBoundaryConditionsCalculationInput calculationInput = CreateInput(duneLocation, targetProbability, calculationSettings); calculator.Calculate(calculationInput); if (string.IsNullOrEmpty(calculator.LastErrorFileContent)) { duneLocationCalculation.Output = CreateDuneLocationCalculationOutput(duneLocationName, calculationInput.Beta, targetProbability, messageProvider); } } catch (HydraRingCalculationException) { if (!canceled) { string lastErrorContent = calculator.LastErrorFileContent; log.Error(string.IsNullOrEmpty(lastErrorContent) ? messageProvider.GetCalculationFailedMessage(duneLocationName) : messageProvider.GetCalculationFailedWithErrorReportMessage(duneLocationName, lastErrorContent)); exceptionThrown = true; throw; } } finally { string lastErrorFileContent = calculator.LastErrorFileContent; bool hasErrorOccurred = CalculationServiceHelper.HasErrorOccurred(canceled, exceptionThrown, lastErrorFileContent); if (hasErrorOccurred) { log.Error(messageProvider.GetCalculationFailedWithErrorReportMessage(duneLocationName, lastErrorFileContent)); } log.InfoFormat(Resources.DuneLocationCalculationService_Calculate_Calculation_temporary_directory_can_be_found_on_location_0, calculator.OutputDirectory); CalculationServiceHelper.LogCalculationEnd(); if (hasErrorOccurred) { throw new HydraRingCalculationException(lastErrorFileContent); } } }
/// <summary> /// Calculates values for a single water level. /// </summary> /// <param name="waterLevel">The level of the water.</param> /// <param name="a">The 'a' factor decided on failure mechanism level.</param> /// <param name="b">The 'b' factor decided on failure mechanism level.</param> /// <param name="c">The 'c' factor decided on failure mechanism level.</param> /// <param name="targetProbability">The target probability to use.</param> /// <param name="input">The input that is different per calculation.</param> /// <param name="calculationSettings">The <see cref="HydraulicBoundaryCalculationSettings"/> containing all data /// to perform a hydraulic boundary calculation.</param> /// <returns>A <see cref="WaveConditionsOutput"/> if the calculation was successful; or <c>null</c> if it was canceled.</returns> /// <remarks>Preprocessing is disabled when the preprocessor directory equals <see cref="string.Empty"/>.</remarks> /// <exception cref="ArgumentException">Thrown when the hydraulic boundary database file path /// contains invalid characters.</exception> /// <exception cref="CriticalFileReadException">Thrown when: /// <list type="bullet"> /// <item>No settings database file could be found at the location of the hydraulic boundary database file path /// with the same name.</item> /// <item>Unable to open settings database file.</item> /// <item>Unable to read required data from database file.</item> /// </list> /// </exception> private WaveConditionsOutput CalculateWaterLevel(RoundedDouble waterLevel, RoundedDouble a, RoundedDouble b, RoundedDouble c, double targetProbability, WaveConditionsInput input, HydraulicBoundaryCalculationSettings calculationSettings) { HydraRingCalculationSettings settings = HydraRingCalculationSettingsFactory.CreateSettings(calculationSettings); calculator = HydraRingCalculatorFactory.Instance.CreateWaveConditionsCosineCalculator(settings); WaveConditionsCosineCalculationInput calculationInput = CreateInput(waterLevel, a, b, c, targetProbability, input, calculationSettings); WaveConditionsOutput output; var exceptionThrown = false; try { calculator.Calculate(calculationInput); output = WaveConditionsOutputFactory.CreateOutput(waterLevel, calculator.WaveHeight, calculator.WavePeakPeriod, calculator.WaveAngle, calculator.WaveDirection, targetProbability, calculator.ReliabilityIndex, calculator.Converged); } catch (Exception e) when(e is HydraRingCalculationException || e is ArgumentOutOfRangeException) { if (!Canceled) { string lastErrorContent = calculator.LastErrorFileContent; if (string.IsNullOrEmpty(lastErrorContent)) { log.ErrorFormat(CultureInfo.CurrentCulture, Resources.WaveConditionsCalculationService_CalculateWaterLevel_Error_in_wave_conditions_calculation_for_waterlevel_0_no_error_report, waterLevel); } else { log.ErrorFormat(CultureInfo.CurrentCulture, Resources.WaveConditionsCalculationService_CalculateWaterLevel_Error_in_wave_conditions_calculation_for_waterlevel_0_click_details_for_last_error_report_1, waterLevel, lastErrorContent); } exceptionThrown = true; } output = null; } finally { string lastErrorFileContent = calculator.LastErrorFileContent; bool errorOccurred = CalculationServiceHelper.HasErrorOccurred(Canceled, exceptionThrown, lastErrorFileContent); if (errorOccurred) { log.ErrorFormat(CultureInfo.CurrentCulture, Resources.WaveConditionsCalculationService_CalculateWaterLevel_Error_in_wave_conditions_calculation_for_waterlevel_0_click_details_for_last_error_report_1, waterLevel, lastErrorFileContent); } log.InfoFormat(CultureInfo.CurrentCulture, Resources.WaveConditionsCalculationService_CalculateWaterLevel_Calculation_temporary_directory_can_be_found_on_location_0, calculator.OutputDirectory); if (errorOccurred) { output = null; } } return(output); }