Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.IO/Configurations/ClosingStructuresCalculationConfigurationExporter.cs =================================================================== diff -u -r16c94d05c67237dec9fcab0f3f03c6b48d3c335b -r0404544d0354a059a0b7a02e5f1bca72d6e81d75 --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.IO/Configurations/ClosingStructuresCalculationConfigurationExporter.cs (.../ClosingStructuresCalculationConfigurationExporter.cs) (revision 16c94d05c67237dec9fcab0f3f03c6b48d3c335b) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.IO/Configurations/ClosingStructuresCalculationConfigurationExporter.cs (.../ClosingStructuresCalculationConfigurationExporter.cs) (revision 0404544d0354a059a0b7a02e5f1bca72d6e81d75) @@ -25,7 +25,6 @@ using Ringtoets.ClosingStructures.IO.Configurations.Helpers; using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.Structures; -using Ringtoets.Common.IO.Configurations; using Ringtoets.Common.IO.Configurations.Helpers; using Ringtoets.Common.IO.Exporters; @@ -46,7 +45,7 @@ /// The path of the XML file to export to. /// Thrown when is null. /// Thrown when is invalid. - public ClosingStructuresCalculationConfigurationExporter(IEnumerable calculations, string filePath) : base(calculations, filePath) {} + public ClosingStructuresCalculationConfigurationExporter(IEnumerable calculations, string filePath) : base(calculations, filePath) { } protected override ClosingStructuresCalculationConfiguration ToConfiguration(StructuresCalculation calculation) { @@ -56,7 +55,6 @@ HydraulicBoundaryLocationName = input.HydraulicBoundaryLocation?.Name }; - if (input.Structure != null) { calculationConfiguration.StructureName = input.Structure.Name; @@ -80,17 +78,7 @@ calculationConfiguration.ThresholdHeightOpenWeir = input.ThresholdHeightOpenWeir.ToStochastConfiguration(); } - if (input.ForeshoreProfile != null) - { - calculationConfiguration.ForeshoreProfileName = input.ForeshoreProfile?.Name; - calculationConfiguration.WaveReduction = new WaveReductionConfiguration - { - UseForeshoreProfile = input.UseForeshore, - UseBreakWater = input.UseBreakWater, - BreakWaterType = (ConfigurationBreakWaterType?) new ConfigurationBreakWaterTypeConverter().ConvertFrom(input.BreakWater.Type), - BreakWaterHeight = input.BreakWater.Height - }; - } + calculationConfiguration.SetConfigurationForeshoreProfileDependendProperties(input); calculationConfiguration.FailureProbabilityStructureWithErosion = input.FailureProbabilityStructureWithErosion; calculationConfiguration.FactorStormDurationOpenStructure = input.FactorStormDurationOpenStructure; Index: Ringtoets/Common/src/Ringtoets.Common.IO/Configurations/Helpers/WaveReductionConversionExtensions.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.IO/Configurations/Helpers/WaveReductionConversionExtensions.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Configurations/Helpers/WaveReductionConversionExtensions.cs (revision 0404544d0354a059a0b7a02e5f1bca72d6e81d75) @@ -0,0 +1,74 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using Ringtoets.Common.Data; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.Structures; + +namespace Ringtoets.Common.IO.Configurations.Helpers +{ + /// + /// Helper methods for setting wave reduction properties of configuration elements. + /// + public static class WaveReductionConversionExtensions + { + /// + /// Sets the using properties from , + /// when is set. + /// + /// The type of structure for . + /// The configuration to update. + /// The structure input to update from. + /// Thrown when any of the input parameters is null. + public static void SetConfigurationForeshoreProfileDependendProperties(this StructuresCalculationConfiguration configuration, + StructuresInputBase input) where T : StructureBase + { + if (configuration == null) + { + throw new ArgumentNullException(nameof(configuration)); + } + if (input == null) + { + throw new ArgumentNullException(nameof(input)); + } + + if (input.ForeshoreProfile == null) + { + return; + } + + configuration.ForeshoreProfileName = input.ForeshoreProfile?.Name; + configuration.WaveReduction = new WaveReductionConfiguration + { + UseForeshoreProfile = input.UseForeshore, + UseBreakWater = input.UseBreakWater, + BreakWaterHeight = input.BreakWater.Height + }; + + if (Enum.IsDefined(typeof(BreakWaterType), input.BreakWater.Type)) + { + configuration.WaveReduction.BreakWaterType = (ConfigurationBreakWaterType?) + new ConfigurationBreakWaterTypeConverter().ConvertFrom(input.BreakWater.Type); + } + } + } +} \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj =================================================================== diff -u -reeac9fe0e250075e6e95683e4781b7b96ddc178c -r0404544d0354a059a0b7a02e5f1bca72d6e81d75 --- Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj (.../Ringtoets.Common.IO.csproj) (revision eeac9fe0e250075e6e95683e4781b7b96ddc178c) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj (.../Ringtoets.Common.IO.csproj) (revision 0404544d0354a059a0b7a02e5f1bca72d6e81d75) @@ -57,6 +57,7 @@ + Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/Configurations/Helpers/WaveReductionConversionExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/Configurations/Helpers/WaveReductionConversionExtensionsTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/Configurations/Helpers/WaveReductionConversionExtensionsTest.cs (revision 0404544d0354a059a0b7a02e5f1bca72d6e81d75) @@ -0,0 +1,155 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Linq; +using Core.Common.Base.Geometry; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.Structures; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.IO.Configurations; +using Ringtoets.Common.IO.Configurations.Helpers; + +namespace Ringtoets.Common.IO.Test.Configurations.Helpers +{ + [TestFixture] + public class WaveReductionConversionExtensionsTest + { + [Test] + public void SetConfigurationForeshoreProfileDependendProperties_ConfigurationNull_ThrowsArgumentNullException() + { + // Setup + SimpleStructuresCalculationConfiguration configuration = null; + var structureInput = new SimpleStructuresInput(); + + // Call + TestDelegate call = () => configuration.SetConfigurationForeshoreProfileDependendProperties(structureInput); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("configuration", paramName); + } + + [Test] + public void SetConfigurationForeshoreProfileDependendProperties_InputNull_ThrowsArgumentNullException() + { + // Setup + var configuration = new SimpleStructuresCalculationConfiguration(); + + // Call + TestDelegate call = () => configuration.SetConfigurationForeshoreProfileDependendProperties(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("input", paramName); + } + + [Test] + public void SetConfigurationForeshoreProfileDependendProperties_WithoutForeshoreProfile_DoesNotUpdate() + { + // Setup + var configuration = new SimpleStructuresCalculationConfiguration(); + var structureInput = new SimpleStructuresInput(); + + // Call + configuration.SetConfigurationForeshoreProfileDependendProperties(structureInput); + + // Assert + Assert.IsNull(configuration.ForeshoreProfileName); + Assert.IsNull(configuration.WaveReduction); + } + + [Test] + public void SetConfigurationForeshoreProfileDependendProperties_WithForeshoreProfile_UpdatesConfiguration() + { + // Setup + var random = new Random(6543); + var configuration = new SimpleStructuresCalculationConfiguration(); + var structureInput = new SimpleStructuresInput + { + ForeshoreProfile = new ForeshoreProfile(new Point2D(0, 0), + Enumerable.Empty(), + new BreakWater( + BreakWaterType.Dam, + random.NextDouble()), + new ForeshoreProfile.ConstructionProperties + { + Id = "id", + Name = "profile" + }), + UseBreakWater = random.NextBoolean(), + UseForeshore = random.NextBoolean() + }; + + // Call + configuration.SetConfigurationForeshoreProfileDependendProperties(structureInput); + + // Assert + Assert.AreEqual("profile", configuration.ForeshoreProfileName); + WaveReductionConfiguration waveReduction = configuration.WaveReduction; + Assert.AreEqual(structureInput.UseBreakWater, waveReduction.UseBreakWater); + Assert.AreEqual(structureInput.UseForeshore, waveReduction.UseForeshoreProfile); + Assert.AreEqual(ConfigurationBreakWaterType.Dam, waveReduction.BreakWaterType); + Assert.AreEqual(structureInput.BreakWater.Height, waveReduction.BreakWaterHeight); + } + + [Test] + public void SetConfigurationForeshoreProfileDependendProperties_WithForeshoreProfileInvalidBreakwaterType_UpdatesConfiguration() + { + // Setup + var random = new Random(6543); + var configuration = new SimpleStructuresCalculationConfiguration(); + var structureInput = new SimpleStructuresInput + { + ForeshoreProfile = new TestForeshoreProfile(new BreakWater( + (BreakWaterType) 999, + random.NextDouble())), + + UseBreakWater = random.NextBoolean(), + UseForeshore = random.NextBoolean() + }; + + // Call + configuration.SetConfigurationForeshoreProfileDependendProperties(structureInput); + + // Assert + Assert.AreEqual(structureInput.ForeshoreProfile.Name, configuration.ForeshoreProfileName); + WaveReductionConfiguration waveReduction = configuration.WaveReduction; + Assert.AreEqual(structureInput.UseBreakWater, waveReduction.UseBreakWater); + Assert.AreEqual(structureInput.UseForeshore, waveReduction.UseForeshoreProfile); + Assert.IsNull(waveReduction.BreakWaterType); + Assert.AreEqual(structureInput.BreakWater.Height, waveReduction.BreakWaterHeight); + } + + private class SimpleStructuresInput : StructuresInputBase + { + protected override void UpdateStructureParameters() { } + } + + private class SimpleStructuresCalculationConfiguration : StructuresCalculationConfiguration + { + public SimpleStructuresCalculationConfiguration() : base(string.Empty) { } + } + } +} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/Ringtoets.Common.IO.Test.csproj =================================================================== diff -u -rb574376e8d2b485ff320504841723923c1e41331 -r0404544d0354a059a0b7a02e5f1bca72d6e81d75 --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/Ringtoets.Common.IO.Test.csproj (.../Ringtoets.Common.IO.Test.csproj) (revision b574376e8d2b485ff320504841723923c1e41331) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/Ringtoets.Common.IO.Test.csproj (.../Ringtoets.Common.IO.Test.csproj) (revision 0404544d0354a059a0b7a02e5f1bca72d6e81d75) @@ -63,6 +63,7 @@ + Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/Configurations/HeightStructuresCalculationConfigurationExporter.cs =================================================================== diff -u -r9a0e768e9ddbc5e4917201fdb864bb2247e5cd90 -r0404544d0354a059a0b7a02e5f1bca72d6e81d75 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/Configurations/HeightStructuresCalculationConfigurationExporter.cs (.../HeightStructuresCalculationConfigurationExporter.cs) (revision 9a0e768e9ddbc5e4917201fdb864bb2247e5cd90) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/Configurations/HeightStructuresCalculationConfigurationExporter.cs (.../HeightStructuresCalculationConfigurationExporter.cs) (revision 0404544d0354a059a0b7a02e5f1bca72d6e81d75) @@ -23,7 +23,6 @@ using System.Collections.Generic; using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.Structures; -using Ringtoets.Common.IO.Configurations; using Ringtoets.Common.IO.Configurations.Helpers; using Ringtoets.Common.IO.Exporters; using Ringtoets.HeightStructures.Data; @@ -45,7 +44,7 @@ /// The path of the XML file to export to. /// Thrown when is null. /// Thrown when is invalid. - public HeightStructuresCalculationConfigurationExporter(IEnumerable calculations, string filePath) : base(calculations, filePath) {} + public HeightStructuresCalculationConfigurationExporter(IEnumerable calculations, string filePath) : base(calculations, filePath) { } protected override HeightStructuresCalculationConfiguration ToConfiguration(StructuresCalculation calculation) { @@ -68,17 +67,7 @@ calculationConfiguration.CriticalOvertoppingDischarge = input.CriticalOvertoppingDischarge.ToStochastConfiguration(); } - if (input.ForeshoreProfile != null) - { - calculationConfiguration.ForeshoreProfileName = input.ForeshoreProfile?.Name; - calculationConfiguration.WaveReduction = new WaveReductionConfiguration - { - UseForeshoreProfile = input.UseForeshore, - UseBreakWater = input.UseBreakWater, - BreakWaterType = (ConfigurationBreakWaterType?) new ConfigurationBreakWaterTypeConverter().ConvertFrom(input.BreakWater.Type), - BreakWaterHeight = input.BreakWater.Height - }; - } + calculationConfiguration.SetConfigurationForeshoreProfileDependendProperties(input); calculationConfiguration.StormDuration = input.StormDuration.ToStochastConfigurationWithMean(); calculationConfiguration.ModelFactorSuperCriticalFlow = input.ModelFactorSuperCriticalFlow.ToStochastConfigurationWithMean(); Index: Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.IO/Configurations/StabilityPointStructuresCalculationConfigurationExporter.cs =================================================================== diff -u -r8df33e6574921c3f844c49268cfb649b2dc78368 -r0404544d0354a059a0b7a02e5f1bca72d6e81d75 --- Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.IO/Configurations/StabilityPointStructuresCalculationConfigurationExporter.cs (.../StabilityPointStructuresCalculationConfigurationExporter.cs) (revision 8df33e6574921c3f844c49268cfb649b2dc78368) +++ Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.IO/Configurations/StabilityPointStructuresCalculationConfigurationExporter.cs (.../StabilityPointStructuresCalculationConfigurationExporter.cs) (revision 0404544d0354a059a0b7a02e5f1bca72d6e81d75) @@ -21,11 +21,8 @@ using System; using System.Collections.Generic; -using Ringtoets.Common.Data; using Ringtoets.Common.Data.Calculation; -using Ringtoets.Common.Data.DikeProfiles; using Ringtoets.Common.Data.Structures; -using Ringtoets.Common.IO.Configurations; using Ringtoets.Common.IO.Configurations.Helpers; using Ringtoets.Common.IO.Exporters; using Ringtoets.StabilityPointStructures.Data; @@ -58,21 +55,22 @@ protected override StabilityPointStructuresCalculationConfiguration ToConfiguration(StructuresCalculation calculation) { - var calculationConfiguration = new StabilityPointStructuresCalculationConfiguration(calculation.Name); StabilityPointStructuresInput input = calculation.InputParameters; - calculationConfiguration.DrainCoefficient = input.DrainCoefficient.ToStochastConfigurationWithMean(); - calculationConfiguration.FactorStormDurationOpenStructure = input.FactorStormDurationOpenStructure; - calculationConfiguration.FailureProbabilityStructureWithErosion = input.FailureProbabilityStructureWithErosion; - calculationConfiguration.HydraulicBoundaryLocationName = input.HydraulicBoundaryLocation?.Name; + var calculationConfiguration = new StabilityPointStructuresCalculationConfiguration(calculation.Name) + { + DrainCoefficient = input.DrainCoefficient.ToStochastConfigurationWithMean(), + FactorStormDurationOpenStructure = input.FactorStormDurationOpenStructure, + FailureProbabilityStructureWithErosion = input.FailureProbabilityStructureWithErosion, + HydraulicBoundaryLocationName = input.HydraulicBoundaryLocation?.Name, + ModelFactorSuperCriticalFlow = input.ModelFactorSuperCriticalFlow.ToStochastConfigurationWithMean(), + VolumicWeightWater = input.VolumicWeightWater, + StormDuration = input.StormDuration.ToStochastConfigurationWithMean() + }; - calculationConfiguration.ModelFactorSuperCriticalFlow = input.ModelFactorSuperCriticalFlow.ToStochastConfigurationWithMean(); - calculationConfiguration.VolumicWeightWater = input.VolumicWeightWater; - calculationConfiguration.StormDuration = input.StormDuration.ToStochastConfigurationWithMean(); - SetConfigurationStructureDependendParameters(calculationConfiguration, input); - SetConfigurationForeshoreProfileDependendParameters(calculationConfiguration, input); + calculationConfiguration.SetConfigurationForeshoreProfileDependendProperties(input); return calculationConfiguration; } @@ -84,7 +82,6 @@ { return; } - var inflowModelTypeConverter = new ConfigurationStabilityPointStructuresInflowModelTypeConverter(); calculationConfiguration.AllowedLevelIncreaseStorage = input.AllowedLevelIncreaseStorage.ToStochastConfiguration(); calculationConfiguration.AreaFlowApertures = input.AreaFlowApertures.ToStochastConfiguration(); @@ -101,15 +98,21 @@ calculationConfiguration.FlowWidthAtBottomProtection = input.FlowWidthAtBottomProtection.ToStochastConfiguration(); if (Enum.IsDefined(typeof(StabilityPointStructureInflowModelType), input.InflowModelType)) { - calculationConfiguration.InflowModelType = (ConfigurationStabilityPointStructuresInflowModelType?) inflowModelTypeConverter.ConvertFrom(input.InflowModelType); + calculationConfiguration.InflowModelType = (ConfigurationStabilityPointStructuresInflowModelType?) + new ConfigurationStabilityPointStructuresInflowModelTypeConverter().ConvertFrom(input.InflowModelType); } calculationConfiguration.InsideWaterLevel = input.InsideWaterLevel.ToStochastConfiguration(); calculationConfiguration.InsideWaterLevelFailureConstruction = input.InsideWaterLevelFailureConstruction.ToStochastConfiguration(); calculationConfiguration.LevelCrestStructure = input.LevelCrestStructure.ToStochastConfiguration(); calculationConfiguration.LevellingCount = input.LevellingCount; - SetConfigurationLoadSchematizationType(calculationConfiguration, input); + if (Enum.IsDefined(typeof(LoadSchematizationType), input.LoadSchematizationType)) + { + calculationConfiguration.LoadSchematizationType = (ConfigurationStabilityPointStructuresLoadSchematizationType?) + new ConfigurationStabilityPointStructuresLoadSchematizationTypeConverter().ConvertFrom(input.LoadSchematizationType); + } + calculationConfiguration.ProbabilityCollisionSecondaryStructure = input.ProbabilityCollisionSecondaryStructure; calculationConfiguration.ShipMass = input.ShipMass.ToStochastConfiguration(); calculationConfiguration.ShipVelocity = input.ShipVelocity.ToStochastConfiguration(); @@ -124,38 +127,5 @@ calculationConfiguration.VerticalDistance = input.VerticalDistance; calculationConfiguration.WidthFlowApertures = input.WidthFlowApertures.ToStochastConfiguration(); } - - private static void SetConfigurationLoadSchematizationType(StabilityPointStructuresCalculationConfiguration calculationConfiguration, StabilityPointStructuresInput input) - { - if (!Enum.IsDefined(typeof(LoadSchematizationType), input.LoadSchematizationType)) - { - return; - } - var loadSchematizationTypeConverter = new ConfigurationStabilityPointStructuresLoadSchematizationTypeConverter(); - calculationConfiguration.LoadSchematizationType = (ConfigurationStabilityPointStructuresLoadSchematizationType?) loadSchematizationTypeConverter.ConvertFrom(input.LoadSchematizationType); - } - - private static void SetConfigurationForeshoreProfileDependendParameters(StructuresCalculationConfiguration calculationConfiguration, - StabilityPointStructuresInput input) - { - if (input.ForeshoreProfile == null) - { - return; - } - - var breakWaterTypeConverter = new ConfigurationBreakWaterTypeConverter(); - calculationConfiguration.ForeshoreProfileName = input.ForeshoreProfile?.Name; - calculationConfiguration.WaveReduction = new WaveReductionConfiguration - { - UseForeshoreProfile = input.UseForeshore, - UseBreakWater = input.UseBreakWater, - BreakWaterHeight = input.BreakWater.Height - }; - - if (Enum.IsDefined(typeof(BreakWaterType), input.BreakWater.Type)) - { - calculationConfiguration.WaveReduction.BreakWaterType = (ConfigurationBreakWaterType?) breakWaterTypeConverter.ConvertFrom(input.BreakWater.Type); - } - } } } \ No newline at end of file