Index: Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLines/ReferenceLineImporter.cs
===================================================================
diff -u -rf4efcc2bb58d597f4a19884d98d0ab79bab04b1c -r693cdb62ee142136d80bc08f36fa506fe9c64438
--- Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLines/ReferenceLineImporter.cs (.../ReferenceLineImporter.cs) (revision f4efcc2bb58d597f4a19884d98d0ab79bab04b1c)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLines/ReferenceLineImporter.cs (.../ReferenceLineImporter.cs) (revision 693cdb62ee142136d80bc08f36fa506fe9c64438)
@@ -50,7 +50,8 @@
/// The object responsible for replacing the
/// .
/// The path to the file to import from.
- /// Thrown when is null.
+ /// Thrown when
+ /// or is null.
public ReferenceLineImporter(IAssessmentSection importTarget,
IReferenceLineReplaceHandler replacementHandler,
string filePath)
Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/Importers/PipingConfigurationImporter.cs
===================================================================
diff -u
--- Ringtoets/Piping/src/Ringtoets.Piping.IO/Importers/PipingConfigurationImporter.cs (revision 0)
+++ Ringtoets/Piping/src/Ringtoets.Piping.IO/Importers/PipingConfigurationImporter.cs (revision 693cdb62ee142136d80bc08f36fa506fe9c64438)
@@ -0,0 +1,95 @@
+// Copyright (C) Stichting Deltares 2016. All rights reserved.
+//
+// This file is part of Ringtoets.
+//
+// Ringtoets is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+using System;
+using System.Linq;
+using Core.Common.Base.IO;
+using Core.Common.IO.Exceptions;
+using Core.Common.IO.Readers;
+using log4net;
+using Ringtoets.Common.Data.Calculation;
+using Ringtoets.Piping.IO.Properties;
+using Ringtoets.Piping.IO.Readers;
+
+namespace Ringtoets.Piping.IO.Importers
+{
+ ///
+ /// Imports a piping configuration and stores it on a .
+ ///
+ public class PipingConfigurationImporter : FileImporterBase
+ {
+ private static readonly ILog log = LogManager.GetLogger(typeof(PipingConfigurationImporter));
+
+ ///
+ /// Creates a new instance of .
+ ///
+ /// The path to the file to import from.
+ /// The calculation group to update.
+ /// Thrown when any parameter is null.
+ public PipingConfigurationImporter(string filePath, CalculationGroup importTarget)
+ : base(filePath, importTarget) {}
+
+ protected override void LogImportCanceledMessage()
+ {
+ log.Info(Resources.PipingConfigurationImporter_LogImportCanceledMessage_import_canceled_no_data_read);
+ }
+
+ protected override bool OnImport()
+ {
+ NotifyProgress("Inlezen berekening configuratie.", 1, 3);
+
+ ReadResult readResult = ReadConfiguration();
+ if (readResult.CriticalErrorOccurred || Canceled)
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ private ReadResult ReadConfiguration()
+ {
+ try
+ {
+ return new ReadResult(false)
+ {
+ ImportedItems = new PipingConfigurationReader(FilePath).Read().ToList()
+ };
+ }
+ catch (ArgumentException e)
+ {
+ return HandleCriticalFileReadError(e);
+ }
+ catch (CriticalFileReadException e)
+ {
+ return HandleCriticalFileReadError(e);
+ }
+ }
+
+ private static ReadResult HandleCriticalFileReadError(Exception e)
+ {
+ var errorMessage = string.Format(Resources.PipingConfigurationImporter_HandleCriticalFileReadError_Error_0_no_configuration_imported,
+ e.Message);
+ log.Error(errorMessage);
+ return new ReadResult(true);
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/Properties/Resources.Designer.cs
===================================================================
diff -u -raf27351920210528ed4f8e121bcca04f6400434d -r693cdb62ee142136d80bc08f36fa506fe9c64438
--- Ringtoets/Piping/src/Ringtoets.Piping.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision af27351920210528ed4f8e121bcca04f6400434d)
+++ Ringtoets/Piping/src/Ringtoets.Piping.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 693cdb62ee142136d80bc08f36fa506fe9c64438)
@@ -202,6 +202,27 @@
}
///
+ /// Looks up a localized string similar to {0}
+ ///Er is geen berekening configuratie geïmporteerd..
+ ///
+ public static string PipingConfigurationImporter_HandleCriticalFileReadError_Error_0_no_configuration_imported {
+ get {
+ return ResourceManager.GetString("PipingConfigurationImporter_HandleCriticalFileReadError_Error_0_no_configuration_" +
+ "imported", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Berekening configuratie importeren afgebroken. Geen data ingelezen..
+ ///
+ public static string PipingConfigurationImporter_LogImportCanceledMessage_import_canceled_no_data_read {
+ get {
+ return ResourceManager.GetString("PipingConfigurationImporter_LogImportCanceledMessage_import_canceled_no_data_read" +
+ "", resourceCulture);
+ }
+ }
+
+ ///
/// Looks up a localized string similar to Het XML-document dat de configuratie voor de berekeningen beschrijft is niet geldig..
///
public static string PipingConfigurationReader_Configuration_contains_no_valid_xml {
Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/Properties/Resources.resx
===================================================================
diff -u -raf27351920210528ed4f8e121bcca04f6400434d -r693cdb62ee142136d80bc08f36fa506fe9c64438
--- Ringtoets/Piping/src/Ringtoets.Piping.IO/Properties/Resources.resx (.../Resources.resx) (revision af27351920210528ed4f8e121bcca04f6400434d)
+++ Ringtoets/Piping/src/Ringtoets.Piping.IO/Properties/Resources.resx (.../Resources.resx) (revision 693cdb62ee142136d80bc08f36fa506fe9c64438)
@@ -266,4 +266,14 @@
{0} Er is geen configuratie geëxporteerd.
+
+ Berekening configuratie importeren afgebroken. Geen data ingelezen.
+
+
+ Berekening configuratie importeren afgebroken. Geen data ingelezen.
+
+
+ {0}
+Er is geen berekening configuratie geïmporteerd.
+
\ No newline at end of file
Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/Ringtoets.Piping.IO.csproj
===================================================================
diff -u -r92549be285a5082435e9625732cf33ff50cd60b9 -r693cdb62ee142136d80bc08f36fa506fe9c64438
--- Ringtoets/Piping/src/Ringtoets.Piping.IO/Ringtoets.Piping.IO.csproj (.../Ringtoets.Piping.IO.csproj) (revision 92549be285a5082435e9625732cf33ff50cd60b9)
+++ Ringtoets/Piping/src/Ringtoets.Piping.IO/Ringtoets.Piping.IO.csproj (.../Ringtoets.Piping.IO.csproj) (revision 693cdb62ee142136d80bc08f36fa506fe9c64438)
@@ -57,6 +57,7 @@
+
Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Importers/PipingConfigurationImporterTest.cs
===================================================================
diff -u
--- Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Importers/PipingConfigurationImporterTest.cs (revision 0)
+++ Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Importers/PipingConfigurationImporterTest.cs (revision 693cdb62ee142136d80bc08f36fa506fe9c64438)
@@ -0,0 +1,143 @@
+// Copyright (C) Stichting Deltares 2016. All rights reserved.
+//
+// This file is part of Ringtoets.
+//
+// Ringtoets is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+using System;
+using System.IO;
+using Core.Common.Base.IO;
+using Core.Common.TestUtil;
+using NUnit.Framework;
+using Ringtoets.Common.Data.Calculation;
+using Ringtoets.Piping.IO.Importers;
+
+namespace Ringtoets.Piping.IO.Test.Importers
+{
+ [TestFixture]
+ public class PipingConfigurationImporterTest
+ {
+ [Test]
+ public void Constructor_ExpectedValues()
+ {
+ // Call
+ var importer = new PipingConfigurationImporter("", new CalculationGroup());
+
+ // Assert
+ Assert.IsInstanceOf>(importer);
+ }
+
+ [Test]
+ public void Import_FilePathIsDirectory_CancelImportWithErrorMessage()
+ {
+ // Setup
+ string path = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Piping.IO, Path.DirectorySeparatorChar.ToString());
+
+ var importer = new PipingConfigurationImporter(path, new CalculationGroup());
+
+ // Call
+ bool importSuccesful = true;
+ Action call = () => importSuccesful = importer.Import();
+
+ // Assert
+ var expectedMessage = $"Fout bij het lezen van bestand '{path}': bestandspad mag niet verwijzen naar een lege bestandsnaam. " + Environment.NewLine +
+ "Er is geen berekening configuratie geïmporteerd.";
+ TestHelper.AssertLogMessageIsGenerated(call, expectedMessage, 1);
+ Assert.IsFalse(importSuccesful);
+ }
+
+ [Test]
+ public void Import_FileDoesNotExist_CancelImportWithErrorMessage()
+ {
+ // Setup
+ string path = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Piping.IO, "I_dont_exist");
+ var importer = new PipingConfigurationImporter(path, new CalculationGroup());
+
+ // Call
+ bool importSuccesful = true;
+ Action call = () => importSuccesful = importer.Import();
+
+ // Assert
+ var expectedMessage = $"Fout bij het lezen van bestand '{path}': het bestand bestaat niet. " + Environment.NewLine +
+ "Er is geen berekening configuratie geïmporteerd.";
+ TestHelper.AssertLogMessageIsGenerated(call, expectedMessage, 1);
+ Assert.IsFalse(importSuccesful);
+ }
+
+ [Test]
+ public void Import_CancelingImport_CancelImportAndLog()
+ {
+ // Setup
+ var calculationGroup = new CalculationGroup();
+
+ string path = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Piping.IO, Path.Combine("PipingConfigurationReader", "validConfiguration.xml"));
+ var importer = new PipingConfigurationImporter(path, calculationGroup);
+ importer.SetProgressChanged((description, step, steps) =>
+ {
+ importer.Cancel();
+ });
+
+ // Call
+ bool importSuccesful = true;
+ Action call = () => importSuccesful = importer.Import();
+
+ // Assert
+ TestHelper.AssertLogMessageIsGenerated(call, "Berekening configuratie importeren afgebroken. Geen data ingelezen.", 1);
+ CollectionAssert.IsEmpty(calculationGroup.Children);
+ Assert.IsFalse(importSuccesful);
+ }
+
+ [Test]
+ public void GivenImport_WhenImporting_ThenExpectedProgressMessagesGenerated()
+ {
+ // Given
+ string path = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Piping.IO, Path.Combine("PipingConfigurationReader", "validConfiguration.xml"));
+ var importer = new PipingConfigurationImporter(path, new CalculationGroup());
+
+ var expectedProgressMessages = new[]
+ {
+ new ExpectedProgressNotification
+ {
+ Text = "Inlezen berekening configuratie.", CurrentStep = 1, MaxNrOfSteps = 3
+ }
+ };
+
+ var progressChangedCallCount = 0;
+ importer.SetProgressChanged((description, step, steps) =>
+ {
+ Assert.AreEqual(expectedProgressMessages[progressChangedCallCount].Text, description);
+ Assert.AreEqual(expectedProgressMessages[progressChangedCallCount].CurrentStep, step);
+ Assert.AreEqual(expectedProgressMessages[progressChangedCallCount].MaxNrOfSteps, steps);
+ progressChangedCallCount++;
+ });
+
+ // When
+ importer.Import();
+
+ // Then
+ Assert.AreEqual(expectedProgressMessages.Length, progressChangedCallCount);
+ }
+
+ private class ExpectedProgressNotification
+ {
+ public string Text { get; set; }
+ public int CurrentStep { get; set; }
+ public int MaxNrOfSteps { get; set; }
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Ringtoets.Piping.IO.Test.csproj
===================================================================
diff -u -r36b1ab8fe4c395ade52f057cb2ce07960d04098c -r693cdb62ee142136d80bc08f36fa506fe9c64438
--- Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Ringtoets.Piping.IO.Test.csproj (.../Ringtoets.Piping.IO.Test.csproj) (revision 36b1ab8fe4c395ade52f057cb2ce07960d04098c)
+++ Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Ringtoets.Piping.IO.Test.csproj (.../Ringtoets.Piping.IO.Test.csproj) (revision 693cdb62ee142136d80bc08f36fa506fe9c64438)
@@ -74,6 +74,7 @@
+