// 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.Collections.Generic; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Calculation; using Ringtoets.GrassCoverErosionInwards.Data; using Ringtoets.GrassCoverErosionInwards.Service; using Ringtoets.HeightStructures.Data; using Ringtoets.HeightStructures.Service; using Ringtoets.HydraRing.Data; using Ringtoets.Piping.Data; using Ringtoets.Piping.Service; namespace Ringtoets.Integration.Service { /// /// Service for synchronizing ringtoets. /// public static class RingtoetsDataSynchronizationService { /// /// Clears all the output data within the . /// /// The to clear the data for. /// An of calculations which are affected by clearing the output. /// Thrown when is null. public static IEnumerable ClearAssessmentSectionData(IAssessmentSection assessmentSection) { if (assessmentSection == null) { throw new ArgumentNullException("assessmentSection"); } ClearHydraulicBoundaryLocationOutput(assessmentSection.HydraulicBoundaryDatabase); return ClearFailureMechanismCalculationOutputs(assessmentSection); } /// /// Clears all the output data and hydraulic boundary locations within the . /// /// The to clear the data for. /// An of calculations which are affected by /// removing data. /// /// Thrown when is null. public static IEnumerable ClearAllCalculationOutputAndHydraulicBoundaryLocations(IAssessmentSection assessmentSection) { if (assessmentSection == null) { throw new ArgumentNullException("assessmentSection"); } List affectedItems = new List(); foreach (var failureMechanism in assessmentSection.GetFailureMechanisms()) { var pipingFailureMechanism = failureMechanism as PipingFailureMechanism; var grassCoverErosionInwardsFailureMechanism = failureMechanism as GrassCoverErosionInwardsFailureMechanism; var heightStructuresFailureMechanism = failureMechanism as HeightStructuresFailureMechanism; if (pipingFailureMechanism != null) { affectedItems.AddRange(PipingDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(pipingFailureMechanism)); } if (grassCoverErosionInwardsFailureMechanism != null) { affectedItems.AddRange(GrassCoverErosionInwardsDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(grassCoverErosionInwardsFailureMechanism)); } if (heightStructuresFailureMechanism != null) { affectedItems.AddRange(HeightStructuresDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(heightStructuresFailureMechanism)); } } return affectedItems; } /// /// Clears the output of all calculations in the . /// /// The which contains the calculations. /// An of calculations which are affected by clearing the output. /// Thrown when is null. public static IEnumerable ClearFailureMechanismCalculationOutputs(IAssessmentSection assessmentSection) { if (assessmentSection == null) { throw new ArgumentNullException("assessmentSection"); } List affectedItems = new List(); foreach (var failureMechanism in assessmentSection.GetFailureMechanisms()) { var pipingFailureMechanism = failureMechanism as PipingFailureMechanism; var grassCoverErosionInwardsFailureMechanism = failureMechanism as GrassCoverErosionInwardsFailureMechanism; var heightStructuresFailureMechanism = failureMechanism as HeightStructuresFailureMechanism; if (pipingFailureMechanism != null) { affectedItems.AddRange(PipingDataSynchronizationService.ClearAllCalculationOutput(pipingFailureMechanism)); } if (grassCoverErosionInwardsFailureMechanism != null) { affectedItems.AddRange(GrassCoverErosionInwardsDataSynchronizationService.ClearAllCalculationOutput(grassCoverErosionInwardsFailureMechanism)); } if (heightStructuresFailureMechanism != null) { affectedItems.AddRange(HeightStructuresDataSynchronizationService.ClearAllCalculationOutput(heightStructuresFailureMechanism)); } } return affectedItems; } private static void ClearHydraulicBoundaryLocationOutput(HydraulicBoundaryDatabase hydraulicBoundaryDatabase) { if (hydraulicBoundaryDatabase == null) { return; } foreach (var hydraulicBoundaryLocation in hydraulicBoundaryDatabase.Locations) { hydraulicBoundaryLocation.DesignWaterLevel = double.NaN; hydraulicBoundaryLocation.WaveHeight = double.NaN; } } } }