Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Service/HeightStructuresDataSynchronizationService.cs
===================================================================
diff -u -r6d6256a21a3a1bc8e4811db1eb638df3cfb4c37b -rd54c98575da700b413bac3ba0acddc7c71794510
--- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Service/HeightStructuresDataSynchronizationService.cs (.../HeightStructuresDataSynchronizationService.cs) (revision 6d6256a21a3a1bc8e4811db1eb638df3cfb4c37b)
+++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Service/HeightStructuresDataSynchronizationService.cs (.../HeightStructuresDataSynchronizationService.cs) (revision d54c98575da700b413bac3ba0acddc7c71794510)
@@ -23,11 +23,13 @@
using System.Collections.Generic;
using System.Linq;
using Core.Common.Base;
+using Ringtoets.Common.Data;
using Ringtoets.Common.Data.Calculation;
using Ringtoets.Common.Data.Hydraulics;
using Ringtoets.Common.Data.Structures;
using Ringtoets.Common.Service;
using Ringtoets.HeightStructures.Data;
+using Ringtoets.HeightStructures.Util;
namespace Ringtoets.HeightStructures.Service
{
@@ -37,6 +39,76 @@
public static class HeightStructuresDataSynchronizationService
{
///
+ /// Removes the , unassigns it from the calculations in
+ /// and clears all dependent data, either directly or indirectly.
+ ///
+ /// The structure to be removed.
+ /// The
+ /// to clear the data from.
+ /// All objects affected by the removal.
+ /// Thrown when any parameter is null.
+ public static IEnumerable RemoveStructure(HeightStructure structure,
+ HeightStructuresFailureMechanism failureMechanism)
+ {
+ if (structure == null)
+ {
+ throw new ArgumentNullException(nameof(structure));
+ }
+
+ if (failureMechanism == null)
+ {
+ throw new ArgumentNullException(nameof(failureMechanism));
+ }
+
+ IEnumerable> calculations =
+ failureMechanism.Calculations.Cast>();
+
+ StructuresCalculation[] calculationWithRemovedStructure = calculations
+ .Where(c => ReferenceEquals(c.InputParameters.Structure, structure))
+ .ToArray();
+
+ List changedObservables = ClearStructureDependentData(failureMechanism,
+ calculationWithRemovedStructure);
+
+ StructureCollection structures = failureMechanism.HeightStructures;
+ structures.Remove(structure);
+ changedObservables.Add(structures);
+
+ return changedObservables;
+ }
+
+ ///
+ /// Clears all structures, unassigns them from the calculations in the
+ /// and clears all data that depends on it, either directly or indirectly.
+ ///
+ /// The to
+ /// clear the structures from.
+ /// All objects that are affected by this operation.
+ /// Thrown when any parameter is null.
+ public static IEnumerable RemoveAllStructures(HeightStructuresFailureMechanism failureMechanism)
+ {
+ if (failureMechanism == null)
+ {
+ throw new ArgumentNullException(nameof(failureMechanism));
+ }
+
+ IEnumerable> calculations =
+ failureMechanism.Calculations.Cast>();
+ StructuresCalculation[] calculationWithRemovedStructure = calculations
+ .Where(c => c.InputParameters.Structure != null)
+ .ToArray();
+
+ List changedObservables = ClearStructureDependentData(failureMechanism,
+ calculationWithRemovedStructure);
+
+ StructureCollection structures = failureMechanism.HeightStructures;
+ structures.Clear();
+ changedObservables.Add(structures);
+
+ return changedObservables;
+ }
+
+ ///
/// Clears the output for all calculations in the .
///
/// The
@@ -135,5 +207,24 @@
return Enumerable.Empty();
}
+
+ private static List ClearStructureDependentData(HeightStructuresFailureMechanism failureMechanism,
+ IEnumerable> calculationWithRemovedStructure)
+ {
+ var changedObservables = new List();
+ foreach (StructuresCalculation calculation in calculationWithRemovedStructure)
+ {
+ changedObservables.AddRange(RingtoetsCommonDataSynchronizationService.ClearCalculationOutput(calculation));
+
+ calculation.InputParameters.ClearStructure();
+ changedObservables.Add(calculation.InputParameters);
+ }
+
+ IEnumerable affectedSectionResults =
+ HeightStructuresHelper.UpdateCalculationToSectionResultAssignments(failureMechanism);
+
+ changedObservables.AddRange(affectedSectionResults);
+ return changedObservables;
+ }
}
}
\ No newline at end of file