Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Service/HeightStructuresDataSynchronizationService.cs =================================================================== diff -u -r20e9bfea15dfe132ee137283a9f24bc4c413ce4a -r8b389428ece343431969fce2e902a7b241f2b372 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Service/HeightStructuresDataSynchronizationService.cs (.../HeightStructuresDataSynchronizationService.cs) (revision 20e9bfea15dfe132ee137283a9f24bc4c413ce4a) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Service/HeightStructuresDataSynchronizationService.cs (.../HeightStructuresDataSynchronizationService.cs) (revision 8b389428ece343431969fce2e902a7b241f2b372) @@ -123,20 +123,67 @@ /// /// Removes the given height structure and all dependent data, either directly or indirectly, - /// from the failure mechanism. + /// from the . /// /// The failure mechanism containing . /// The structure to be removed. /// All objects affected by the removal. public static IEnumerable RemoveStructure(HeightStructuresFailureMechanism failureMechanism, HeightStructure structure) { - var changedObservables = new HashSet(); StructuresCalculation[] heightStructureCalculations = failureMechanism.Calculations .Cast>() .ToArray(); StructuresCalculation[] calculationWithRemovedHeightStructure = heightStructureCalculations .Where(c => ReferenceEquals(c.InputParameters.Structure, structure)) .ToArray(); + + HashSet changedObservables = RemoveStructureDependentData(failureMechanism, + calculationWithRemovedHeightStructure, + heightStructureCalculations); + + failureMechanism.HeightStructures.Remove(structure); + changedObservables.Add(failureMechanism.HeightStructures); + + return changedObservables; + } + + /// + /// Removes all height structures from the + /// and clears all data that depends on it, either directly or indirectly. + /// + /// The failure mechanism. + /// All objects that are affected by this operation. + /// Thrown when + /// is null. + public static IEnumerable RemoveAllStructures(HeightStructuresFailureMechanism failureMechanism) + { + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + + StructuresCalculation[] heightStructureCalculations = failureMechanism.Calculations + .Cast>() + .ToArray(); + StructuresCalculation[] calculationWithRemovedHeightStructure = heightStructureCalculations + .Where(c => c.InputParameters.Structure != null) + .ToArray(); + + HashSet changedObservables = RemoveStructureDependentData(failureMechanism, + calculationWithRemovedHeightStructure, + heightStructureCalculations); + + failureMechanism.HeightStructures.Clear(); + changedObservables.Add(failureMechanism.HeightStructures); + + return changedObservables; + } + + private static HashSet RemoveStructureDependentData(HeightStructuresFailureMechanism failureMechanism, + StructuresCalculation[] calculationWithRemovedHeightStructure, + StructuresCalculation[] heightStructureCalculations) + { + var changedObservables = new HashSet(); foreach (StructuresCalculation calculation in calculationWithRemovedHeightStructure) { foreach (IObservable calculationWithRemovedOutput in RingtoetsCommonDataSynchronizationService.ClearCalculationOutput(calculation)) @@ -154,10 +201,6 @@ { changedObservables.Add(result); } - - failureMechanism.HeightStructures.Remove(structure); - changedObservables.Add(failureMechanism.HeightStructures); - return changedObservables; }