Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/HeightStructuresCalculationConfigurationImporter.cs =================================================================== diff -u -r512bebcd5570951b18657513c56843d9e2f8e969 -r82af27f82c4dc2248e03c0e22bbe46b5e01e88bb --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/HeightStructuresCalculationConfigurationImporter.cs (.../HeightStructuresCalculationConfigurationImporter.cs) (revision 512bebcd5570951b18657513c56843d9e2f8e969) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/HeightStructuresCalculationConfigurationImporter.cs (.../HeightStructuresCalculationConfigurationImporter.cs) (revision 82af27f82c4dc2248e03c0e22bbe46b5e01e88bb) @@ -33,7 +33,6 @@ using Ringtoets.Common.IO.FileImporters; using Ringtoets.Common.IO.Schema; using Ringtoets.HeightStructures.Data; -using Ringtoets.HeightStructures.IO.Properties; using RingtoetsCommonIOResources = Ringtoets.Common.IO.Properties.Resources; namespace Ringtoets.HeightStructures.IO @@ -58,8 +57,8 @@ /// used to check if the imported objects contain the right location. /// The foreshore profiles used to check if /// the imported objects contain the right foreshore profile. - /// The dike profiles used to check if - /// the imported objects contain the right profile. + /// The structures used to check if + /// the imported objects contain the right structure. /// Thrown when any parameter is null. public HeightStructuresCalculationConfigurationImporter( string xmlFilePath, @@ -93,18 +92,18 @@ protected override ICalculation ParseReadCalculation(HeightStructuresCalculationConfiguration readCalculation) { - var calculation = new StructuresCalculation() + var calculation = new StructuresCalculation { Name = readCalculation.Name }; - if (TryReadStructure(readCalculation, calculation) + if (TryReadStructure(readCalculation.StructureName, calculation) + && TryReadHydraulicBoundaryLocation(readCalculation.HydraulicBoundaryLocationName, calculation) + && TryReadForeshoreProfile(readCalculation.ForeshoreProfileName, calculation) && TryReadStochasts(readCalculation, calculation) - && TryReadHydraulicBoundaryLocation(readCalculation, calculation) - && TryReadDikeProfile(readCalculation, calculation) && TryReadOrientation(readCalculation, calculation) && TryReadFailureProbabilityStructureWithErosion(readCalculation, calculation) - && TryReadWaveReduction(readCalculation, calculation)) + && TryReadWaveReduction(readCalculation.WaveReduction, calculation)) { return calculation; } @@ -338,175 +337,81 @@ return true; } - /// - /// Reads the hydraulic boundary location. - /// - /// The calculation read from the imported file. - /// The calculation to configure. - /// false when the has a - /// set which is not available in , true otherwise. - private bool TryReadHydraulicBoundaryLocation(StructuresCalculationConfiguration readCalculation, StructuresCalculation calculation) + private bool TryReadHydraulicBoundaryLocation(string locationName, StructuresCalculation calculation) { - if (readCalculation.HydraulicBoundaryLocationName != null) - { - HydraulicBoundaryLocation location = availableHydraulicBoundaryLocations - .FirstOrDefault(l => l.Name == readCalculation.HydraulicBoundaryLocationName); + HydraulicBoundaryLocation location; - if (location == null) - { - LogReadCalculationConversionError( - string.Format( - RingtoetsCommonIOResources.CalculationConfigurationImporter_ReadHydraulicBoundaryLocation_HydraulicBoundaryLocation_0_does_not_exist, - readCalculation.HydraulicBoundaryLocationName), - calculation.Name); - - return false; - } - + if (TryReadHydraulicBoundaryLocation(locationName, calculation.Name, availableHydraulicBoundaryLocations, out location)) + { calculation.InputParameters.HydraulicBoundaryLocation = location; + return true; } - return true; + return false; } - /// - /// Reads the hydraulic boundary location. - /// - /// The calculation read from the imported file. - /// The calculation to configure. - /// false when the has a - /// set which is not available in , true otherwise. - private bool TryReadStructure(StructuresCalculationConfiguration readCalculation, StructuresCalculation calculation) + private bool TryReadStructure(string structureName, StructuresCalculation calculation) { - if (readCalculation.StructureName != null) - { - HeightStructure structure = availableStructures - .FirstOrDefault(l => l.Name == readCalculation.StructureName); + HeightStructure structure; - if (structure == null) - { - LogReadCalculationConversionError( - string.Format( - RingtoetsCommonIOResources.CalculationConfigurationImporter_ReadStructure_Structure_0_does_not_exist, - readCalculation.StructureName), - calculation.Name); - - return false; - } - + if (TryReadStructure(structureName, calculation.Name, availableStructures, out structure)) + { calculation.InputParameters.Structure = structure; + return true; } - return true; + return false; } - /// - /// Reads the dike profile. - /// - /// The calculation read from the imported file. - /// The calculation to configure. - /// false when the has a - /// set which is not available in , true otherwise. - private bool TryReadDikeProfile(StructuresCalculationConfiguration readCalculation, StructuresCalculation calculation) + private bool TryReadForeshoreProfile(string foreshoreProfileName, StructuresCalculation calculation) { - if (readCalculation.ForeshoreProfileName != null) - { - ForeshoreProfile foreshoreProfile = availableForeshoreProfiles.FirstOrDefault(fp => fp.Name == readCalculation.ForeshoreProfileName); + ForeshoreProfile foreshoreProfile; - if (foreshoreProfile == null) - { - LogReadCalculationConversionError( - string.Format( - RingtoetsCommonIOResources.CalculationConfigurationImporter_ReadForeshoreProfile_ForeshoreProfile_0_does_not_exist, - readCalculation.ForeshoreProfileName), - calculation.Name); - - return false; - } - + if (TryReadForeshoreProfile(foreshoreProfileName, calculation.Name, availableForeshoreProfiles, out foreshoreProfile)) + { calculation.InputParameters.ForeshoreProfile = foreshoreProfile; + return true; } - return true; + return false; } /// /// Reads the wave reduction parameters. /// - /// The calculation read from the imported file. + /// /// The calculation to configure. /// false when there is an invalid wave reduction parameter defined, true otherwise. - private bool TryReadWaveReduction(StructuresCalculationConfiguration readCalculation, StructuresCalculation calculation) + private bool TryReadWaveReduction(WaveReductionConfiguration waveReduction, StructuresCalculation calculation) { - if (!ValidateWaveReduction(readCalculation, calculation)) + if (!ValidateWaveReduction(waveReduction, calculation.InputParameters.ForeshoreProfile, calculation.Name)) { return false; } - WaveReductionConfiguration waveReduction = readCalculation.WaveReduction; - if (waveReduction == null) + if (waveReduction != null) { - return true; - } + if (waveReduction.UseForeshoreProfile.HasValue) + { + calculation.InputParameters.UseForeshore = waveReduction.UseForeshoreProfile.Value; + } - if (waveReduction.UseForeshoreProfile.HasValue) - { - calculation.InputParameters.UseForeshore = waveReduction.UseForeshoreProfile.Value; - } - - if (waveReduction.UseBreakWater.HasValue) - { - calculation.InputParameters.UseBreakWater = waveReduction.UseBreakWater.Value; - } - - if (waveReduction.BreakWaterType.HasValue) - { - calculation.InputParameters.BreakWater.Type = (BreakWaterType) new ConfigurationBreakWaterTypeConverter().ConvertTo(waveReduction.BreakWaterType.Value, typeof(BreakWaterType)); - } - - if (waveReduction.BreakWaterHeight.HasValue) - { - calculation.InputParameters.BreakWater.Height = (RoundedDouble) waveReduction.BreakWaterHeight.Value; - } - - return true; - } - - /// - /// Validation to check if the defined wave reduction parameters are valid. - /// - /// The calculation read from the imported file. - /// The calculation to configure. - /// false when there is an invalid wave reduction parameter defined, true otherwise. - private bool ValidateWaveReduction(StructuresCalculationConfiguration readCalculation, StructuresCalculation calculation) - { - if (calculation.InputParameters.ForeshoreProfile == null) - { - if (readCalculation.WaveReduction != null - && (readCalculation.WaveReduction.UseBreakWater.HasValue - || readCalculation.WaveReduction.UseForeshoreProfile.HasValue - || readCalculation.WaveReduction.BreakWaterHeight.HasValue - || readCalculation.WaveReduction.BreakWaterType.HasValue)) + if (waveReduction.UseBreakWater.HasValue) { - LogReadCalculationConversionError( - RingtoetsCommonIOResources.CalculationConfigurationImporter_ValidateWaveReduction_No_foreshore_profile_provided, - calculation.Name); + calculation.InputParameters.UseBreakWater = waveReduction.UseBreakWater.Value; + } - return false; + if (waveReduction.BreakWaterType.HasValue) + { + calculation.InputParameters.BreakWater.Type = (BreakWaterType) new ConfigurationBreakWaterTypeConverter().ConvertTo(waveReduction.BreakWaterType.Value, typeof(BreakWaterType)); } - } - else if (!calculation.InputParameters.ForeshoreGeometry.Any()) - { - if (readCalculation.WaveReduction.UseForeshoreProfile.HasValue && readCalculation.WaveReduction.UseForeshoreProfile.Value) + + if (waveReduction.BreakWaterHeight.HasValue) { - LogReadCalculationConversionError( - string.Format( - RingtoetsCommonIOResources.ReadForeshoreProfile_ForeshoreProfile_0_has_no_geometry_and_cannot_be_used, - readCalculation.ForeshoreProfileName), - calculation.Name); - return false; + calculation.InputParameters.BreakWater.Height = (RoundedDouble) waveReduction.BreakWaterHeight.Value; } } + return true; } }