public void CreateStructuresCalculator_Always_ReturnsStructuresCalculator() { // Setup HydraRingCalculationSettings settings = HydraRingCalculationSettingsTestFactory.CreateSettings(); // Call IStructuresCalculator <ExceedanceProbabilityCalculationInput> calculator = HydraRingCalculatorFactory.Instance.CreateStructuresCalculator <ExceedanceProbabilityCalculationInput>(settings); // Assert Assert.IsInstanceOf <StructuresCalculator <ExceedanceProbabilityCalculationInput> >(calculator); }
/// <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); } } }