Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/StochasticSoilModelUpdateData.cs =================================================================== diff -u -rbbca25e660e1ebf3d4dce4e9ce6bbd07bf7a12e1 -r5e70f173b3839314912e086b6c1c784b975ee646 --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/StochasticSoilModelUpdateData.cs (.../StochasticSoilModelUpdateData.cs) (revision bbca25e660e1ebf3d4dce4e9ce6bbd07bf7a12e1) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/StochasticSoilModelUpdateData.cs (.../StochasticSoilModelUpdateData.cs) (revision 5e70f173b3839314912e086b6c1c784b975ee646) @@ -31,8 +31,10 @@ /// /// Strategy for updating the current stochastic soil models with the imported stochastic soil models. /// - public class StochasticSoilModelUpdateData : StochasticSoilModelUpdateStrategyBase + public class StochasticSoilModelUpdateData : IStochasticSoilModelUpdateStrategy { + private readonly ILog log = LogManager.GetLogger(typeof(StochasticSoilModelUpdateData)); + /// /// Updates the . /// Updates stochastic soil models in that are part of @@ -47,32 +49,34 @@ /// were imported. /// The current collection of . /// An action to be used to notify progress changes. - public override void UpdateModelWithImportedData( - ICollection readStochasticSoilModels, + /// Thrown when + /// contains multiple with the same , + /// and also contains a with + /// the same name. + /// + public void UpdateModelWithImportedData( + IEnumerable readStochasticSoilModels, string sourceFilePath, StochasticSoilModelCollection targetCollection, Action notifyProgress) { - var log = LogManager.GetLogger(typeof(StochasticSoilModelImporter)); + var updatedModels = new List(); - var stochasticSoilModelCount = readStochasticSoilModels.Count; - var currentIndex = 1; - var modelsToAdd = new List(readStochasticSoilModels.Count); - foreach (StochasticSoilModel readStochasticSoilModel in readStochasticSoilModels) + foreach (var readModel in readStochasticSoilModels) { - notifyProgress(Resources.Importer_ProgressText_Adding_imported_data_to_DataModel, currentIndex++, stochasticSoilModelCount); - if (!ValidateStochasticSoilModel(readStochasticSoilModel)) + var existingModel = targetCollection.SingleOrDefault(existing => existing.Name.Equals(readModel.Name)); + if (existingModel != null) { - continue; + existingModel.Update(readModel); + updatedModels.Add(existingModel); } - var stochasticSoilModel = targetCollection.FirstOrDefault(ssm => ssm.Id == readStochasticSoilModel.Id); - if (stochasticSoilModel != null) + else { - log.WarnFormat(Properties.Resources.PipingSoilProfilesImporter_AddImportedDataToModel_Stochastisch_soil_model_0_already_exists, stochasticSoilModel.Name); + updatedModels.Add(readModel); } - modelsToAdd.Add(readStochasticSoilModel); } - targetCollection.AddRange(modelsToAdd, sourceFilePath); + targetCollection.Clear(); + targetCollection.AddRange(updatedModels, sourceFilePath); } } } \ No newline at end of file