Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/Configurations/HeightStructuresCalculationConfigurationImporter.cs =================================================================== diff -u -r9a0e768e9ddbc5e4917201fdb864bb2247e5cd90 -r335523a40d190e19b1061804de21c28f74140f52 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/Configurations/HeightStructuresCalculationConfigurationImporter.cs (.../HeightStructuresCalculationConfigurationImporter.cs) (revision 9a0e768e9ddbc5e4917201fdb864bb2247e5cd90) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/Configurations/HeightStructuresCalculationConfigurationImporter.cs (.../HeightStructuresCalculationConfigurationImporter.cs) (revision 335523a40d190e19b1061804de21c28f74140f52) @@ -22,6 +22,7 @@ using System; using System.Collections.Generic; using Core.Common.Base.Data; +using log4net; using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.DikeProfiles; using Ringtoets.Common.Data.Hydraulics; @@ -30,6 +31,7 @@ using Ringtoets.Common.IO.Configurations; using Ringtoets.Common.IO.Configurations.Helpers; using Ringtoets.Common.IO.FileImporters; +using Ringtoets.Common.IO.Properties; using Ringtoets.Common.IO.Schema; using Ringtoets.HeightStructures.Data; using RingtoetsCommonIOResources = Ringtoets.Common.IO.Properties.Resources; @@ -102,7 +104,7 @@ && TryReadStochasts(readCalculation, calculation) && TryReadOrientation(readCalculation, calculation) && TryReadFailureProbabilityStructureWithErosion(readCalculation, calculation) - && ValidateWaveReduction(readCalculation.WaveReduction, calculation.InputParameters.ForeshoreProfile, calculation.Name)) + && readCalculation.WaveReduction.ValidateWaveReduction(calculation.InputParameters.ForeshoreProfile, calculation.Name, Log)) { ReadWaveReductionParameters(readCalculation.WaveReduction, calculation.InputParameters); return calculation; @@ -112,145 +114,64 @@ private bool TryReadStochasts(HeightStructuresCalculationConfiguration readCalculation, StructuresCalculation calculation) { - if (!ValidateStochasts(readCalculation)) + if (!readCalculation.ValidateStochasts(Log)) { return false; } return TryReadStandardDeviationStochast( - calculation, + calculation.Name, HeightStructuresConfigurationSchemaIdentifiers.LevelCrestStructureStochastName, + calculation.InputParameters, readCalculation.LevelCrestStructure, i => i.LevelCrestStructure, (i, d) => i.LevelCrestStructure = d) && TryReadStandardDeviationStochast( - calculation, + calculation.Name, ConfigurationSchemaIdentifiers.AllowedLevelIncreaseStorageStochastName, - readCalculation.AllowedLevelIncreaseStorage, + calculation.InputParameters, readCalculation.AllowedLevelIncreaseStorage, i => i.AllowedLevelIncreaseStorage, (i, d) => i.AllowedLevelIncreaseStorage = d) && TryReadStandardDeviationStochast( - calculation, + calculation.Name, ConfigurationSchemaIdentifiers.FlowWidthAtBottomProtectionStochastName, - readCalculation.FlowWidthAtBottomProtection, + calculation.InputParameters, readCalculation.FlowWidthAtBottomProtection, i => i.FlowWidthAtBottomProtection, (i, d) => i.FlowWidthAtBottomProtection = d) && TryReadStandardDeviationStochast( - calculation, + calculation.Name, ConfigurationSchemaIdentifiers.ModelFactorSuperCriticalFlowStochastName, - readCalculation.ModelFactorSuperCriticalFlow, + calculation.InputParameters, readCalculation.ModelFactorSuperCriticalFlow, i => i.ModelFactorSuperCriticalFlow, (i, d) => i.ModelFactorSuperCriticalFlow = d) && TryReadStandardDeviationStochast( - calculation, + calculation.Name, ConfigurationSchemaIdentifiers.WidthFlowAperturesStochastName, - readCalculation.WidthFlowApertures, - i => i.WidthFlowApertures, - (i, d) => i.WidthFlowApertures = d) + calculation.InputParameters, readCalculation.WidthFlowApertures, + i => i.WidthFlowApertures, (i, d) => i.WidthFlowApertures = d) && TryReadVariationCoefficientStochast( - calculation, + calculation.Name, ConfigurationSchemaIdentifiers.CriticalOvertoppingDischargeStochastName, - readCalculation.CriticalOvertoppingDischarge, + calculation.InputParameters, readCalculation.CriticalOvertoppingDischarge, i => i.CriticalOvertoppingDischarge, (i, d) => i.CriticalOvertoppingDischarge = d) && TryReadVariationCoefficientStochast( - calculation, + calculation.Name, ConfigurationSchemaIdentifiers.StorageStructureAreaStochastName, + calculation.InputParameters, readCalculation.StorageStructureArea, i => i.StorageStructureArea, (i, d) => i.StorageStructureArea = d) && TryReadVariationCoefficientStochast( - calculation, + calculation.Name, ConfigurationSchemaIdentifiers.StormDurationStochastName, + calculation.InputParameters, readCalculation.StormDuration, i => i.StormDuration, (i, d) => i.StormDuration = d); } - private bool ValidateStochasts(HeightStructuresCalculationConfiguration readCalculation) - { - if (readCalculation.StormDuration?.VariationCoefficient != null) - { - LogReadCalculationConversionError("Er kan geen variatiecoƫfficiƫnt voor stochast 'stormduur' opgegeven worden.", readCalculation.Name); - return false; - } - if (readCalculation.ModelFactorSuperCriticalFlow?.StandardDeviation != null) - { - LogReadCalculationConversionError("Er kan geen standaardafwijking voor stochast 'modelfactoroverloopdebiet' opgegeven worden.", readCalculation.Name); - return false; - } - return true; - } - /// - /// Reads the stochast parameters. - /// - /// The calculation to configure. - /// The stochast's name. - /// The configuration of the stochast. - /// The function for obtaining the stochast to read. - /// The function to set the stochast with the read parameters. - /// true if reading all required stochast parameters was successful, - /// false otherwise. - private bool TryReadStandardDeviationStochast( - StructuresCalculation calculation, - string stochastName, - MeanStandardDeviationStochastConfiguration stochastConfiguration, - Func getStochast, - Action setStochast) - where T : IDistribution - { - if (stochastConfiguration == null) - { - return true; - } - var distribution = (T) getStochast(calculation.InputParameters).Clone(); - - if (!distribution.TrySetDistributionProperties(stochastConfiguration, - stochastName, - calculation.Name)) - { - return false; - } - setStochast(calculation.InputParameters, distribution); - return true; - } - - /// - /// Reads the stochast parameters. - /// - /// The calculation to configure. - /// The stochast's name. - /// The configuration of the stochast. - /// The function for obtaining the stochast to read. - /// The function to set the stochast with the read parameters. - /// true if reading all required stochast parameters was successful, - /// false otherwise. - private bool TryReadVariationCoefficientStochast( - StructuresCalculation calculation, - string stochastName, - MeanVariationCoefficientStochastConfiguration stochastConfiguration, - Func getStochast, - Action setStochast) - where T : IVariationCoefficientDistribution - { - if (stochastConfiguration == null) - { - return true; - } - var distribution = (T) getStochast(calculation.InputParameters).Clone(); - - if (!distribution.TrySetDistributionProperties(stochastConfiguration, - stochastName, - calculation.Name)) - { - return false; - } - setStochast(calculation.InputParameters, distribution); - return true; - } - - /// /// Reads the orientation. /// /// The calculation read from the imported file. @@ -263,10 +184,9 @@ { if (calculation.InputParameters.Structure == null) { - LogReadCalculationConversionError( - string.Format(RingtoetsCommonIOResources.CalculationConfigurationImporter_TryParameter_No_Structure_to_assign_Parameter_0_, - RingtoetsCommonIOResources.CalculationConfigurationImporter_Orientation_DisplayName), - calculation.Name); + Log.LogCalculationConversionError(string.Format(RingtoetsCommonIOResources.CalculationConfigurationImporter_TryParameter_No_Structure_to_assign_Parameter_0_, + RingtoetsCommonIOResources.CalculationConfigurationImporter_Orientation_DisplayName), + calculation.Name); return false; } @@ -279,12 +199,11 @@ } catch (ArgumentOutOfRangeException e) { - LogOutOfRangeException( - string.Format(RingtoetsCommonIOResources.TryReadParameter_Value_0_ParameterName_1_is_invalid, - orientation, - RingtoetsCommonIOResources.CalculationConfigurationImporter_Orientation_DisplayName), - calculation.Name, - e); + Log.LogOutOfRangeException(string.Format(RingtoetsCommonIOResources.TryReadParameter_Value_0_ParameterName_1_is_invalid, + orientation, + RingtoetsCommonIOResources.CalculationConfigurationImporter_Orientation_DisplayName), + calculation.Name, + e); return false; } @@ -306,10 +225,9 @@ { if (calculation.InputParameters.Structure == null) { - LogReadCalculationConversionError( - string.Format(RingtoetsCommonIOResources.CalculationConfigurationImporter_TryParameter_No_Structure_to_assign_Parameter_0_, - RingtoetsCommonIOResources.CalculationConfigurationImporter_FailureProbabilityStructureWithErosion_DisplayName), - calculation.Name); + Log.LogCalculationConversionError(string.Format(RingtoetsCommonIOResources.CalculationConfigurationImporter_TryParameter_No_Structure_to_assign_Parameter_0_, + RingtoetsCommonIOResources.CalculationConfigurationImporter_FailureProbabilityStructureWithErosion_DisplayName), + calculation.Name); return false; } @@ -322,13 +240,12 @@ } catch (ArgumentOutOfRangeException e) { - LogOutOfRangeException( - string.Format( - RingtoetsCommonIOResources.TryReadParameter_Value_0_ParameterName_1_is_invalid, - failureProbability, - RingtoetsCommonIOResources.CalculationConfigurationImporter_FailureProbabilityStructureWithErosion_DisplayName), - calculation.Name, - e); + Log.LogOutOfRangeException(string.Format( + RingtoetsCommonIOResources.TryReadParameter_Value_0_ParameterName_1_is_invalid, + failureProbability, + RingtoetsCommonIOResources.CalculationConfigurationImporter_FailureProbabilityStructureWithErosion_DisplayName), + calculation.Name, + e); return false; }