Index: Ringtoets/Common/src/Ringtoets.Common.Data/UpdateDataStrategies/UpdateDataStrategyBase.cs =================================================================== diff -u -rfe48b787571cbc5b0fa82df6c9bb718fbd869f04 -rc0af7b97084a578a78834cbccb43bf53ca39b8e6 --- Ringtoets/Common/src/Ringtoets.Common.Data/UpdateDataStrategies/UpdateDataStrategyBase.cs (.../UpdateDataStrategyBase.cs) (revision fe48b787571cbc5b0fa82df6c9bb718fbd869f04) +++ Ringtoets/Common/src/Ringtoets.Common.Data/UpdateDataStrategies/UpdateDataStrategyBase.cs (.../UpdateDataStrategyBase.cs) (revision c0af7b97084a578a78834cbccb43bf53ca39b8e6) @@ -46,19 +46,14 @@ { protected readonly TFailureMechanism FailureMechanism; private readonly IEqualityComparer equalityComparer; - private ObservableUniqueItemCollectionWithSourcePath targetCollection; /// /// Creates a new instance of object. /// /// The failure mechanism which needs to be updated. - /// The collection to add the updated objects to. /// The comparer which should be used to determine when two objects are equal. /// Thrown when any input parameter is null. - protected UpdateDataStrategyBase( - TFailureMechanism failureMechanism, - ObservableUniqueItemCollectionWithSourcePath targetCollection, - IEqualityComparer equalityComparer) + protected UpdateDataStrategyBase(TFailureMechanism failureMechanism, IEqualityComparer equalityComparer) { if (failureMechanism == null) { @@ -68,13 +63,8 @@ { throw new ArgumentNullException(nameof(equalityComparer)); } - if (targetCollection == null) - { - throw new ArgumentNullException(nameof(targetCollection)); - } this.equalityComparer = equalityComparer; - this.targetCollection = targetCollection; FailureMechanism = failureMechanism; } @@ -99,16 +89,22 @@ /// Updates the items and their associated data within the target collection with the data contained /// in the imported data collection. /// + /// The target collection that needs to be updated. /// The imported data collection that is used to update - /// the . + /// the . /// The source file path. /// A of affected objects. /// Thrown when an error occurred while updating the data. /// Thrown when contains /// null elements. - protected IEnumerable UpdateTargetCollectionData(IEnumerable importedDataCollection, + protected IEnumerable UpdateTargetCollectionData(ObservableUniqueItemCollectionWithSourcePath targetDataCollection, + IEnumerable importedDataCollection, string sourceFilePath) { + if (targetDataCollection == null) + { + throw new ArgumentNullException(nameof(targetDataCollection)); + } if (importedDataCollection == null) { throw new ArgumentNullException(nameof(importedDataCollection)); @@ -117,44 +113,47 @@ { throw new ArgumentNullException(nameof(sourceFilePath)); } - return ModifyDataCollection(importedDataCollection, sourceFilePath); + + return ModifyDataCollection(targetDataCollection, importedDataCollection, sourceFilePath); } /// /// Identifies which items were changed, removed and added to the target collection /// when compared with the imported data and performs the necessary operations for /// the dependent data of the affected elements. /// + /// The target data collection which needs to be updated. /// The imported data collection which is used to update - /// the . + /// the . /// The source file path. /// A with affected objects. /// Thrown when: /// - /// duplicate items are being added to the . + /// duplicate items are being added to the . /// duplicate items are found in the . /// /// - /// Thrown when - /// is null. + /// Thrown when either + /// or is null. /// Thrown when contains /// null elements. - private IEnumerable ModifyDataCollection(IEnumerable importedDataCollection, + private IEnumerable ModifyDataCollection(ObservableUniqueItemCollectionWithSourcePath targetDataCollection, + IEnumerable importedDataCollection, string sourceFilePath) { TTargetData[] importedObjects = importedDataCollection.ToArray(); - var modification = new CollectionModification(targetCollection, importedObjects, equalityComparer); + var modification = new CollectionModification(targetDataCollection, importedObjects, equalityComparer); var affectedObjects = new List(); if (modification.HasUpdates()) { - affectedObjects.Add(targetCollection); + affectedObjects.Add(targetDataCollection); } affectedObjects.AddRange(UpdateData(modification.ObjectsToBeUpdated.Values, importedObjects)); affectedObjects.AddRange(RemoveData(modification.ObjectsToBeRemoved)); - targetCollection.Clear(); - targetCollection.AddRange(modification.GetModifiedCollection(), sourceFilePath); + targetDataCollection.Clear(); + targetDataCollection.AddRange(modification.GetModifiedCollection(), sourceFilePath); return affectedObjects.Distinct(new ReferenceEqualityComparer()); }