Index: Core/Common/src/Core.Common.Base/IO/FileImporterBase.cs
===================================================================
diff -u -r54c7814db3c2403b6427afb131cd48acd496c396 -r3c17d0ec1a154f1c5a19601fd8885366a01b2daa
--- Core/Common/src/Core.Common.Base/IO/FileImporterBase.cs (.../FileImporterBase.cs) (revision 54c7814db3c2403b6427afb131cd48acd496c396)
+++ Core/Common/src/Core.Common.Base/IO/FileImporterBase.cs (.../FileImporterBase.cs) (revision 3c17d0ec1a154f1c5a19601fd8885366a01b2daa)
@@ -22,6 +22,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using Core.Common.Base.Properties;
+using log4net;
namespace Core.Common.Base.IO
{
@@ -33,6 +35,8 @@
/// Object type that is the target for this importer.
public abstract class FileImporterBase : IFileImporter
{
+ private readonly ILog log = LogManager.GetLogger(typeof(FileImporterBase));
+
///
/// Initializes a new instance of the class.
///
@@ -44,12 +48,12 @@
{
if (filePath == null)
{
- throw new ArgumentNullException("filePath");
+ throw new ArgumentNullException(nameof(filePath));
}
if (importTarget == null)
{
- throw new ArgumentNullException("importTarget");
+ throw new ArgumentNullException(nameof(importTarget));
}
FilePath = filePath;
@@ -61,8 +65,35 @@
ProgressChanged = action;
}
- public abstract bool Import();
+ public bool Import()
+ {
+ Canceled = false;
+ bool importResult = OnImport();
+ if (importResult)
+ {
+ if (Canceled)
+ {
+ LogImportUncancellableMessage();
+ Canceled = false;
+ }
+ }
+ else
+ {
+ if (AffectedNonTargetObservableInstances.Any())
+ {
+ throw new InvalidOperationException("There should be no affected items in case of a canceled or failed import.");
+ }
+
+ if (Canceled)
+ {
+ LogImportCanceledMessage();
+ }
+ }
+
+ return importResult;
+ }
+
public void Cancel()
{
Canceled = true;
@@ -98,14 +129,14 @@
protected string FilePath { get; private set; }
///
- /// Gets or sets value indicating if a cancel request has been made. When true, no
+ /// Gets the value indicating if a cancel request has been made. When true, no
/// changes should be made to the data model unless the importer is already in progress
/// of changing the data model.
///
- protected bool Canceled { get; set; }
+ protected bool Canceled { get; private set; }
///
- /// Gets all objects that have been affected during the call
+ /// Gets all objects that have been affected during the call
/// that implement and which are not the targeted object
/// to import the data to.
///
@@ -119,6 +150,17 @@
}
}
+ ///
+ /// This method logs messages when the importer is cancelled in a cancelable state.
+ ///
+ protected virtual void LogImportCanceledMessage() {}
+
+ ///
+ /// This method returns the result of the import action.
+ ///
+ /// True if the import was succesful, false if otherwise.
+ protected abstract bool OnImport();
+
protected void NotifyProgress(string currentStepName, int currentStep, int totalNumberOfSteps)
{
if (ProgressChanged != null)
@@ -128,5 +170,10 @@
}
private OnProgressChanged ProgressChanged { get; set; }
+
+ private void LogImportUncancellableMessage()
+ {
+ log.Warn(Resources.FileImporterBase_LogUncancellableMessage_Import_cannot_be_canceled_and_continued);
+ }
}
}
\ No newline at end of file
Index: Core/Common/src/Core.Common.Base/Properties/Resources.Designer.cs
===================================================================
diff -u -r6f159dc2b01ba3605c9c67a3405275fe88d24741 -r3c17d0ec1a154f1c5a19601fd8885366a01b2daa
--- Core/Common/src/Core.Common.Base/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 6f159dc2b01ba3605c9c67a3405275fe88d24741)
+++ Core/Common/src/Core.Common.Base/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 3c17d0ec1a154f1c5a19601fd8885366a01b2daa)
@@ -22,7 +22,7 @@
//------------------------------------------------------------------------------
//
// This code was generated by a tool.
-// Runtime Version:4.0.30319.17929
+// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
@@ -146,6 +146,15 @@
}
///
+ /// Looks up a localized string similar to Huidige actie was niet meer te annuleren en is daarom voortgezet..
+ ///
+ public static string FileImporterBase_LogUncancellableMessage_Import_cannot_be_canceled_and_continued {
+ get {
+ return ResourceManager.GetString("FileImporterBase_LogUncancellableMessage_Import_cannot_be_canceled_and_continued", resourceCulture);
+ }
+ }
+
+ ///
/// Looks up a localized string similar to Punten voor een lijn moeten uit elkaar liggen om een lijn te kunnen vormen..
///
public static string Math2D_LineIntersectionWithLine_Line_points_are_equal {
Index: Core/Common/src/Core.Common.Base/Properties/Resources.resx
===================================================================
diff -u -r6f159dc2b01ba3605c9c67a3405275fe88d24741 -r3c17d0ec1a154f1c5a19601fd8885366a01b2daa
--- Core/Common/src/Core.Common.Base/Properties/Resources.resx (.../Resources.resx) (revision 6f159dc2b01ba3605c9c67a3405275fe88d24741)
+++ Core/Common/src/Core.Common.Base/Properties/Resources.resx (.../Resources.resx) (revision 3c17d0ec1a154f1c5a19601fd8885366a01b2daa)
@@ -174,4 +174,7 @@
Fout
+
+ Huidige actie was niet meer te annuleren en is daarom voortgezet.
+
\ No newline at end of file
Index: Core/Common/src/Core.Common.Base/Service/FileImportActivity.cs
===================================================================
diff -u -r489a69776408397699e1cf17866530ad2a1a3d4e -r3c17d0ec1a154f1c5a19601fd8885366a01b2daa
--- Core/Common/src/Core.Common.Base/Service/FileImportActivity.cs (.../FileImportActivity.cs) (revision 489a69776408397699e1cf17866530ad2a1a3d4e)
+++ Core/Common/src/Core.Common.Base/Service/FileImportActivity.cs (.../FileImportActivity.cs) (revision 3c17d0ec1a154f1c5a19601fd8885366a01b2daa)
@@ -43,11 +43,11 @@
{
if (fileImporter == null)
{
- throw new ArgumentNullException("fileImporter");
+ throw new ArgumentNullException(nameof(fileImporter));
}
if (name == null)
{
- throw new ArgumentNullException("name");
+ throw new ArgumentNullException(nameof(name));
}
this.fileImporter = fileImporter;
@@ -67,8 +67,17 @@
currentStep, totalSteps, currentStepName);
});
- if (!fileImporter.Import() && State != ActivityState.Canceled)
+ bool importSuccessful = fileImporter.Import();
+
+ if (State == ActivityState.Canceled)
{
+ if (importSuccessful)
+ {
+ State = ActivityState.Executed;
+ }
+ }
+ else if (!importSuccessful)
+ {
State = ActivityState.Failed;
}
}
Index: Core/Common/test/Core.Common.Base.Test/IO/FileImporterBaseTest.cs
===================================================================
diff -u -r54c7814db3c2403b6427afb131cd48acd496c396 -r3c17d0ec1a154f1c5a19601fd8885366a01b2daa
--- Core/Common/test/Core.Common.Base.Test/IO/FileImporterBaseTest.cs (.../FileImporterBaseTest.cs) (revision 54c7814db3c2403b6427afb131cd48acd496c396)
+++ Core/Common/test/Core.Common.Base.Test/IO/FileImporterBaseTest.cs (.../FileImporterBaseTest.cs) (revision 3c17d0ec1a154f1c5a19601fd8885366a01b2daa)
@@ -22,6 +22,7 @@
using System;
using System.Collections.Generic;
using Core.Common.Base.IO;
+using Core.Common.TestUtil;
using NUnit.Framework;
using Rhino.Mocks;
@@ -178,31 +179,116 @@
Assert.AreEqual(1, progressChangedCallCount);
}
+ [Test]
+ public void Import_CancelGivesSuccesfulImport_LogsMessage()
+ {
+ // Setup
+ var importTarget = new object();
+ var simpleImporter = new SimpleFileImporter(importTarget)
+ {
+ ImportSuccesful = true
+ };
+
+ simpleImporter.SetProgressChanged((description, step, steps) => simpleImporter.Cancel());
+
+ // Call
+ Action call = () => simpleImporter.Import();
+
+ // Assert
+ TestHelper.AssertLogMessageIsGenerated(call, "Huidige actie was niet meer te annuleren en is daarom voortgezet.");
+ }
+
+ [Test]
+ public void Import_CancelGivesUnsuccesfulImport_CallsLogImportoverigensCanceledMessage()
+ {
+ // Setup
+ var importTarget = new object();
+ var simpleImporter = new SimpleFileImporter(importTarget)
+ {
+ ImportSuccesful = false
+ };
+
+ simpleImporter.SetProgressChanged((description, step, steps) => simpleImporter.Cancel());
+
+ // Call
+ simpleImporter.Import();
+
+ // Assert
+ Assert.IsTrue(simpleImporter.LogCanceledMessageCalled);
+ }
+
+ [Test]
+ [TestCase(true)]
+ [TestCase(false)]
+ public void Import_UnsuccesfulAndHasAffectedNonTargetObservableInstances_ThrowsInvalidOperationException(bool isImportCancelled)
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var observableInstance = mocks.StrictMock();
+ var observableTarget = mocks.StrictMock();
+ mocks.ReplayAll();
+
+ var simpleImporter = new SimpleFileImporter(observableTarget)
+ {
+ AffectedNonTargetObservableInstancesOverride = new[]
+ {
+ observableInstance
+ },
+ ImportSuccesful = false
+ };
+
+ if (isImportCancelled)
+ {
+ simpleImporter.SetProgressChanged((description, step, steps) => simpleImporter.Cancel());
+ }
+
+ // Call
+ TestDelegate call = () => simpleImporter.Import();
+
+ // Assert
+ string message = Assert.Throws(call).Message;
+ const string expectedMessage = "There should be no affected items in case of a canceled or failed import.";
+ Assert.AreEqual(expectedMessage, message);
+ }
+
private class SimpleFileImporter : FileImporterBase
{
- public SimpleFileImporter(T importTarget) : base("", importTarget) {}
+ public SimpleFileImporter(T importTarget) : this("", importTarget) {}
- public SimpleFileImporter(string filePath, T importTarget) : base(filePath, importTarget) {}
+ public SimpleFileImporter(string filePath, T importTarget) : base(filePath, importTarget)
+ {
+ LogCanceledMessageCalled = false;
+ }
+ public bool ImportSuccesful { private get; set; }
+
+ public bool LogCanceledMessageCalled { get; private set; }
+
public IObservable[] AffectedNonTargetObservableInstancesOverride { private get; set; }
public void TestNotifyProgress(string currentStepName, int currentStep, int totalNumberOfSteps)
{
NotifyProgress(currentStepName, currentStep, totalNumberOfSteps);
}
- public override bool Import()
- {
- throw new NotImplementedException();
- }
-
protected override IEnumerable AffectedNonTargetObservableInstances
{
get
{
return AffectedNonTargetObservableInstancesOverride ?? base.AffectedNonTargetObservableInstances;
}
}
+
+ protected override bool OnImport()
+ {
+ TestNotifyProgress(string.Empty, 1, 1);
+ return ImportSuccesful;
+ }
+
+ protected override void LogImportCanceledMessage()
+ {
+ LogCanceledMessageCalled = true;
+ }
}
}
}
\ No newline at end of file
Index: Core/Common/test/Core.Common.Base.Test/Service/FileImportActivityTest.cs
===================================================================
diff -u -r489a69776408397699e1cf17866530ad2a1a3d4e -r3c17d0ec1a154f1c5a19601fd8885366a01b2daa
--- Core/Common/test/Core.Common.Base.Test/Service/FileImportActivityTest.cs (.../FileImportActivityTest.cs) (revision 489a69776408397699e1cf17866530ad2a1a3d4e)
+++ Core/Common/test/Core.Common.Base.Test/Service/FileImportActivityTest.cs (.../FileImportActivityTest.cs) (revision 3c17d0ec1a154f1c5a19601fd8885366a01b2daa)
@@ -116,9 +116,35 @@
}
[Test]
- public void Cancel_WhenImporting_ImportActivityStateCancelled()
+ public void Cancel_WhenImportingAndUncancellable_ImportActivityStateExecuted()
{
// Setup
+ var mocks = new MockRepository();
+ var fileImporter = mocks.Stub();
+ fileImporter.Stub(x => x.SetProgressChanged(null)).IgnoreArguments();
+ fileImporter.Stub(i => i.Import()).Return(true);
+ mocks.ReplayAll();
+
+ var fileImportActivity = new FileImportActivity(fileImporter, "");
+ fileImportActivity.ProgressChanged += (sender, args) =>
+ {
+ if (fileImportActivity.State != ActivityState.Canceled)
+ {
+ // Call
+ fileImportActivity.Cancel();
+ }
+ };
+
+ // Assert
+ fileImportActivity.Run();
+ Assert.AreEqual(ActivityState.Executed, fileImportActivity.State);
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void Cancel_WhenImportingAndCancellable_ImportActivityStateCancelled()
+ {
+ // Setup
var fileImporter = new SimpleFileImporter(new object());
var fileImportActivity = new FileImportActivity(fileImporter, "");
fileImportActivity.ProgressChanged += (sender, args) =>
@@ -195,11 +221,11 @@
{
public SimpleFileImporter(T importTarget) : base("", importTarget) {}
- public override bool Import()
+ protected override bool OnImport()
{
NotifyProgress("Step description", 1, 10);
- return true;
+ return false;
}
}
}
Index: Core/Components/src/Core.Components.Gis.IO/Importers/FeatureBasedMapDataImporter.cs
===================================================================
diff -u -r0324c332753d36bb804a804b9757ef1cd336435f -r3c17d0ec1a154f1c5a19601fd8885366a01b2daa
--- Core/Components/src/Core.Components.Gis.IO/Importers/FeatureBasedMapDataImporter.cs (.../FeatureBasedMapDataImporter.cs) (revision 0324c332753d36bb804a804b9757ef1cd336435f)
+++ Core/Components/src/Core.Components.Gis.IO/Importers/FeatureBasedMapDataImporter.cs (.../FeatureBasedMapDataImporter.cs) (revision 3c17d0ec1a154f1c5a19601fd8885366a01b2daa)
@@ -54,25 +54,24 @@
public FeatureBasedMapDataImporter(MapDataCollection importTarget, string filePath)
: base(filePath, importTarget) {}
- public override bool Import()
+ protected override bool OnImport()
{
ReadResult readResult = ReadFeatureBasedMapData();
- if (readResult.CriticalErrorOccurred)
+ if (readResult.CriticalErrorOccurred || Canceled)
{
return false;
}
- if (Canceled)
- {
- HandleUserCancellingImport();
- return false;
- }
-
AddFeatureBasedMapDataToMapDataCollection(readResult.ImportedItems.First());
return true;
}
+ protected override void LogImportCanceledMessage()
+ {
+ log.Info(Resources.FeatureBasedMapDataImporter_HandleUserCancellingImport_Import_cancelled_no_data_read);
+ }
+
private void AddFeatureBasedMapDataToMapDataCollection(FeatureBasedMapData importedMapData)
{
ImportTarget.Add(importedMapData);
@@ -151,10 +150,5 @@
log.Error(errorMessage);
return new ReadResult(true);
}
-
- private static void HandleUserCancellingImport()
- {
- log.Info(Resources.FeatureBasedMapDataImporter_HandleUserCancellingImport_Import_cancelled_no_data_read);
- }
}
}
\ No newline at end of file
Index: Core/Components/test/Core.Components.Gis.IO.Test/Importers/FeatureBasedMapDataImporterTest.cs
===================================================================
diff -u -rc9667df5e30c9fc7083fd727aa497714621053f6 -r3c17d0ec1a154f1c5a19601fd8885366a01b2daa
--- Core/Components/test/Core.Components.Gis.IO.Test/Importers/FeatureBasedMapDataImporterTest.cs (.../FeatureBasedMapDataImporterTest.cs) (revision c9667df5e30c9fc7083fd727aa497714621053f6)
+++ Core/Components/test/Core.Components.Gis.IO.Test/Importers/FeatureBasedMapDataImporterTest.cs (.../FeatureBasedMapDataImporterTest.cs) (revision 3c17d0ec1a154f1c5a19601fd8885366a01b2daa)
@@ -152,29 +152,6 @@
}
[Test]
- public void Import_ValidFileImportBeingCancelled_ReturnFalseAndNoChanges()
- {
- // Setup
- var path = TestHelper.GetTestDataPath(TestDataPath.Core.Components.Gis.IO, "Single_Point_with_ID.shp");
- var mapDataCollection = new MapDataCollection("test");
- var importer = new FeatureBasedMapDataImporter(mapDataCollection, path);
-
- // Precondition
- CollectionAssert.IsEmpty(mapDataCollection.Collection);
-
- importer.Cancel();
-
- // Call
- bool importSuccesful = true;
- Action call = () => importSuccesful = importer.Import();
-
- // Assert
- TestHelper.AssertLogMessageIsGenerated(call, "Kaartlaag toevoegen afgebroken. Geen data ingelezen.", 1);
- Assert.IsFalse(importSuccesful);
- CollectionAssert.IsEmpty(mapDataCollection.Collection);
- }
-
- [Test]
public void DoPostImportUpdates_ImportSuccesful_NotifiesMapDataCollection()
{
// Setup
Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.IO/ClosingStructuresImporter.cs
===================================================================
diff -u -rd641f7a03b05f5d7e48f9adeffabafdcb48e1c14 -r3c17d0ec1a154f1c5a19601fd8885366a01b2daa
--- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.IO/ClosingStructuresImporter.cs (.../ClosingStructuresImporter.cs) (revision d641f7a03b05f5d7e48f9adeffabafdcb48e1c14)
+++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.IO/ClosingStructuresImporter.cs (.../ClosingStructuresImporter.cs) (revision 3c17d0ec1a154f1c5a19601fd8885366a01b2daa)
@@ -60,12 +60,6 @@
}
}
- protected override void HandleUserCancellingImport()
- {
- Log.Info(RingtoetsCommonIOResources.StructuresImporter_User_cancelled);
- base.HandleUserCancellingImport();
- }
-
private IEnumerable CreateClosingStructures(IList structureLocations,
Dictionary> groupedStructureParameterRows)
{
Index: Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/DikeProfilesImporter.cs
===================================================================
diff -u -r25695fa024db28f8926ed7e361d19bec16d3c112 -r3c17d0ec1a154f1c5a19601fd8885366a01b2daa
--- Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/DikeProfilesImporter.cs (.../DikeProfilesImporter.cs) (revision 25695fa024db28f8926ed7e361d19bec16d3c112)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/DikeProfilesImporter.cs (.../DikeProfilesImporter.cs) (revision 3c17d0ec1a154f1c5a19601fd8885366a01b2daa)
@@ -60,10 +60,9 @@
}
}
- protected override void HandleUserCancellingImport()
+ protected override void LogImportCanceledMessage()
{
Log.Info(Resources.DikeProfilesImporter_HandleUserCancellingImport_dikeprofile_import_aborted);
- base.HandleUserCancellingImport();
}
protected override bool DikeProfileDataIsValid(DikeProfileData data, string prflFilePath)
Index: Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/FailureMechanismSectionsImporter.cs
===================================================================
diff -u -ra6b7d895b8e5fe00b1fccb22f473637e87e3bcc8 -r3c17d0ec1a154f1c5a19601fd8885366a01b2daa
--- Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/FailureMechanismSectionsImporter.cs (.../FailureMechanismSectionsImporter.cs) (revision a6b7d895b8e5fe00b1fccb22f473637e87e3bcc8)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/FailureMechanismSectionsImporter.cs (.../FailureMechanismSectionsImporter.cs) (revision 3c17d0ec1a154f1c5a19601fd8885366a01b2daa)
@@ -65,27 +65,21 @@
{
if (referenceLine == null)
{
- throw new ArgumentNullException("referenceLine");
+ throw new ArgumentNullException(nameof(referenceLine));
}
this.referenceLine = referenceLine;
}
- public override bool Import()
+ protected override bool OnImport()
{
NotifyProgress(Resources.FailureMechanismSectionsImporter_ProgressText_Reading_file, 1, 3);
ReadResult readResults = ReadFailureMechanismSections();
- if (readResults.CriticalErrorOccurred)
+ if (readResults.CriticalErrorOccurred || Canceled)
{
return false;
}
- if (Canceled)
- {
- HandleUserCancellingImport();
- return false;
- }
-
NotifyProgress(Resources.FailureMechanismSectionsImporter_ProgressText_Validating_imported_sections, 2, 3);
ICollection readFailureMechanismSections = readResults.ImportedItems;
if (HasStartOrEndPointsTooFarFromReferenceLine(referenceLine, readFailureMechanismSections))
@@ -101,7 +95,6 @@
if (Canceled)
{
- HandleUserCancellingImport();
return false;
}
@@ -110,10 +103,9 @@
return true;
}
- private void HandleUserCancellingImport()
+ protected override void LogImportCanceledMessage()
{
log.Info(Resources.FailureMechanismSectionsImporter_Import_cancelled_no_data_read);
- Canceled = false;
}
private ReadResult ReadFailureMechanismSections()
Index: Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/ForeshoreProfilesImporter.cs
===================================================================
diff -u -r25695fa024db28f8926ed7e361d19bec16d3c112 -r3c17d0ec1a154f1c5a19601fd8885366a01b2daa
--- Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/ForeshoreProfilesImporter.cs (.../ForeshoreProfilesImporter.cs) (revision 25695fa024db28f8926ed7e361d19bec16d3c112)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/ForeshoreProfilesImporter.cs (.../ForeshoreProfilesImporter.cs) (revision 3c17d0ec1a154f1c5a19601fd8885366a01b2daa)
@@ -60,10 +60,9 @@
}
}
- protected override void HandleUserCancellingImport()
+ protected override void LogImportCanceledMessage()
{
Log.Info(Resources.ForeshoreProfilesImporter_HandleUserCancellingImport_foreshoreprofile_import_aborted);
- base.HandleUserCancellingImport();
}
protected override bool DikeProfileDataIsValid(DikeProfileData data, string prflFilePath)
Index: Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/ProfilesImporter.cs
===================================================================
diff -u -ra633912c0e5c538b2a0849eea7c1ab4957aaadeb -r3c17d0ec1a154f1c5a19601fd8885366a01b2daa
--- Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/ProfilesImporter.cs (.../ProfilesImporter.cs) (revision a633912c0e5c538b2a0849eea7c1ab4957aaadeb)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/ProfilesImporter.cs (.../ProfilesImporter.cs) (revision 3c17d0ec1a154f1c5a19601fd8885366a01b2daa)
@@ -65,34 +65,22 @@
this.referenceLine = referenceLine;
}
- public override bool Import()
+ protected override bool OnImport()
{
ReadResult importDikeProfilesResult = ReadProfileLocations();
- if (importDikeProfilesResult.CriticalErrorOccurred)
+ if (importDikeProfilesResult.CriticalErrorOccurred || Canceled)
{
return false;
}
- if (Canceled)
- {
- HandleUserCancellingImport();
- return false;
- }
-
string folderPath = Path.GetDirectoryName(FilePath);
string[] acceptedIds = importDikeProfilesResult.ImportedItems.Select(dp => dp.Id).ToArray();
ReadResult importDikeProfileDataResult = ReadDikeProfileData(folderPath, acceptedIds);
- if (importDikeProfileDataResult.CriticalErrorOccurred)
+ if (importDikeProfileDataResult.CriticalErrorOccurred || Canceled)
{
return false;
}
- if (Canceled)
- {
- HandleUserCancellingImport();
- return false;
- }
-
CreateProfiles(importDikeProfilesResult, importDikeProfileDataResult);
return true;
@@ -137,14 +125,6 @@
}
///
- /// Act upon the user cancelling the import operation.
- ///
- protected virtual void HandleUserCancellingImport()
- {
- Canceled = false;
- }
-
- ///
/// Validate the consistency of a object.
///
/// The to validate.
Index: Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/StructuresImporter.cs
===================================================================
diff -u -r723c48084f30ec6a930a9ef16cf1a657e9eeec65 -r3c17d0ec1a154f1c5a19601fd8885366a01b2daa
--- Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/StructuresImporter.cs (.../StructuresImporter.cs) (revision 723c48084f30ec6a930a9ef16cf1a657e9eeec65)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/StructuresImporter.cs (.../StructuresImporter.cs) (revision 3c17d0ec1a154f1c5a19601fd8885366a01b2daa)
@@ -43,7 +43,7 @@
///
public abstract class StructuresImporter : FileImporterBase
{
- protected readonly ILog Log = LogManager.GetLogger(typeof(StructuresImporter));
+ private readonly ILog Log = LogManager.GetLogger(typeof(StructuresImporter));
private readonly ReferenceLine referenceLine;
///
@@ -65,43 +65,27 @@
this.referenceLine = referenceLine;
}
- public override bool Import()
+ protected override bool OnImport()
{
ReadResult importStructureLocationsResult = ReadStructureLocations();
- if (importStructureLocationsResult.CriticalErrorOccurred)
+ if (importStructureLocationsResult.CriticalErrorOccurred || Canceled)
{
return false;
}
- if (Canceled)
- {
- HandleUserCancellingImport();
- return false;
- }
-
ReadResult importStructureParameterRowsDataResult = ReadStructureParameterRowsData();
- if (importStructureParameterRowsDataResult.CriticalErrorOccurred)
+ if (importStructureParameterRowsDataResult.CriticalErrorOccurred || Canceled)
{
return false;
}
- if (Canceled)
- {
- HandleUserCancellingImport();
- return false;
- }
-
CreateStructures(importStructureLocationsResult, importStructureParameterRowsDataResult);
-
return true;
}
- ///
- /// Act upon the user cancelling the import operation.
- ///
- protected virtual void HandleUserCancellingImport()
+ protected override void LogImportCanceledMessage()
{
- Canceled = false;
+ Log.Info(Resources.StructuresImporter_User_cancelled);
}
///
Index: Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLines/ReferenceLineImporter.cs
===================================================================
diff -u -rce9e1d476f00cfb42ce2a8ab6c762baf5abfd97b -r3c17d0ec1a154f1c5a19601fd8885366a01b2daa
--- Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLines/ReferenceLineImporter.cs (.../ReferenceLineImporter.cs) (revision ce9e1d476f00cfb42ce2a8ab6c762baf5abfd97b)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLines/ReferenceLineImporter.cs (.../ReferenceLineImporter.cs) (revision 3c17d0ec1a154f1c5a19601fd8885366a01b2daa)
@@ -56,37 +56,33 @@
this.replacementHandler = replacementHandler;
}
- public override bool Import()
+ protected override bool OnImport()
{
- Canceled = false;
changedObservables.Clear();
bool clearReferenceLineDependentData = IsClearingOfReferenceLineDependentDataRequired();
-
if (Canceled)
{
- HandleUserCancellingImport();
return false;
}
NotifyProgress(RingtoetsCommonIOResources.ReferenceLineImporter_ProgressText_Reading_referenceline,
1, clearReferenceLineDependentData ? 3 : 2);
ReadResult readResult = ReadReferenceLine();
- if (readResult.CriticalErrorOccurred)
+ if (readResult.CriticalErrorOccurred || Canceled)
{
return false;
}
- if (Canceled)
- {
- HandleUserCancellingImport();
- return false;
- }
-
AddReferenceLineToDataModel(readResult.ImportedItems.First(), clearReferenceLineDependentData);
return true;
}
+ protected override void LogImportCanceledMessage()
+ {
+ log.Info(RingtoetsCommonIOResources.ReferenceLineImporter_ProgressText_Import_cancelled_no_data_read);
+ }
+
public override void DoPostImportUpdates()
{
replacementHandler.DoPostReplacementUpdates();
@@ -109,7 +105,7 @@
{
if (!replacementHandler.ConfirmReplace())
{
- Canceled = true;
+ Cancel();
}
else
{
@@ -119,11 +115,6 @@
return clearReferenceLineDependentData;
}
- private static void HandleUserCancellingImport()
- {
- log.Info(RingtoetsCommonIOResources.ReferenceLineImporter_ProgressText_Import_cancelled_no_data_read);
- }
-
private ReadResult ReadReferenceLine()
{
try
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/FileImporters/DikeProfilesImporterTest.cs
===================================================================
diff -u -r01d327694595b1acb77a9b0532a0d5bb91c9eadb -r3c17d0ec1a154f1c5a19601fd8885366a01b2daa
--- Ringtoets/Common/test/Ringtoets.Common.IO.Test/FileImporters/DikeProfilesImporterTest.cs (.../DikeProfilesImporterTest.cs) (revision 01d327694595b1acb77a9b0532a0d5bb91c9eadb)
+++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/FileImporters/DikeProfilesImporterTest.cs (.../DikeProfilesImporterTest.cs) (revision 3c17d0ec1a154f1c5a19601fd8885366a01b2daa)
@@ -280,18 +280,52 @@
}
[Test]
- public void Import_CancelOfImportToValidTargetWithValidFile_CancelImportAndLog()
+ public void Import_CancelOfImportWhileReadingProfileLocations_CancelImportAndLogs()
{
// Setup
string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO,
Path.Combine("DikeProfiles", "AllOkTestData", "Voorlanden 12-2.shp"));
ReferenceLine referenceLine = CreateMatchingReferenceLine();
+ var dikeProfiles = new ObservableList();
+ var dikeProfilesImporter = new DikeProfilesImporter(dikeProfiles, referenceLine, filePath);
+ dikeProfilesImporter.SetProgressChanged((description, step, steps) =>
+ {
+ if (description.Contains("Inlezen van profiellocaties uit een shapebestand."))
+ {
+ dikeProfilesImporter.Cancel();
+ }
+ });
+ bool importResult = true;
+
+ // Call
+ Action call = () => importResult = dikeProfilesImporter.Import();
+
+ // Assert
+ TestHelper.AssertLogMessageIsGenerated(call, "Dijkprofielen importeren is afgebroken. Geen gegevens ingelezen.", 1);
+ Assert.IsFalse(importResult);
+ CollectionAssert.IsEmpty(dikeProfiles);
+ }
+
+ [Test]
+ public void Import_CancelOfImportWhileReadingDikeProfileData_CancelImportAndLogs()
+ {
+ // Setup
+ string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO,
+ Path.Combine("DikeProfiles", "AllOkTestData", "Voorlanden 12-2.shp"));
+
+ ReferenceLine referenceLine = CreateMatchingReferenceLine();
var dikeProfiles = new ObservableList();
var dikeProfilesImporter = new DikeProfilesImporter(dikeProfiles, referenceLine, filePath);
+ dikeProfilesImporter.SetProgressChanged((description, step, steps) =>
+ {
+ if (description.Contains("Inlezen van profielgegevens uit een prfl bestand."))
+ {
+ dikeProfilesImporter.Cancel();
+ }
+ });
- dikeProfilesImporter.Cancel();
bool importResult = true;
// Call
@@ -300,6 +334,7 @@
// Assert
TestHelper.AssertLogMessageIsGenerated(call, "Dijkprofielen importeren is afgebroken. Geen gegevens ingelezen.", 1);
Assert.IsFalse(importResult);
+ CollectionAssert.IsEmpty(dikeProfiles);
}
[Test]
@@ -313,10 +348,13 @@
var dikeProfiles = new ObservableList();
var dikeProfilesImporter = new DikeProfilesImporter(dikeProfiles, referenceLine, filePath);
+ dikeProfilesImporter.SetProgressChanged((description, step, steps) => dikeProfilesImporter.Cancel());
- dikeProfilesImporter.Cancel();
+ // Pre-condition
bool importResult = dikeProfilesImporter.Import();
Assert.IsFalse(importResult);
+ CollectionAssert.IsEmpty(dikeProfiles);
+ dikeProfilesImporter.SetProgressChanged(null);
// Call
importResult = dikeProfilesImporter.Import();
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/FileImporters/FailureMechanismSectionsImporterTest.cs
===================================================================
diff -u -r0d16ab05f8d9c06a04e09a9f9d47c20304c2f831 -r3c17d0ec1a154f1c5a19601fd8885366a01b2daa
--- Ringtoets/Common/test/Ringtoets.Common.IO.Test/FileImporters/FailureMechanismSectionsImporterTest.cs (.../FailureMechanismSectionsImporterTest.cs) (revision 0d16ab05f8d9c06a04e09a9f9d47c20304c2f831)
+++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/FileImporters/FailureMechanismSectionsImporterTest.cs (.../FailureMechanismSectionsImporterTest.cs) (revision 3c17d0ec1a154f1c5a19601fd8885366a01b2daa)
@@ -429,6 +429,106 @@
}
[Test]
+ public void Import_CancelOfImportWhenReadingFailureMechanismSections_CancelsImportAndLogs()
+ {
+ // Setup
+ var referenceLineFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO,
+ Path.Combine("ReferenceLine", "traject_1-1.shp"));
+ var sectionsFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO,
+ Path.Combine("FailureMechanismSections", "traject_1-1_vakken.shp"));
+
+ ReferenceLine importReferenceLine = ImportReferenceLine(referenceLineFilePath);
+
+ var failureMechanism = new Simple();
+
+ var importer = new FailureMechanismSectionsImporter(failureMechanism, importReferenceLine, sectionsFilePath);
+ importer.SetProgressChanged((description, step, steps) =>
+ {
+ if (description.Contains("Inlezen vakindeling."))
+ {
+ importer.Cancel();
+ }
+ });
+
+ bool importSuccessful = true;
+
+ // Call
+ Action call = () => importSuccessful = importer.Import();
+
+ // Assert
+ TestHelper.AssertLogMessageIsGenerated(call, "Vakindeling importeren afgebroken. Geen gegevens ingelezen.", 1);
+ Assert.IsFalse(importSuccessful);
+ CollectionAssert.IsEmpty(failureMechanism.Sections);
+
+ }
+
+ [Test]
+ public void Import_CancelOfImportWhenValidatingImportedections_CancelsImportAndLogs()
+ {
+ // Setup
+ var referenceLineFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO,
+ Path.Combine("ReferenceLine", "traject_1-1.shp"));
+ var sectionsFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO,
+ Path.Combine("FailureMechanismSections", "traject_1-1_vakken.shp"));
+
+ ReferenceLine importReferenceLine = ImportReferenceLine(referenceLineFilePath);
+
+ var failureMechanism = new Simple();
+
+ var importer = new FailureMechanismSectionsImporter(failureMechanism, importReferenceLine, sectionsFilePath);
+ importer.SetProgressChanged((description, step, steps) =>
+ {
+ if (description.Contains("Valideren ingelezen vakindeling."))
+ {
+ importer.Cancel();
+ }
+ });
+
+ bool importSuccessful = true;
+
+ // Call
+ Action call = () => importSuccessful = importer.Import();
+
+ // Assert
+ TestHelper.AssertLogMessageIsGenerated(call, "Vakindeling importeren afgebroken. Geen gegevens ingelezen.", 1);
+ Assert.IsFalse(importSuccessful);
+ CollectionAssert.IsEmpty(failureMechanism.Sections);
+ }
+
+ [Test]
+ public void Import_CancelOfImportWhenAddingDataToModel_ContinuesImportAndLogs()
+ {
+ // Setup
+ var referenceLineFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO,
+ Path.Combine("ReferenceLine", "traject_1-1.shp"));
+ var sectionsFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO,
+ Path.Combine("FailureMechanismSections", "traject_1-1_vakken.shp"));
+
+ ReferenceLine importReferenceLine = ImportReferenceLine(referenceLineFilePath);
+
+ var failureMechanism = new Simple();
+
+ var importer = new FailureMechanismSectionsImporter(failureMechanism, importReferenceLine, sectionsFilePath);
+ importer.SetProgressChanged((description, step, steps) =>
+ {
+ if (description.Contains("Geïmporteerde gegevens toevoegen aan het toetsspoor."))
+ {
+ importer.Cancel();
+ }
+ });
+
+ bool importSuccessful = true;
+
+ // Call
+ Action call = () => importSuccessful = importer.Import();
+
+ // Assert
+ TestHelper.AssertLogMessageIsGenerated(call, "Huidige actie was niet meer te annuleren en is daarom voortgezet.", 1);
+ Assert.IsTrue(importSuccessful);
+ CollectionAssert.IsNotEmpty(failureMechanism.Sections);
+ }
+
+ [Test]
public void Import_ValidFileImportBeingCancelled_CancelImportWithInfoMessage()
{
// Setup
@@ -442,9 +542,10 @@
var failureMechanism = new Simple();
var importer = new FailureMechanismSectionsImporter(failureMechanism, importReferenceLine, sectionsFilePath);
+ importer.SetProgressChanged((description, step, steps) => importer.Cancel());
- importer.Cancel();
Assert.IsFalse(importer.Import());
+ importer.SetProgressChanged(null);
// Call
var importSuccessful = importer.Import();
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/FileImporters/ForeshoreProfilesImporterTest.cs
===================================================================
diff -u -r01d327694595b1acb77a9b0532a0d5bb91c9eadb -r3c17d0ec1a154f1c5a19601fd8885366a01b2daa
--- Ringtoets/Common/test/Ringtoets.Common.IO.Test/FileImporters/ForeshoreProfilesImporterTest.cs (.../ForeshoreProfilesImporterTest.cs) (revision 01d327694595b1acb77a9b0532a0d5bb91c9eadb)
+++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/FileImporters/ForeshoreProfilesImporterTest.cs (.../ForeshoreProfilesImporterTest.cs) (revision 3c17d0ec1a154f1c5a19601fd8885366a01b2daa)
@@ -315,7 +315,7 @@
}
[Test]
- public void Import_CancelOfImportToValidTargetWithValidFile_CancelImportAndLog()
+ public void Import_CancelOfImporWhileReadingProfileLocations_CancelsImportAndLogs()
{
// Setup
string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO,
@@ -328,21 +328,59 @@
var foreshoreProfiles = new ObservableList();
var foreshoreProfilesImporter = new ForeshoreProfilesImporter(foreshoreProfiles, referenceLine, filePath);
+ foreshoreProfilesImporter.SetProgressChanged((description, step, steps) =>
+ {
+ if (description.Contains("Inlezen van profiellocaties uit een shapebestand."))
+ {
+ foreshoreProfilesImporter.Cancel();
+ }
+ });
- // Precondition
- foreshoreProfilesImporter.Cancel();
+ bool importResult = true;
// Call
- var importResult = true;
Action call = () => importResult = foreshoreProfilesImporter.Import();
// Assert
TestHelper.AssertLogMessageIsGenerated(call, "Voorlandprofielen importeren is afgebroken. Geen gegevens ingelezen.", 1);
Assert.IsFalse(importResult);
- mockRepository.VerifyAll(); // 'observer' should not be notified
+ mockRepository.VerifyAll();
}
[Test]
+ public void Import_CancelOfImporWhileReadingDikeProfileData_CancelsImportAndLogs()
+ {
+ // Setup
+ string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO,
+ Path.Combine("DikeProfiles", "AllOkTestData", "Voorlanden 12-2.shp"));
+
+ ReferenceLine referenceLine = CreateMatchingReferenceLine();
+ var assessmentSection = mockRepository.Stub();
+ assessmentSection.ReferenceLine = referenceLine;
+ mockRepository.ReplayAll();
+
+ var foreshoreProfiles = new ObservableList();
+ var foreshoreProfilesImporter = new ForeshoreProfilesImporter(foreshoreProfiles, referenceLine, filePath);
+ foreshoreProfilesImporter.SetProgressChanged((description, step, steps) =>
+ {
+ if (description.Contains("Inlezen van profielgegevens uit een prfl bestand."))
+ {
+ foreshoreProfilesImporter.Cancel();
+ }
+ });
+
+ bool importResult = true;
+
+ // Call
+ Action call = () => importResult = foreshoreProfilesImporter.Import();
+
+ // Assert
+ TestHelper.AssertLogMessageIsGenerated(call, "Voorlandprofielen importeren is afgebroken. Geen gegevens ingelezen.", 1);
+ Assert.IsFalse(importResult);
+ mockRepository.VerifyAll();
+ }
+
+ [Test]
public void Import_ReuseOfCancelledImportToValidTargetWithValidFile_TrueAndLogMessagesAndFiveForeshoreProfiles()
{
// Setup
@@ -356,18 +394,20 @@
var foreshoreProfiles = new ObservableList();
var foreshoreProfilesImporter = new ForeshoreProfilesImporter(foreshoreProfiles, referenceLine, filePath);
+ foreshoreProfilesImporter.SetProgressChanged((description, step, steps) => foreshoreProfilesImporter.Cancel());
- foreshoreProfilesImporter.Cancel();
bool importResult = foreshoreProfilesImporter.Import();
Assert.IsFalse(importResult);
+ CollectionAssert.IsEmpty(foreshoreProfiles);
+ foreshoreProfilesImporter.SetProgressChanged(null);
// Call
importResult = foreshoreProfilesImporter.Import();
// Assert
Assert.IsTrue(importResult);
Assert.AreEqual(5, foreshoreProfiles.Count);
- mockRepository.VerifyAll(); // 'observer' should not be notified
+ mockRepository.VerifyAll();
}
private ReferenceLine CreateMatchingReferenceLine()
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/FileImporters/ProfilesImporterTest.cs
===================================================================
diff -u -r3ef2233d45ec65453a83651716d5e3d5cf96ac4c -r3c17d0ec1a154f1c5a19601fd8885366a01b2daa
--- Ringtoets/Common/test/Ringtoets.Common.IO.Test/FileImporters/ProfilesImporterTest.cs (.../ProfilesImporterTest.cs) (revision 3ef2233d45ec65453a83651716d5e3d5cf96ac4c)
+++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/FileImporters/ProfilesImporterTest.cs (.../ProfilesImporterTest.cs) (revision 3c17d0ec1a154f1c5a19601fd8885366a01b2daa)
@@ -480,16 +480,51 @@
}
[Test]
- public void Import_CancelOfImportToValidTargetWithValidFile_CancelImport()
+ public void Import_CancelOfImportWhileReadingProfileLocations_CancelsImportAndLogs()
{
// Setup
string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Integration.Plugin,
Path.Combine("DikeProfiles", "AllOkTestData", "Voorlanden 12-2.shp"));
var testProfilesImporter = new TestProfilesImporter(testImportTarget, testReferenceLine, filePath);
+ testProfilesImporter.SetProgressChanged((description, step, steps) =>
+ {
+ if (description.Contains("Inlezen van profiellocaties uit een shapebestand."))
+ {
+ testProfilesImporter.Cancel();
+ }
+ });
- testProfilesImporter.Cancel();
+ // Call
+ bool importResult = testProfilesImporter.Import();
+ // Assert
+ Assert.IsFalse(importResult);
+ }
+
+ [Test]
+ public void Import_CancelOfImportWhileReadingDikeProfileLocations_CancelsImportAndLogs()
+ {
+ // Setup
+ string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Integration.Plugin,
+ Path.Combine("DikeProfiles", "AllOkTestData", "Voorlanden 12-2.shp"));
+
+ ReferenceLine referenceLine = new ReferenceLine();
+ referenceLine.SetGeometry(new List
+ {
+ new Point2D(130074.3, 543717.4),
+ new Point2D(130084.3, 543727.4)
+ });
+
+ var testProfilesImporter = new TestProfilesImporter(testImportTarget, referenceLine, filePath);
+ testProfilesImporter.SetProgressChanged((description, step, steps) =>
+ {
+ if (description.Contains("Inlezen van profielgegevens uit een prfl bestand."))
+ {
+ testProfilesImporter.Cancel();
+ }
+ });
+
// Call
bool importResult = testProfilesImporter.Import();
@@ -512,12 +547,13 @@
ReferenceLine referenceLine = new ReferenceLine();
referenceLine.SetGeometry(referencePoints);
var testProfilesImporter = new TestProfilesImporter(new ObservableList(), referenceLine, filePath);
+ testProfilesImporter.SetProgressChanged((description, step, steps) => testProfilesImporter.Cancel());
- testProfilesImporter.Cancel();
bool importResult = testProfilesImporter.Import();
// Precondition
Assert.IsFalse(importResult);
+ testProfilesImporter.SetProgressChanged(null);
// Call
importResult = testProfilesImporter.Import();
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/FileImporters/StructuresImporterTest.cs
===================================================================
diff -u -r8dcb8c0fa8992c488bdea7d0631c84b7b1b09e61 -r3c17d0ec1a154f1c5a19601fd8885366a01b2daa
--- Ringtoets/Common/test/Ringtoets.Common.IO.Test/FileImporters/StructuresImporterTest.cs (.../StructuresImporterTest.cs) (revision 8dcb8c0fa8992c488bdea7d0631c84b7b1b09e61)
+++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/FileImporters/StructuresImporterTest.cs (.../StructuresImporterTest.cs) (revision 3c17d0ec1a154f1c5a19601fd8885366a01b2daa)
@@ -245,6 +245,82 @@
}
[Test]
+ public void Import_CancelOfImportWhenReadingLocations_CancelsImportAndLogs()
+ {
+ // Setup
+ string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO,
+ Path.Combine("Structures", "CorrectFiles", "Kunstwerken.shp"));
+
+ var referencePoints = new List
+ {
+ new Point2D(131144.094, 549979.893),
+ new Point2D(131538.705, 548316.752),
+ new Point2D(135878.442, 532149.859),
+ new Point2D(131225.017, 548395.948),
+ new Point2D(131270.38, 548367.462),
+ new Point2D(131507.119, 548322.951)
+ };
+ ReferenceLine referenceLine = new ReferenceLine();
+ referenceLine.SetGeometry(referencePoints);
+ var importTarget = new ObservableList();
+ var testStructuresImporter = new TestStructuresImporter(importTarget, referenceLine, filePath);
+ testStructuresImporter.SetProgressChanged((description, step, steps) =>
+ {
+ if (description.Contains("Inlezen van kunstwerklocaties uit een shapebestand."))
+ {
+ testStructuresImporter.Cancel();
+ }
+ });
+
+ bool importResult = true;
+
+ // Call
+ Action call = () => importResult = testStructuresImporter.Import();
+
+ // Assert
+ TestHelper.AssertLogMessageIsGenerated(call, "Kunstwerken importeren is afgebroken. Geen gegevens ingelezen.");
+ Assert.IsFalse(importResult);
+ }
+
+ [Test]
+ public void Import_CancelOfImportWhenReadingStructureData_ReturnsFalse()
+ {
+ // Setup
+ string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO,
+ Path.Combine("Structures", "CorrectFiles", "Kunstwerken.shp"));
+
+ var referencePoints = new List
+ {
+ new Point2D(131144.094, 549979.893),
+ new Point2D(131538.705, 548316.752),
+ new Point2D(135878.442, 532149.859),
+ new Point2D(131225.017, 548395.948),
+ new Point2D(131270.38, 548367.462),
+ new Point2D(131507.119, 548322.951)
+ };
+ ReferenceLine referenceLine = new ReferenceLine();
+ referenceLine.SetGeometry(referencePoints);
+ var importTarget = new ObservableList();
+ var testStructuresImporter = new TestStructuresImporter(importTarget, referenceLine, filePath);
+ testStructuresImporter.SetProgressChanged((description, step, steps) =>
+ {
+ if (description.Contains("Inlezen van kunstwerkgegevens uit een kommagescheiden bestand."))
+ {
+ testStructuresImporter.Cancel();
+ }
+ });
+
+ bool importResult = true;
+
+ // Call
+ Action call = () => importResult = testStructuresImporter.Import();
+
+ // Assert
+ TestHelper.AssertLogMessageIsGenerated(call, "Kunstwerken importeren is afgebroken. Geen gegevens ingelezen.");
+ Assert.IsFalse(importResult);
+ }
+
+ [Test]
public void Import_ReuseOfCancelledImportToValidTargetWithValidFile_ReturnsTrue()
{
// Setup
@@ -264,12 +340,13 @@
referenceLine.SetGeometry(referencePoints);
var importTarget = new ObservableList();
var testStructuresImporter = new TestStructuresImporter(importTarget, referenceLine, filePath);
+ testStructuresImporter.SetProgressChanged((description, step, steps) => testStructuresImporter.Cancel());
- testStructuresImporter.Cancel();
bool importResult = testStructuresImporter.Import();
// Precondition
Assert.IsFalse(importResult);
+ testStructuresImporter.SetProgressChanged(null);
// Call
importResult = testStructuresImporter.Import();
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/ReferenceLines/ReferenceLineImporterTest.cs
===================================================================
diff -u -r54c7814db3c2403b6427afb131cd48acd496c396 -r3c17d0ec1a154f1c5a19601fd8885366a01b2daa
--- Ringtoets/Common/test/Ringtoets.Common.IO.Test/ReferenceLines/ReferenceLineImporterTest.cs (.../ReferenceLineImporterTest.cs) (revision 54c7814db3c2403b6427afb131cd48acd496c396)
+++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/ReferenceLines/ReferenceLineImporterTest.cs (.../ReferenceLineImporterTest.cs) (revision 3c17d0ec1a154f1c5a19601fd8885366a01b2daa)
@@ -238,7 +238,7 @@
[Test]
[TestCase(true)]
[TestCase(false)]
- public void Import_CancelImportDuringDialogInteraction_GenerateCancelledLogMessage(bool acceptRemovalOfReferenceLineDependentData)
+ public void Import_CancelImportDuringDialogInteraction_GenerateCancelledLogMessageAndReturnsFalse(bool acceptRemovalOfReferenceLineDependentData)
{
// Setup
var path = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, "traject_10-2.shp");
@@ -257,15 +257,92 @@
.Repeat.Never();
mocks.ReplayAll();
+ bool importResult = true;
+
// Call
- Action call = () => importer.Import();
+ Action call = () => importResult = importer.Import();
// Assert
TestHelper.AssertLogMessageIsGenerated(call, "Referentielijn importeren afgebroken. Geen data ingelezen.", 1);
+ Assert.IsFalse(importResult);
mocks.VerifyAll();
}
[Test]
+ public void Import_CancelImportDuringReadReferenceLine_CancelsImportAndLogs()
+ {
+ // Setup
+ var path = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, Path.Combine("ReferenceLine", "traject_10-2.shp"));
+ var originalReferenceLine = new ReferenceLine();
+
+ var mocks = new MockRepository();
+ var assessmentSection = mocks.Stub();
+ assessmentSection.ReferenceLine = originalReferenceLine;
+ var handler = mocks.Stub();
+ handler.Stub(h => h.ConfirmReplace())
+ .Return(true);
+ mocks.ReplayAll();
+
+ var importer = new ReferenceLineImporter(assessmentSection, handler, path);
+ importer.SetProgressChanged((description, step, steps) =>
+ {
+ if (description.Contains("Inlezen referentielijn."))
+ {
+ importer.Cancel();
+ }
+ });
+
+ bool importResult = true;
+
+ // Call
+ Action call = () => importResult = importer.Import();
+
+ // Assert
+ TestHelper.AssertLogMessageIsGenerated(call, "Referentielijn importeren afgebroken. Geen data ingelezen.", 1);
+ Assert.IsFalse(importResult);
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void Import_CancelImportDuringAddReferenceLineToData_ContinuesImportAndLogs()
+ {
+ // Setup
+ var path = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, Path.Combine("ReferenceLine", "traject_10-2.shp"));
+ var originalReferenceLine = new ReferenceLine();
+
+ var mocks = new MockRepository();
+ var assessmentSection = mocks.Stub();
+ assessmentSection.ReferenceLine = originalReferenceLine;
+ var handler = mocks.Stub();
+ handler.Stub(h => h.ConfirmReplace())
+ .Return(true);
+ handler.Stub(h => h.Replace(Arg.Is.Same(assessmentSection),
+ Arg.Is.NotNull))
+ .Return(Enumerable.Empty());
+ mocks.ReplayAll();
+
+ var importer = new ReferenceLineImporter(assessmentSection, handler, path);
+ importer.SetProgressChanged((description, step, steps) =>
+ {
+ if (description.Contains("Geïmporteerde data toevoegen aan het traject."))
+ {
+ importer.Cancel();
+ }
+ });
+
+ bool importResult = true;
+
+ // Call
+ importer.Import();
+ Action call = () => importResult = importer.Import();
+
+ // Assert
+ TestHelper.AssertLogMessageIsGenerated(call, "Huidige actie was niet meer te annuleren en is daarom voortgezet.", 1);
+ Assert.IsTrue(importResult);
+ mocks.VerifyAll();
+ }
+
+ [Test]
public void Import_ReusingCancelledImporterForContextWithoutReferenceLine_ImportReferenceLineToAssessmentSection()
{
// Setup
@@ -291,11 +368,16 @@
Path.Combine("ReferenceLine", "traject_10-2.shp"));
var importer = new ReferenceLineImporter(assessmentSection, handler, path);
- importer.Cancel();
+ importer.SetProgressChanged((description, step, steps) => importer.Cancel());
- // Call
+ // Pre-condition
bool importSuccesful = importer.Import();
+ Assert.IsFalse(importSuccesful);
+ importer.SetProgressChanged(null);
+ // Call
+ importSuccesful = importer.Import();
+
// Assert
Assert.IsTrue(importSuccesful);
mocks.VerifyAll();
Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/HeightStructuresImporter.cs
===================================================================
diff -u -r7e24cbef3a5a475fef4442be00ced9e5305e0b24 -r3c17d0ec1a154f1c5a19601fd8885366a01b2daa
--- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/HeightStructuresImporter.cs (.../HeightStructuresImporter.cs) (revision 7e24cbef3a5a475fef4442be00ced9e5305e0b24)
+++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/HeightStructuresImporter.cs (.../HeightStructuresImporter.cs) (revision 3c17d0ec1a154f1c5a19601fd8885366a01b2daa)
@@ -60,12 +60,6 @@
}
}
- protected override void HandleUserCancellingImport()
- {
- Log.Info(RingtoetsCommonIOResources.StructuresImporter_User_cancelled);
- base.HandleUserCancellingImport();
- }
-
private IEnumerable CreateHeightStructures(IList structureLocations,
Dictionary> groupedStructureParameterRows)
{
Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSoilProfilesImporter.cs
===================================================================
diff -u -r0df7cded06f5afbac08b97e025242ba55c90ec57 -r3c17d0ec1a154f1c5a19601fd8885366a01b2daa
--- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSoilProfilesImporter.cs (.../PipingSoilProfilesImporter.cs) (revision 0df7cded06f5afbac08b97e025242ba55c90ec57)
+++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSoilProfilesImporter.cs (.../PipingSoilProfilesImporter.cs) (revision 3c17d0ec1a154f1c5a19601fd8885366a01b2daa)
@@ -32,7 +32,6 @@
using Ringtoets.Piping.IO.Exceptions;
using Ringtoets.Piping.IO.SoilProfile;
using Ringtoets.Piping.Primitives;
-using PipingFormsResources = Ringtoets.Piping.Forms.Properties.Resources;
using RingtoetsPluginResources = Ringtoets.Piping.Plugin.Properties.Resources;
namespace Ringtoets.Piping.Plugin.FileImporter
@@ -52,46 +51,36 @@
/// Thrown when is null .
public PipingSoilProfilesImporter(ObservableList importTarget, string filePath) : base(filePath, importTarget) {}
- public override bool Import()
+ protected override bool OnImport()
{
var importSoilProfileResult = ReadSoilProfiles();
- if (importSoilProfileResult.CriticalErrorOccurred)
+ if (importSoilProfileResult.CriticalErrorOccurred || Canceled)
{
return false;
}
- if (Canceled)
- {
- HandleUserCancellingImport();
- return false;
- }
-
var importStochasticSoilModelResult = ReadStochasticSoilModels();
- if (importStochasticSoilModelResult.CriticalErrorOccurred)
+ if (importStochasticSoilModelResult.CriticalErrorOccurred || Canceled)
{
return false;
}
- if (Canceled)
- {
- HandleUserCancellingImport();
- return false;
- }
-
AddSoilProfilesToStochasticSoilModels(importSoilProfileResult.ImportedItems, importStochasticSoilModelResult.ImportedItems);
-
CheckIfAllProfilesAreUsed(importSoilProfileResult.ImportedItems, importStochasticSoilModelResult.ImportedItems);
-
if (Canceled)
{
- HandleUserCancellingImport();
return false;
}
AddImportedDataToModel(importStochasticSoilModelResult.ImportedItems);
return true;
}
+ protected override void LogImportCanceledMessage()
+ {
+ log.Info(RingtoetsPluginResources.PipingSoilProfilesImporter_Import_Import_cancelled);
+ }
+
private void AddSoilProfilesToStochasticSoilModels(ICollection soilProfiles, ICollection stochasticSoilModels)
{
foreach (var stochasticSoilModel in stochasticSoilModels)
@@ -178,13 +167,6 @@
log.Error(message);
}
- private void HandleUserCancellingImport()
- {
- log.Info(RingtoetsPluginResources.PipingSoilProfilesImporter_Import_Import_cancelled);
-
- Canceled = false;
- }
-
#region read stochastic soil models
private ReadResult ReadStochasticSoilModels()
Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSurfaceLinesCsvImporter.cs
===================================================================
diff -u -r54c7814db3c2403b6427afb131cd48acd496c396 -r3c17d0ec1a154f1c5a19601fd8885366a01b2daa
--- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSurfaceLinesCsvImporter.cs (.../PipingSurfaceLinesCsvImporter.cs) (revision 54c7814db3c2403b6427afb131cd48acd496c396)
+++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSurfaceLinesCsvImporter.cs (.../PipingSurfaceLinesCsvImporter.cs) (revision 3c17d0ec1a154f1c5a19601fd8885366a01b2daa)
@@ -32,8 +32,6 @@
using Ringtoets.Common.Data.AssessmentSection;
using Ringtoets.Piping.IO.SurfaceLines;
using Ringtoets.Piping.Primitives;
-using PipingFormsResources = Ringtoets.Piping.Forms.Properties.Resources;
-using PipingDataResources = Ringtoets.Piping.Data.Properties.Resources;
using RingtoetsPluginResources = Ringtoets.Piping.Plugin.Properties.Resources;
namespace Ringtoets.Piping.Plugin.FileImporter
@@ -76,42 +74,29 @@
this.referenceLine = referenceLine;
}
- public override bool Import()
+ protected override bool OnImport()
{
var importSurfaceLinesResult = ReadPipingSurfaceLines();
- if (importSurfaceLinesResult.CriticalErrorOccurred)
+ if (importSurfaceLinesResult.CriticalErrorOccurred || Canceled)
{
return false;
}
- if (Canceled)
- {
- HandleUserCancellingImport();
- return false;
- }
-
var importCharacteristicPointsResult = ReadCharacteristicPoints();
- if (importCharacteristicPointsResult.CriticalErrorOccurred)
+ if (importCharacteristicPointsResult.CriticalErrorOccurred || Canceled)
{
return false;
}
- if (Canceled)
- {
- HandleUserCancellingImport();
- return false;
- }
-
AddImportedDataToModel(importSurfaceLinesResult.ImportedItems, importCharacteristicPointsResult.ImportedItems);
-
- if (Canceled)
- {
- Canceled = false; // Note: Adding imported data to the model cannot be canceled, so ignore any cancel request
- }
-
return true;
}
+ protected override void LogImportCanceledMessage()
+ {
+ log.Info(RingtoetsPluginResources.PipingSurfaceLinesCsvImporter_Import_Import_cancelled);
+ }
+
private ReadResult HandleCriticalReadError(Exception e)
{
log.ErrorFormat(RingtoetsPluginResources.PipingSurfaceLinesCsvImporter_CriticalErrorMessage_0_File_Skipped,
@@ -250,13 +235,6 @@
readSurfaceLine.TrySetDikeToeAtPolder(characteristicPointsLocation.DikeToeAtPolder);
}
- private void HandleUserCancellingImport()
- {
- log.Info(RingtoetsPluginResources.PipingSurfaceLinesCsvImporter_Import_Import_cancelled);
-
- Canceled = false;
- }
-
private class ReferenceLineIntersectionResult
{
private ReferenceLineIntersectionResult(ReferenceLineIntersectionsResult typeOfIntersection, Point2D intersectionPoint)
Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/PipingSoilProfilesImporterTest.cs
===================================================================
diff -u -r2aa9661130f20e88c41dac921ffb780573dcf799 -r3c17d0ec1a154f1c5a19601fd8885366a01b2daa
--- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/PipingSoilProfilesImporterTest.cs (.../PipingSoilProfilesImporterTest.cs) (revision 2aa9661130f20e88c41dac921ffb780573dcf799)
+++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/PipingSoilProfilesImporterTest.cs (.../PipingSoilProfilesImporterTest.cs) (revision 3c17d0ec1a154f1c5a19601fd8885366a01b2daa)
@@ -31,8 +31,6 @@
using Ringtoets.Piping.Data;
using Ringtoets.Piping.Plugin.FileImporter;
using Ringtoets.Piping.Primitives;
-using PipingFormsResources = Ringtoets.Piping.Forms.Properties.Resources;
-using RingtoetsFormsResources = Ringtoets.Common.Forms.Properties.Resources;
using ApplicationResources = Ringtoets.Piping.Plugin.Properties.Resources;
using RingtoetsIOResources = Ringtoets.Piping.IO.Properties.Resources;
@@ -212,58 +210,154 @@
}
[Test]
- public void Import_CancelOfImportToValidTargetWithValidFile_CancelImportAndLog()
+ public void Import_CancelOfImportWhenReadingSoilProfiles_CancelsImportAndLogs()
{
// Setup
string validFilePath = Path.Combine(testDataPath, "complete.soil");
var failureMechanism = new PipingFailureMechanism();
var importer = new PipingSoilProfilesImporter(failureMechanism.StochasticSoilModels, validFilePath);
- importer.SetProgressChanged(IncrementProgress);
+ importer.SetProgressChanged((description, step, steps) =>
+ {
+ if (description.Contains("Inlezen van de D-Soil Model database."))
+ {
+ importer.Cancel();
+ }
+ });
// Precondition
CollectionAssert.IsEmpty(failureMechanism.StochasticSoilModels);
Assert.IsTrue(File.Exists(validFilePath));
- importer.Cancel();
+ var importResult = true;
+ // Call
+ Action call = () => importResult = importer.Import();
+
+ // Assert
+ TestHelper.AssertLogMessageIsGenerated(call, "Stochastische ondergrondmodellen importeren afgebroken. Geen data ingelezen.", 1);
+ Assert.IsFalse(importResult);
+ CollectionAssert.IsEmpty(failureMechanism.StochasticSoilModels);
+ }
+
+ [Test]
+ public void Import_CancelOfImportWhenReadingStochasticSoilModels_CancelsImportAndLogs()
+ {
+ // Setup
+ string validFilePath = Path.Combine(testDataPath, "complete.soil");
+
+ var failureMechanism = new PipingFailureMechanism();
+ var importer = new PipingSoilProfilesImporter(failureMechanism.StochasticSoilModels, validFilePath);
+ importer.SetProgressChanged((description, step, steps) =>
+ {
+ if (description.Contains("Inlezen van de stochastische ondergrondmodellen."))
+ {
+ importer.Cancel();
+ }
+ });
+
+ // Precondition
+ CollectionAssert.IsEmpty(failureMechanism.StochasticSoilModels);
+ Assert.IsTrue(File.Exists(validFilePath));
+
var importResult = true;
// Call
Action call = () => importResult = importer.Import();
// Assert
- TestHelper.AssertLogMessageIsGenerated(call, ApplicationResources.PipingSoilProfilesImporter_Import_Import_cancelled, 1);
+ TestHelper.AssertLogMessageIsGenerated(call, "Stochastische ondergrondmodellen importeren afgebroken. Geen data ingelezen.", 1);
Assert.IsFalse(importResult);
CollectionAssert.IsEmpty(failureMechanism.StochasticSoilModels);
- Assert.AreEqual(1, progress);
}
[Test]
+ public void Import_CancelOfImportWhenAddingAndCheckingSoilProfiles_CancelsImportAndLogs()
+ {
+ // Setup
+ string validFilePath = Path.Combine(testDataPath, "complete.soil");
+
+ var failureMechanism = new PipingFailureMechanism();
+ var importer = new PipingSoilProfilesImporter(failureMechanism.StochasticSoilModels, validFilePath);
+ importer.SetProgressChanged((description, step, steps) =>
+ {
+ if (description.Contains("Controleren van ondergrondschematisaties."))
+ {
+ importer.Cancel();
+ }
+ });
+
+ // Precondition
+ CollectionAssert.IsEmpty(failureMechanism.StochasticSoilModels);
+ Assert.IsTrue(File.Exists(validFilePath));
+
+ var importResult = true;
+
+ // Call
+ Action call = () => importResult = importer.Import();
+
+ // Assert
+ TestHelper.AssertLogMessageIsGenerated(call, "Stochastische ondergrondmodellen importeren afgebroken. Geen data ingelezen.", 1);
+ Assert.IsFalse(importResult);
+ CollectionAssert.IsEmpty(failureMechanism.StochasticSoilModels);
+ }
+
+ [Test]
+ public void Import_CancelOfImportWhenAddingDataToModel_CancelsImportAndLogs()
+ {
+ // Setup
+ string validFilePath = Path.Combine(testDataPath, "complete.soil");
+
+ var failureMechanism = new PipingFailureMechanism();
+ var importer = new PipingSoilProfilesImporter(failureMechanism.StochasticSoilModels, validFilePath);
+ importer.SetProgressChanged((description, step, steps) =>
+ {
+ if (description.Contains("Geïmporteerde data toevoegen aan toetsspoor."))
+ {
+ importer.Cancel();
+ }
+ });
+
+ // Precondition
+ CollectionAssert.IsEmpty(failureMechanism.StochasticSoilModels);
+ Assert.IsTrue(File.Exists(validFilePath));
+
+ var importResult = false;
+
+ // Call
+ Action call = () => importResult = importer.Import();
+
+ // Assert
+ TestHelper.AssertLogMessageIsGenerated(call, "Huidige actie was niet meer te annuleren en is daarom voortgezet.", 1);
+ Assert.IsTrue(importResult);
+ CollectionAssert.IsNotEmpty(failureMechanism.StochasticSoilModels);
+ }
+
+ [Test]
public void Import_ReuseOfCancelledImportToValidTargetWithValidFile_ImportSoilModelToCollection()
{
// Setup
string validFilePath = Path.Combine(testDataPath, "complete.soil");
var failureMechanism = new PipingFailureMechanism();
var importer = new PipingSoilProfilesImporter(failureMechanism.StochasticSoilModels, validFilePath);
- importer.SetProgressChanged(IncrementProgress);
+ importer.SetProgressChanged((description, step, steps) => importer.Cancel());
// Precondition
CollectionAssert.IsEmpty(failureMechanism.StochasticSoilModels);
Assert.IsTrue(File.Exists(validFilePath));
// Setup (second part)
- importer.Cancel();
- var importResult = importer.Import();
+ bool importResult = importer.Import();
Assert.IsFalse(importResult);
+ importer.SetProgressChanged(null);
// Call
importResult = importer.Import();
// Assert
Assert.IsTrue(importResult);
- Assert.AreEqual(36, progress);
+ CollectionAssert.IsNotEmpty(failureMechanism.StochasticSoilModels);
}
[Test]
Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/PipingSurfaceLinesCsvImporterTest.cs
===================================================================
diff -u -r49c5da81f49a23dd6e66526d264a08bf510e6963 -r3c17d0ec1a154f1c5a19601fd8885366a01b2daa
--- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/PipingSurfaceLinesCsvImporterTest.cs (.../PipingSurfaceLinesCsvImporterTest.cs) (revision 49c5da81f49a23dd6e66526d264a08bf510e6963)
+++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/PipingSurfaceLinesCsvImporterTest.cs (.../PipingSurfaceLinesCsvImporterTest.cs) (revision 3c17d0ec1a154f1c5a19601fd8885366a01b2daa)
@@ -33,7 +33,6 @@
using Ringtoets.Piping.Data;
using Ringtoets.Piping.Plugin.FileImporter;
using Ringtoets.Piping.Primitives;
-using PipingFormsResources = Ringtoets.Piping.Forms.Properties.Resources;
using PipingIOResources = Ringtoets.Piping.IO.Properties.Resources;
using PipingDataResources = Ringtoets.Piping.Data.Properties.Resources;
using PipingPluginResources = Ringtoets.Piping.Plugin.Properties.Resources;
@@ -211,7 +210,7 @@
}
[Test]
- public void Import_CancelOfImportToValidTargetWithValidFile_CancelImportAndLog()
+ public void Import_CancelOfImportWhenReadingPipingSurfaceLines_CancelsImportAndLogs()
{
// Setup
string validFilePath = Path.Combine(ioTestDataPath, "TwoValidSurfaceLines.csv");
@@ -220,25 +219,104 @@
var failureMechanism = new PipingFailureMechanism();
var importer = new PipingSurfaceLinesCsvImporter(failureMechanism.SurfaceLines, referenceLine, validFilePath);
+ importer.SetProgressChanged(delegate(string description, int step, int steps)
+ {
+ if (description.Contains("Inlezen van het profielschematisatiesbestand."))
+ {
+ importer.Cancel();
+ }
+ });
// Precondition
CollectionAssert.IsEmpty(failureMechanism.SurfaceLines);
Assert.IsTrue(File.Exists(validFilePath));
- importer.Cancel();
+ bool importResult = true;
+ // Call
+ Action call = () => importResult = importer.Import();
+
+ // Assert
+ TestHelper.AssertLogMessageIsGenerated(call, "Profielschematisaties importeren afgebroken. Geen data ingelezen.", 3);
+ Assert.IsFalse(importResult);
+ CollectionAssert.IsEmpty(failureMechanism.SurfaceLines);
+ }
+
+ [Test]
+ public void Import_CancelOfImportWhenReadingCharacteristicPoints_CancelsImportAndLogs()
+ {
+ // Setup
+ string validFilePath = Path.Combine(ioTestDataPath, "TwoValidSurfaceLines.csv");
+
+ var referenceLine = new ReferenceLine();
+ var failureMechanism = new PipingFailureMechanism();
+
+ var importer = new PipingSurfaceLinesCsvImporter(failureMechanism.SurfaceLines, referenceLine, validFilePath);
+ importer.SetProgressChanged((description, step, steps) =>
+ {
+ if (description.Contains("Inlezen van het karakteristieke punten-bestand."))
+ {
+ importer.Cancel();
+ }
+ });
+
+ // Precondition
+ CollectionAssert.IsEmpty(failureMechanism.SurfaceLines);
+ Assert.IsTrue(File.Exists(validFilePath));
+
bool importResult = true;
// Call
Action call = () => importResult = importer.Import();
// Assert
- TestHelper.AssertLogMessageIsGenerated(call, PipingPluginResources.PipingSurfaceLinesCsvImporter_Import_Import_cancelled, 3);
+ TestHelper.AssertLogMessageIsGenerated(call, "Profielschematisaties importeren afgebroken. Geen data ingelezen.", 4);
Assert.IsFalse(importResult);
CollectionAssert.IsEmpty(failureMechanism.SurfaceLines);
}
[Test]
+ public void Import_CancelOfImportWhenAddingDataToModel_ContinuesImportAndLogs()
+ {
+ // Setup
+ string validFilePath = Path.Combine(ioTestDataPath, "TwoValidSurfaceLines.csv");
+
+ var referenceLine = new ReferenceLine();
+ referenceLine.SetGeometry(new[]
+ {
+ new Point2D(3.3, -1),
+ new Point2D(3.3, 1),
+ new Point2D(94270, 427775.65),
+ new Point2D(94270, 427812.08)
+ });
+
+ var failureMechanism = new PipingFailureMechanism();
+
+ var importer = new PipingSurfaceLinesCsvImporter(failureMechanism.SurfaceLines, referenceLine, validFilePath);
+ importer.SetProgressChanged((description, step, steps) =>
+ {
+ if (description.Contains("Geïmporteerde data toevoegen aan toetsspoor."))
+ {
+ importer.Cancel();
+ }
+ });
+
+ // Precondition
+ CollectionAssert.IsEmpty(failureMechanism.SurfaceLines);
+ Assert.IsTrue(File.Exists(validFilePath));
+
+ bool importResult = false;
+
+ // Call
+ Action call = () => importResult = importer.Import();
+
+ // Assert
+ TestHelper.AssertLogMessageIsGenerated(call, "Huidige actie was niet meer te annuleren en is daarom voortgezet.", 6);
+ Assert.IsTrue(importResult);
+ CollectionAssert.IsNotEmpty(failureMechanism.SurfaceLines);
+ }
+
+ [Test]
public void Import_ReuseOfCancelledImportToValidTargetWithValidFile_ImportSurfaceLinesToCollection()
{
// Setup
@@ -257,14 +335,15 @@
var failureMechanism = new PipingFailureMechanism();
var importer = new PipingSurfaceLinesCsvImporter(failureMechanism.SurfaceLines, referenceLine, validFilePath);
+ importer.SetProgressChanged((description, step, steps) => importer.Cancel());
// Precondition
CollectionAssert.IsEmpty(failureMechanism.SurfaceLines);
Assert.IsTrue(File.Exists(validFilePath));
// Setup (second part)
- importer.Cancel();
var importResult = importer.Import();
+ importer.SetProgressChanged(null);
Assert.IsFalse(importResult);
// Call
@@ -658,33 +737,6 @@
}
[Test]
- public void Import_CancelOfImportWithCharacteristicPointsAfterSurfaceLinesRead_CancelImportAndLog()
- {
- // Setup
- string validFilePath = Path.Combine(ioTestDataPath, "TwoValidSurfaceLines.csv");
-
- var failureMechanism = new PipingFailureMechanism();
-
- var importer = new PipingSurfaceLinesCsvImporter(failureMechanism.SurfaceLines, new ReferenceLine(), validFilePath);
-
- // Precondition
- CollectionAssert.IsEmpty(failureMechanism.SurfaceLines);
- Assert.IsTrue(File.Exists(validFilePath));
-
- importer.Cancel();
-
- var importResult = true;
-
- // Call
- Action call = () => importResult = importer.Import();
-
- // Assert
- TestHelper.AssertLogMessageIsGenerated(call, PipingPluginResources.PipingSurfaceLinesCsvImporter_Import_Import_cancelled, 3);
- Assert.IsFalse(importResult);
- CollectionAssert.IsEmpty(failureMechanism.SurfaceLines);
- }
-
- [Test]
public void Import_CharacteristicPointsFileDoesNotExist_Log()
{
// Setup
Index: Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.IO/StabilityPointStructuresImporter.cs
===================================================================
diff -u -r7e24cbef3a5a475fef4442be00ced9e5305e0b24 -r3c17d0ec1a154f1c5a19601fd8885366a01b2daa
--- Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.IO/StabilityPointStructuresImporter.cs (.../StabilityPointStructuresImporter.cs) (revision 7e24cbef3a5a475fef4442be00ced9e5305e0b24)
+++ Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.IO/StabilityPointStructuresImporter.cs (.../StabilityPointStructuresImporter.cs) (revision 3c17d0ec1a154f1c5a19601fd8885366a01b2daa)
@@ -60,12 +60,6 @@
}
}
- protected override void HandleUserCancellingImport()
- {
- Log.Info(RingtoetsCommonIOResources.StructuresImporter_User_cancelled);
- base.HandleUserCancellingImport();
- }
-
private IEnumerable CreateStabilityPointStructures(IList structureLocations,
Dictionary> groupedStructureParameterRows)
{