Index: Ringtoets/Revetment/src/Ringtoets.Revetment.Service/WaveConditionsCalculationServiceBase.cs
===================================================================
diff -u -r876e8dad04c55d7c515f485312be8c3acf899740 -r6ddf92411860d3f692da3018e1662e633003e0a9
--- Ringtoets/Revetment/src/Ringtoets.Revetment.Service/WaveConditionsCalculationServiceBase.cs (.../WaveConditionsCalculationServiceBase.cs) (revision 876e8dad04c55d7c515f485312be8c3acf899740)
+++ Ringtoets/Revetment/src/Ringtoets.Revetment.Service/WaveConditionsCalculationServiceBase.cs (.../WaveConditionsCalculationServiceBase.cs) (revision 6ddf92411860d3f692da3018e1662e633003e0a9)
@@ -52,6 +52,9 @@
private int currentStep = 1;
private IWaveConditionsCosineCalculator calculator;
+ ///
+ /// Cancels any currently running wave conditions calculation.
+ ///
public void Cancel()
{
if (calculator != null)
@@ -61,18 +64,34 @@
Canceled = true;
}
- protected bool Canceled { get; set; }
+ ///
+ /// Gets whether the calculation is canceled or not.
+ ///
+ protected bool Canceled { get; private set; }
- protected static bool ValidateWaveConditionsInput(WaveConditionsInput waveConditionsInput, string name, string hydraulicBoundaryDatabaseFilePath, string calculatedValueName)
+ ///
+ /// Performs validation over the values on the given .
+ /// Error and status information is logged during the execution of the operation.
+ ///
+ /// The input of the calculation.
+ /// The name of the calculation.
+ /// The directory of the HLCD file that should be used for performing the calculation.
+ /// The name of the design water level property.
+ /// Truec> if has no validation errors; Falsec> otherwise.
+ /// Thrown when is null.
+ protected static bool ValidateWaveConditionsInput(WaveConditionsInput waveConditionsInput,
+ string name,
+ string hydraulicBoundaryDatabaseFilePath,
+ string designWaterLevelName)
{
- if (calculatedValueName == null)
+ if (designWaterLevelName == null)
{
- throw new ArgumentNullException("calculatedValueName");
+ throw new ArgumentNullException("designWaterLevelName");
}
CalculationServiceHelper.LogValidationBeginTime(name);
- string[] messages = ValidateInput(hydraulicBoundaryDatabaseFilePath, waveConditionsInput, calculatedValueName);
+ string[] messages = ValidateInput(hydraulicBoundaryDatabaseFilePath, waveConditionsInput, designWaterLevelName);
CalculationServiceHelper.LogMessagesAsError(RingtoetsCommonServiceResources.Error_in_validation_0, messages);
@@ -81,21 +100,36 @@
return !messages.Any();
}
- protected IEnumerable CalculateWaveConditions(string calculationName, WaveConditionsInput waveConditionsInput, RoundedDouble a, RoundedDouble b, RoundedDouble c, double norm, string ringId, string hlcdFilePath)
+ ///
+ /// Performs a wave conditoins calculation based on the supplied and returns the output.
+ /// Error and status information is logged during the execution of the operation.
+ ///
+ /// The name of the calculation.
+ /// The that holds all the information required to perform the calculation.
+ /// The 'a' factor decided on failure mechanism level.
+ /// The 'b' factor decided on failure mechanism level.
+ /// The 'c' factor decided on failure mechanism level.
+ /// The norm to use as the target.
+ /// The id of the assessment section for which calculations are performed.
+ /// The directory of the hydraulic boundary database.
+ /// An of .
+ protected IEnumerable CalculateWaveConditions(string calculationName,
+ WaveConditionsInput waveConditionsInput,
+ RoundedDouble a,
+ RoundedDouble b,
+ RoundedDouble c,
+ double norm,
+ string ringId,
+ string hlcdFilePath)
{
var outputs = new List();
var waterLevels = waveConditionsInput.WaterLevels.ToArray();
- foreach (var waterLevel in waterLevels)
+ foreach (var waterLevel in waterLevels.TakeWhile(waterLevel => !Canceled))
{
- if (Canceled)
- {
- break;
- }
-
log.Info(string.Format(Resources.WaveConditionsCalculationService_OnRun_Subject_0_for_waterlevel_1_started,
- calculationName,
- waterLevel));
+ calculationName,
+ waterLevel));
NotifyProgress(waterLevel, currentStep++, TotalWaterLevelCalculations);
@@ -115,33 +149,33 @@
}
log.Info(string.Format(Resources.WaveConditionsCalculationService_OnRun_Subject_0_for_waterlevel_1_ended,
- calculationName,
- waterLevel));
+ calculationName,
+ waterLevel));
}
return outputs;
}
- protected static string[] ValidateInput(string hydraulicBoundaryDatabaseFilePath,
+ private static string[] ValidateInput(string hydraulicBoundaryDatabaseFilePath,
WaveConditionsInput input,
- string calculatedValueName)
+ string designWaterLevelName)
{
- List validationResult = new List();
+ var validationResults = new List();
string validationProblem = HydraulicDatabaseHelper.ValidatePathForCalculation(hydraulicBoundaryDatabaseFilePath);
if (!string.IsNullOrEmpty(validationProblem))
{
- validationResult.Add(validationProblem);
+ validationResults.Add(validationProblem);
}
else
{
- string message = ValidateWaveConditionsInput(input, calculatedValueName);
+ string message = ValidateWaveConditionsInput(input, designWaterLevelName);
if (!string.IsNullOrEmpty(message))
{
- validationResult.Add(message);
+ validationResults.Add(message);
}
}
- return validationResult.ToArray();
+ return validationResults.ToArray();
}
private void NotifyProgress(RoundedDouble waterLevel, int currentStepNumber, int totalStepsNumber)
@@ -166,7 +200,15 @@
/// The id of the assessment section for which calculations are performed.
/// The name used for logging.
/// A if the calcultion was succesful; or null if it was canceled.
- private WaveConditionsOutput CalculateWaterLevel(RoundedDouble waterLevel, double a, double b, double c, double norm, WaveConditionsInput input, string hlcdDirectory, string ringId, string name)
+ private WaveConditionsOutput CalculateWaterLevel(RoundedDouble waterLevel,
+ RoundedDouble a,
+ RoundedDouble b,
+ RoundedDouble c,
+ double norm,
+ WaveConditionsInput input,
+ string hlcdDirectory,
+ string ringId,
+ string name)
{
calculator = HydraRingCalculatorFactory.Instance.CreateWaveConditionsCosineCalculator(hlcdDirectory, ringId);
WaveConditionsCosineCalculationInput calculationInput = CreateInput(waterLevel, a, b, c, norm, input);
@@ -184,17 +226,20 @@
{
if (!Canceled)
{
- log.ErrorFormat(CultureInfo.CurrentCulture, Resources.WaveConditionsCalculationService_VerifyWaveConditionsCalculationOutput_Error_in_wave_conditions_calculation_0_for_waterlevel_1, name, waterLevel);
+ log.ErrorFormat(CultureInfo.CurrentCulture,
+ Resources.WaveConditionsCalculationService_VerifyWaveConditionsCalculationOutput_Error_in_wave_conditions_calculation_0_for_waterlevel_1,
+ name,
+ waterLevel);
throw;
}
return null;
}
}
- private static WaveConditionsCosineCalculationInput CreateInput(double waterLevel,
- double a,
- double b,
- double c,
+ private static WaveConditionsCosineCalculationInput CreateInput(RoundedDouble waterLevel,
+ RoundedDouble a,
+ RoundedDouble b,
+ RoundedDouble c,
double norm,
WaveConditionsInput input)
{