Index: Ringtoets/Common/src/Ringtoets.Common.Data/UpdateDataStrategies/UpdateDataStrategyBase.cs
===================================================================
diff -u -r92d8502b4ffd316c6387a0b1378e4d097c43c58d -r501642521ffd0016f8f8c1d1b618395c4898612b
--- Ringtoets/Common/src/Ringtoets.Common.Data/UpdateDataStrategies/UpdateDataStrategyBase.cs (.../UpdateDataStrategyBase.cs) (revision 92d8502b4ffd316c6387a0b1378e4d097c43c58d)
+++ Ringtoets/Common/src/Ringtoets.Common.Data/UpdateDataStrategies/UpdateDataStrategyBase.cs (.../UpdateDataStrategyBase.cs) (revision 501642521ffd0016f8f8c1d1b618395c4898612b)
@@ -147,7 +147,7 @@
{
affectedObjects.Add(targetDataCollection);
}
- affectedObjects.AddRange(UpdateData(targetDataCollection, importedObjects));
+ affectedObjects.AddRange(UpdateData(updatedObjects, importedObjects));
affectedObjects.AddRange(RemoveData(removedObjects));
targetDataCollection.Clear();
Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/RingtoetsPipingSurfaceLineUpdateStrategy.cs
===================================================================
diff -u -r2939615955f7dc0d299fd1baa7b2c7dafcca3db2 -r501642521ffd0016f8f8c1d1b618395c4898612b
--- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/RingtoetsPipingSurfaceLineUpdateStrategy.cs (.../RingtoetsPipingSurfaceLineUpdateStrategy.cs) (revision 2939615955f7dc0d299fd1baa7b2c7dafcca3db2)
+++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/RingtoetsPipingSurfaceLineUpdateStrategy.cs (.../RingtoetsPipingSurfaceLineUpdateStrategy.cs) (revision 501642521ffd0016f8f8c1d1b618395c4898612b)
@@ -23,7 +23,7 @@
using System.Collections.Generic;
using System.Linq;
using Core.Common.Base;
-using Core.Common.Utils;
+using Ringtoets.Common.Data.UpdateDataStrategies;
using Ringtoets.Piping.Data;
using Ringtoets.Piping.Forms;
using Ringtoets.Piping.IO.Importers;
@@ -41,131 +41,66 @@
/// - Updates the surface lines that are part of the current collection and are part of the imported surface line collection.
///
///
- public class RingtoetsPipingSurfaceLineUpdateDataStrategy : ISurfaceLineUpdateDataStrategy
+ public class RingtoetsPipingSurfaceLineUpdateDataStrategy : UpdateDataStrategyBase,
+ ISurfaceLineUpdateDataStrategy
{
- private readonly PipingFailureMechanism failureMechanism;
-
///
/// Creates a new instance of .
///
/// The failure mechanism in which the surface lines are updated.
+ /// Thrown when is null.
public RingtoetsPipingSurfaceLineUpdateDataStrategy(PipingFailureMechanism failureMechanism)
- {
- if (failureMechanism == null)
- {
- throw new ArgumentNullException(nameof(failureMechanism));
- }
+ : base(failureMechanism, new RingtoetsPipingSurfaceLineNameEqualityComparer()) {}
- this.failureMechanism = failureMechanism;
- }
-
public IEnumerable UpdateSurfaceLinesWithImportedData(RingtoetsPipingSurfaceLineCollection targetCollection,
IEnumerable readRingtoetsPipingSurfaceLines,
string sourceFilePath)
{
- if (targetCollection == null)
+ try
{
- throw new ArgumentNullException(nameof(targetCollection));
+ return UpdateTargetCollectionData(targetCollection, readRingtoetsPipingSurfaceLines, sourceFilePath);
}
- if (readRingtoetsPipingSurfaceLines == null)
+ catch (ArgumentNullException)
{
- throw new ArgumentNullException(nameof(readRingtoetsPipingSurfaceLines));
+ throw;
}
- if (sourceFilePath == null)
+ catch (ArgumentException e)
{
- throw new ArgumentNullException(nameof(sourceFilePath));
+ throw new RingtoetsPipingSurfaceLineUpdateException(e.Message, e);
}
-
- try
- {
- return ModifySurfaceLineCollection(targetCollection, readRingtoetsPipingSurfaceLines, sourceFilePath);
- }
catch (InvalidOperationException e)
{
- var message = Resources.RingtoetsPipingSurfaceLineUpdateDataStrategy_UpdateSurfaceLinesWithImportedData_Update_of_RingtoetsPipingSurfaceLine_has_failed;
+ string message = Resources.RingtoetsPipingSurfaceLineUpdateDataStrategy_UpdateSurfaceLinesWithImportedData_Update_of_RingtoetsPipingSurfaceLine_has_failed;
throw new RingtoetsPipingSurfaceLineUpdateException(message, e);
}
}
- private IEnumerable ModifySurfaceLineCollection(RingtoetsPipingSurfaceLineCollection existingCollection,
- IEnumerable readSurfaceLines,
- string sourceFilePath)
+ ///
+ /// Class for comparing by only the name.
+ ///
+ private class RingtoetsPipingSurfaceLineNameEqualityComparer : IEqualityComparer
{
- List readSurfaceLineList = readSurfaceLines.ToList();
- List addedSurfaceLines = GetAddedReadSurfaceLines(existingCollection, readSurfaceLineList).ToList();
- List updatedSurfaceLines = GetUpdatedSurfaceLines(existingCollection, readSurfaceLineList).ToList();
- List removedSurfaceLines = GetRemovedSurfaceLines(existingCollection, readSurfaceLineList).ToList();
-
- var affectedObjects = new List();
- if (addedSurfaceLines.Any())
+ public bool Equals(RingtoetsPipingSurfaceLine x, RingtoetsPipingSurfaceLine y)
{
- affectedObjects.Add(existingCollection);
+ return x.Name == y.Name;
}
- affectedObjects.AddRange(UpdateSurfaceLines(updatedSurfaceLines, readSurfaceLineList));
- affectedObjects.AddRange(RemoveSurfaceLines(removedSurfaceLines));
- existingCollection.Clear();
-
- try
+ public int GetHashCode(RingtoetsPipingSurfaceLine obj)
{
- existingCollection.AddRange(addedSurfaceLines.Union(updatedSurfaceLines), sourceFilePath);
+ return obj.Name.GetHashCode();
}
- catch (ArgumentException e)
- {
- throw new RingtoetsPipingSurfaceLineUpdateException(e.Message, e);
- }
-
- return affectedObjects.Distinct(new ReferenceEqualityComparer());
}
- private static IEnumerable GetRemovedSurfaceLines(IEnumerable existingCollection,
- IEnumerable readSurfaceLine)
- {
- return existingCollection.Except(readSurfaceLine, new RingtoetsPipingSurfaceLineNameEqualityComparer());
- }
+ #region Updating Data Functions
- private static IEnumerable GetUpdatedSurfaceLines(IEnumerable existingCollection,
- IEnumerable readSurfaceLines)
+ protected override IEnumerable UpdateData(IEnumerable objectsToUpdate,
+ IEnumerable importedDataCollection)
{
- return existingCollection.Intersect(readSurfaceLines, new RingtoetsPipingSurfaceLineNameEqualityComparer());
- }
-
- private static IEnumerable GetAddedReadSurfaceLines(IEnumerable existingCollection,
- IEnumerable readSurfaceLines)
- {
- return readSurfaceLines.Except(existingCollection, new RingtoetsPipingSurfaceLineNameEqualityComparer());
- }
-
- #region Removing surface line helpers
-
- private IEnumerable RemoveSurfaceLines(IEnumerable removedSurfaceLines)
- {
var affectedObjects = new List();
- foreach (RingtoetsPipingSurfaceLine surfaceLine in removedSurfaceLines)
+ foreach (RingtoetsPipingSurfaceLine updatedSurfaceLine in objectsToUpdate)
{
- affectedObjects.AddRange(ClearSurfaceLineDependentData(surfaceLine));
- }
- return affectedObjects;
- }
-
- private IEnumerable ClearSurfaceLineDependentData(RingtoetsPipingSurfaceLine surfaceLine)
- {
- return PipingDataSynchronizationService.RemoveSurfaceLine(failureMechanism, surfaceLine);
- }
-
- #endregion
-
- #region Updating surface line helper
-
- private IEnumerable UpdateSurfaceLines(IEnumerable updatedSurfaceLines,
- IList readSurfaceLines)
- {
- var affectedObjects = new List();
-
- foreach (RingtoetsPipingSurfaceLine updatedSurfaceLine in updatedSurfaceLines)
- {
- RingtoetsPipingSurfaceLine matchingSurfaceLine = readSurfaceLines.Single(sl => sl.Name == updatedSurfaceLine.Name);
+ RingtoetsPipingSurfaceLine matchingSurfaceLine = importedDataCollection.Single(sl => sl.Name == updatedSurfaceLine.Name);
updatedSurfaceLine.Update(matchingSurfaceLine);
affectedObjects.Add(updatedSurfaceLine);
@@ -201,20 +136,24 @@
#endregion
- ///
- /// Class for comparing by only the name.
- ///
- private class RingtoetsPipingSurfaceLineNameEqualityComparer : IEqualityComparer
+ #region Removing Data Functions
+
+ protected override IEnumerable RemoveData(IEnumerable removedObjects)
{
- public bool Equals(RingtoetsPipingSurfaceLine x, RingtoetsPipingSurfaceLine y)
- {
- return x.Name == y.Name;
- }
+ var affectedObjects = new List();
- public int GetHashCode(RingtoetsPipingSurfaceLine obj)
+ foreach (RingtoetsPipingSurfaceLine surfaceLine in removedObjects)
{
- return obj.Name.GetHashCode();
+ affectedObjects.AddRange(ClearSurfaceLineDependentData(surfaceLine));
}
+ return affectedObjects;
}
+
+ private IEnumerable ClearSurfaceLineDependentData(RingtoetsPipingSurfaceLine surfaceLine)
+ {
+ return PipingDataSynchronizationService.RemoveSurfaceLine(failureMechanism, surfaceLine);
+ }
+
+ #endregion
}
}
\ No newline at end of file
Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/StochasticSoilModelUpdateDataStrategy.cs
===================================================================
diff -u -r92549be285a5082435e9625732cf33ff50cd60b9 -r501642521ffd0016f8f8c1d1b618395c4898612b
--- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/StochasticSoilModelUpdateDataStrategy.cs (.../StochasticSoilModelUpdateDataStrategy.cs) (revision 92549be285a5082435e9625732cf33ff50cd60b9)
+++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/StochasticSoilModelUpdateDataStrategy.cs (.../StochasticSoilModelUpdateDataStrategy.cs) (revision 501642521ffd0016f8f8c1d1b618395c4898612b)
@@ -24,6 +24,7 @@
using System.Linq;
using Core.Common.Base;
using Core.Common.Utils;
+using Ringtoets.Common.Data.UpdateDataStrategies;
using Ringtoets.Piping.Data;
using Ringtoets.Piping.IO.Importers;
using Ringtoets.Piping.Plugin.Properties;
@@ -43,132 +44,71 @@
/// imported.
///
///
- public class StochasticSoilModelUpdateDataStrategy : IStochasticSoilModelUpdateModelStrategy
+ public class StochasticSoilModelUpdateDataStrategy : UpdateDataStrategyBase,
+ IStochasticSoilModelUpdateModelStrategy
{
- private readonly PipingFailureMechanism failureMechanism;
-
///
/// Creates a new instance of .
///
/// The failure mechanism in which the models are updated.
+ /// Thrown when is null.
public StochasticSoilModelUpdateDataStrategy(PipingFailureMechanism failureMechanism)
- {
- if (failureMechanism == null)
- {
- throw new ArgumentNullException(nameof(failureMechanism));
- }
- this.failureMechanism = failureMechanism;
- }
-
+ : base(failureMechanism, new SoilModelNameEqualityComparer()) {}
+
public IEnumerable UpdateModelWithImportedData(StochasticSoilModelCollection targetCollection,
IEnumerable readStochasticSoilModels,
string sourceFilePath)
{
- if (readStochasticSoilModels == null)
+ try
{
- throw new ArgumentNullException(nameof(readStochasticSoilModels));
+ return UpdateTargetCollectionData(targetCollection, readStochasticSoilModels, sourceFilePath);
}
- if (targetCollection == null)
+ catch (ArgumentNullException)
{
- throw new ArgumentNullException(nameof(targetCollection));
+ throw;
}
- if (sourceFilePath == null)
+ catch (ArgumentException e)
{
- throw new ArgumentNullException(nameof(sourceFilePath));
+ throw new StochasticSoilModelUpdateException(e.Message, e);
}
-
- try
- {
- return ModifyModelCollection(readStochasticSoilModels, targetCollection, sourceFilePath);
- }
catch (InvalidOperationException e)
{
- var message = Resources.StochasticSoilModelUpdateDataStrategy_UpdateModelWithImportedData_Update_of_StochasticSoilModel_failed;
+ string message = Resources.StochasticSoilModelUpdateDataStrategy_UpdateModelWithImportedData_Update_of_StochasticSoilModel_failed;
throw new StochasticSoilModelUpdateException(message, e);
}
}
- private IEnumerable ModifyModelCollection(IEnumerable readStochasticSoilModels,
- StochasticSoilModelCollection targetCollection,
- string sourceFilePath)
+ ///
+ /// Class for comparing by just the name.
+ ///
+ private class SoilModelNameEqualityComparer : IEqualityComparer
{
- List readModelList = readStochasticSoilModels.ToList();
- List addedModels = GetAddedReadModels(targetCollection, readModelList).ToList();
- List updatedModels = GetUpdatedExistingModels(targetCollection, readModelList).ToList();
- List removedModels = GetRemovedExistingModels(targetCollection, readModelList).ToList();
-
- var affectedObjects = new List();
- if (addedModels.Any())
+ public bool Equals(StochasticSoilModel x, StochasticSoilModel y)
{
- affectedObjects.Add(targetCollection);
+ return x.Name == y.Name;
}
- affectedObjects.AddRange(UpdateModels(updatedModels, readModelList));
- affectedObjects.AddRange(RemoveModels(removedModels));
- targetCollection.Clear();
-
- try
+ public int GetHashCode(StochasticSoilModel obj)
{
- targetCollection.AddRange(addedModels.Union(updatedModels), sourceFilePath);
+ return obj.Name.GetHashCode();
}
- catch (ArgumentException e)
- {
- throw new StochasticSoilModelUpdateException(e.Message, e);
- }
-
- return affectedObjects.Distinct(new ReferenceEqualityComparer());
}
- private static IEnumerable GetAddedReadModels(IEnumerable existingCollection, IEnumerable readStochasticSoilModels)
- {
- var comparer = new SoilModelNameEqualityComparer();
- foreach (StochasticSoilModel source in readStochasticSoilModels)
- {
- if (!existingCollection.Contains(source, comparer))
- {
- yield return source;
- }
- }
- }
+ #region Update Data Functions
- private static IEnumerable GetUpdatedExistingModels(IEnumerable existingCollection, IEnumerable readStochasticSoilModels)
+ protected override IEnumerable UpdateData(IEnumerable objectsToUpdate,
+ IEnumerable importedDataCollection)
{
- return existingCollection.Intersect(readStochasticSoilModels, new SoilModelNameEqualityComparer());
- }
-
- private static IEnumerable GetRemovedExistingModels(IEnumerable existingCollection, IEnumerable readStochasticSoilModels)
- {
- return existingCollection.Except(readStochasticSoilModels, new SoilModelNameEqualityComparer());
- }
-
- private IEnumerable RemoveModels(IEnumerable removedModels)
- {
var affectedObjects = new List();
-
- foreach (var model in removedModels)
+ foreach (StochasticSoilModel updatedModel in objectsToUpdate)
{
- affectedObjects.AddRange(ClearStochasticSoilModelDependentData(model));
- }
- return affectedObjects;
- }
-
- private IEnumerable UpdateModels(IList updatedModels, IList readModels)
- {
- var affectedObjects = new List();
- foreach (StochasticSoilModel updatedModel in updatedModels)
- {
affectedObjects.Add(updatedModel);
- StochasticSoilModel readModel = readModels.Single(r => r.Name.Equals(updatedModel.Name));
+ StochasticSoilModel readModel = importedDataCollection.Single(r => r.Name.Equals(updatedModel.Name));
affectedObjects.AddRange(UpdateStochasticSoilModel(updatedModel, readModel));
}
return affectedObjects;
}
- private IEnumerable ClearStochasticSoilModelDependentData(StochasticSoilModel removedModel)
- {
- return PipingDataSynchronizationService.RemoveStochasticSoilModel(failureMechanism, removedModel);
- }
-
private IEnumerable UpdateStochasticSoilModel(StochasticSoilModel existingModel, StochasticSoilModel readModel)
{
Dictionary oldProfiles = existingModel
@@ -192,20 +132,26 @@
return affectedObjects;
}
- ///
- /// Class for comparing by just the name.
- ///
- private class SoilModelNameEqualityComparer : IEqualityComparer
+ #endregion
+
+ #region Remove Data Functions
+
+ protected override IEnumerable RemoveData(IEnumerable removedObjects)
{
- public bool Equals(StochasticSoilModel x, StochasticSoilModel y)
- {
- return x.Name == y.Name;
- }
+ var affectedObjects = new List();
- public int GetHashCode(StochasticSoilModel obj)
+ foreach (StochasticSoilModel model in removedObjects)
{
- return obj.Name.GetHashCode();
+ affectedObjects.AddRange(ClearStochasticSoilModelDependentData(model));
}
+ return affectedObjects;
}
+
+ private IEnumerable ClearStochasticSoilModelDependentData(StochasticSoilModel removedModel)
+ {
+ return PipingDataSynchronizationService.RemoveStochasticSoilModel(failureMechanism, removedModel);
+ }
+
+ #endregion
}
}
\ No newline at end of file
Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/RingtoetsPipingSurfaceLineUpdateDataStrategyTest.cs
===================================================================
diff -u -r2939615955f7dc0d299fd1baa7b2c7dafcca3db2 -r501642521ffd0016f8f8c1d1b618395c4898612b
--- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/RingtoetsPipingSurfaceLineUpdateDataStrategyTest.cs (.../RingtoetsPipingSurfaceLineUpdateDataStrategyTest.cs) (revision 2939615955f7dc0d299fd1baa7b2c7dafcca3db2)
+++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/RingtoetsPipingSurfaceLineUpdateDataStrategyTest.cs (.../RingtoetsPipingSurfaceLineUpdateDataStrategyTest.cs) (revision 501642521ffd0016f8f8c1d1b618395c4898612b)
@@ -25,6 +25,7 @@
using Core.Common.Base;
using Core.Common.Base.Geometry;
using NUnit.Framework;
+using Ringtoets.Common.Data.UpdateDataStrategies;
using Ringtoets.Piping.Data;
using Ringtoets.Piping.IO.Importers;
using Ringtoets.Piping.Plugin.FileImporter;
@@ -56,6 +57,7 @@
// Assert
Assert.IsInstanceOf(strategy);
+ Assert.IsInstanceOf>(strategy);
}
[Test]
@@ -69,7 +71,7 @@
// Assert
string paramName = Assert.Throws(test).ParamName;
- Assert.AreEqual("targetCollection", paramName);
+ Assert.AreEqual("targetDataCollection", paramName);
}
[Test]
@@ -85,7 +87,7 @@
// Assert
string paramName = Assert.Throws(test).ParamName;
- Assert.AreEqual("readRingtoetsPipingSurfaceLines", paramName);
+ Assert.AreEqual("importedDataCollection", paramName);
}
[Test]
@@ -397,7 +399,7 @@
StochasticSoilModel = soilModels[1]
}
};
-
+
var failureMechanism = new PipingFailureMechanism();
failureMechanism.CalculationsGroup.Children.Add(calculation);
failureMechanism.SurfaceLines.AddRange(new[]
Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/StochasticSoilModelUpdateDataStrategyTest.cs
===================================================================
diff -u -rc290911dd4647e3115e239c8baf814717c098a5a -r501642521ffd0016f8f8c1d1b618395c4898612b
--- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/StochasticSoilModelUpdateDataStrategyTest.cs (.../StochasticSoilModelUpdateDataStrategyTest.cs) (revision c290911dd4647e3115e239c8baf814717c098a5a)
+++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/StochasticSoilModelUpdateDataStrategyTest.cs (.../StochasticSoilModelUpdateDataStrategyTest.cs) (revision 501642521ffd0016f8f8c1d1b618395c4898612b)
@@ -24,6 +24,7 @@
using System.Linq;
using Core.Common.Base;
using NUnit.Framework;
+using Ringtoets.Common.Data.UpdateDataStrategies;
using Ringtoets.Piping.Data;
using Ringtoets.Piping.Data.TestUtil;
using Ringtoets.Piping.IO.Importers;
@@ -57,6 +58,7 @@
// Assert
Assert.IsInstanceOf(strategy);
+ Assert.IsInstanceOf>(strategy);
}
[Test]
@@ -70,7 +72,7 @@
// Assert
string paramName = Assert.Throws(test).ParamName;
- Assert.AreEqual("readStochasticSoilModels", paramName);
+ Assert.AreEqual("importedDataCollection", paramName);
}
[Test]
@@ -98,7 +100,7 @@
// Assert
string paramName = Assert.Throws(test).ParamName;
- Assert.AreEqual("targetCollection", paramName);
+ Assert.AreEqual("targetDataCollection", paramName);
}
[Test]