Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/PipingPlugin.cs
===================================================================
diff -u -ra8557d0292f7cca077c69756d6b3511385da6c77 -r06d2a1e1525e818b3e71c4bcd61778e1ef4b2df7
--- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/PipingPlugin.cs (.../PipingPlugin.cs) (revision a8557d0292f7cca077c69756d6b3511385da6c77)
+++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/PipingPlugin.cs (.../PipingPlugin.cs) (revision 06d2a1e1525e818b3e71c4bcd61778e1ef4b2df7)
@@ -23,6 +23,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
+using System.IO;
using System.Linq;
using System.Windows.Forms;
using Core.Common.Base;
@@ -33,6 +34,7 @@
using Core.Common.Gui.Forms;
using Core.Common.Gui.Forms.ProgressDialog;
using Core.Common.Gui.Plugin;
+using log4net;
using Ringtoets.Common.Data.AssessmentSection;
using Ringtoets.Common.Data.Calculation;
using Ringtoets.Common.Data.FailureMechanism;
@@ -61,6 +63,8 @@
///
public class PipingPlugin : PluginBase
{
+ private readonly ILog log = LogManager.GetLogger(typeof(PipingPlugin));
+
public override IRibbonCommandHandler RibbonCommandHandler
{
get
@@ -515,22 +519,60 @@
private StrictContextMenuItem CreateUpdateStochasticSoilModelsItem(StochasticSoilModelCollection soilModelCollection, PipingFailureMechanism failureMechanism)
{
return new StrictContextMenuItem(
- "&Bijwerken...",
- "Werk de reeds bekende lijst van stochastische ondergrondmodellen bij.",
+ PipingPluginResources.PipingPlugin_UpdateStochasticSoilModelsMenuItem_Text,
+ PipingPluginResources.PipingPlugin_UpdateStochasticSoilModelsMenuItem_ToolTip,
PipingPluginResources.RefreshIcon,
- (sender, args) =>
- {
- var importer = new StochasticSoilModelImporter(soilModelCollection,
- soilModelCollection.SourcePath,
- new StochasticSoilModelUpdateData(failureMechanism));
- var activity = new FileImportActivity(importer, "Bijwerken van stochastische ondergrondmodellen.");
- ActivityProgressDialogRunner.Run(Gui.MainWindow, activity);
- })
+ (sender, args) => UpdateStochasticSoilModelFromKnownSourceFile(soilModelCollection, failureMechanism))
{
Enabled = soilModelCollection.SourcePath != null
};
}
+ private void UpdateStochasticSoilModelFromKnownSourceFile(StochasticSoilModelCollection soilModelCollection, PipingFailureMechanism failureMechanism)
+ {
+ string updateFromPath = soilModelCollection.SourcePath;
+ if (!File.Exists(updateFromPath))
+ {
+ updateFromPath = InquireUserForNewPath();
+ }
+
+ if (updateFromPath != null)
+ {
+ RunUpdateStochasticSoilModel(soilModelCollection, failureMechanism, updateFromPath);
+ }
+ else
+ {
+ log.Info(string.Format(
+ PipingPluginResources.PipingPlugin_UpdateStochasticSoilModels_Update_of_StochasticSoilModels_from_File_0_canceled_by_user,
+ soilModelCollection.SourcePath));
+ }
+ }
+
+ private string InquireUserForNewPath()
+ {
+ var openFileDialog = new OpenFileDialog
+ {
+ Multiselect = false,
+ Title = PipingPluginResources.PipingPlugin_UpdateStochasticSoilModelsFileDialog_Title,
+ Filter = $"{PipingPluginResources.Soil_file_name} (*.soil)|*.soil"
+ };
+ if (openFileDialog.ShowDialog(Gui.MainWindow) == DialogResult.OK)
+ {
+ return openFileDialog.FileName;
+ }
+ return null;
+ }
+
+ private void RunUpdateStochasticSoilModel(StochasticSoilModelCollection soilModelCollection, PipingFailureMechanism failureMechanism, string sourceFilePath)
+ {
+ var importer = new StochasticSoilModelImporter(soilModelCollection,
+ sourceFilePath,
+ new StochasticSoilModelUpdateData(failureMechanism));
+
+ var activity = new FileImportActivity(importer, PipingPluginResources.PipingPlugin_RunUpdateStochasticSoilModel_Update_StochasticSoilModels);
+ ActivityProgressDialogRunner.Run(Gui.MainWindow, activity);
+ }
+
#endregion
#region RingtoetsPipingSurfaceLine TreeNodeInfo
Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Properties/Resources.Designer.cs
===================================================================
diff -u -r673bf2f4f4de6006444aae3a10183f9442eb0f23 -r06d2a1e1525e818b3e71c4bcd61778e1ef4b2df7
--- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 673bf2f4f4de6006444aae3a10183f9442eb0f23)
+++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 06d2a1e1525e818b3e71c4bcd61778e1ef4b2df7)
@@ -82,6 +82,52 @@
}
///
+ /// Looks up a localized string similar to Bijwerken van stochastische ondergrondmodellen..
+ ///
+ public static string PipingPlugin_RunUpdateStochasticSoilModel_Update_StochasticSoilModels {
+ get {
+ return ResourceManager.GetString("PipingPlugin_RunUpdateStochasticSoilModel_Update_StochasticSoilModels", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Bijwerken van ondergrondschematisaties in '{0}' is door de gebruiker geannuleerd..
+ ///
+ public static string PipingPlugin_UpdateStochasticSoilModels_Update_of_StochasticSoilModels_from_File_0_canceled_by_user {
+ get {
+ return ResourceManager.GetString("PipingPlugin_UpdateStochasticSoilModels_Update_of_StochasticSoilModels_from_File_" +
+ "0_canceled_by_user", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Selecteer de nieuwe locatie van het geïmporteerde bestand.
+ ///
+ public static string PipingPlugin_UpdateStochasticSoilModelsFileDialog_Title {
+ get {
+ return ResourceManager.GetString("PipingPlugin_UpdateStochasticSoilModelsFileDialog_Title", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to &Bijwerken....
+ ///
+ public static string PipingPlugin_UpdateStochasticSoilModelsMenuItem_Text {
+ get {
+ return ResourceManager.GetString("PipingPlugin_UpdateStochasticSoilModelsMenuItem_Text", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Werk de reeds bekende lijst van stochastische ondergrondmodellen bij..
+ ///
+ public static string PipingPlugin_UpdateStochasticSoilModelsMenuItem_ToolTip {
+ get {
+ return ResourceManager.GetString("PipingPlugin_UpdateStochasticSoilModelsMenuItem_ToolTip", resourceCulture);
+ }
+ }
+
+ ///
/// Looks up a localized string similar to Het stochastische ondergrondmodel '{0}' bestaat al in het toetsspoor..
///
public static string PipingSoilProfilesImporter_AddImportedDataToModel_Stochastisch_soil_model_0_already_exists {
Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Properties/Resources.resx
===================================================================
diff -u -r673bf2f4f4de6006444aae3a10183f9442eb0f23 -r06d2a1e1525e818b3e71c4bcd61778e1ef4b2df7
--- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Properties/Resources.resx (.../Resources.resx) (revision 673bf2f4f4de6006444aae3a10183f9442eb0f23)
+++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Properties/Resources.resx (.../Resources.resx) (revision 06d2a1e1525e818b3e71c4bcd61778e1ef4b2df7)
@@ -237,4 +237,19 @@
..\Resources\table_refresh.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
+
+ Bijwerken van stochastische ondergrondmodellen.
+
+
+ Bijwerken van ondergrondschematisaties in '{0}' is door de gebruiker geannuleerd.
+
+
+ &Bijwerken...
+
+
+ Werk de reeds bekende lijst van stochastische ondergrondmodellen bij.
+
+
+ Selecteer de nieuwe locatie van het geïmporteerde bestand
+
\ No newline at end of file
Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/TreeNodeInfos/StochasticSoilModelCollectionContextTreeNodeInfoTest.cs
===================================================================
diff -u -r673bf2f4f4de6006444aae3a10183f9442eb0f23 -r06d2a1e1525e818b3e71c4bcd61778e1ef4b2df7
--- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/TreeNodeInfos/StochasticSoilModelCollectionContextTreeNodeInfoTest.cs (.../StochasticSoilModelCollectionContextTreeNodeInfoTest.cs) (revision 673bf2f4f4de6006444aae3a10183f9442eb0f23)
+++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/TreeNodeInfos/StochasticSoilModelCollectionContextTreeNodeInfoTest.cs (.../StochasticSoilModelCollectionContextTreeNodeInfoTest.cs) (revision 06d2a1e1525e818b3e71c4bcd61778e1ef4b2df7)
@@ -19,13 +19,21 @@
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
+using System;
using System.Collections.Generic;
using System.Drawing;
+using System.IO;
using System.Linq;
+using System.Threading;
+using System.Windows.Forms;
using Core.Common.Controls.TreeView;
using Core.Common.Gui;
+using Core.Common.Gui.Commands;
using Core.Common.Gui.ContextMenu;
+using Core.Common.Gui.Forms.MainWindow;
+using Core.Common.Gui.TestUtil.ContextMenu;
using Core.Common.TestUtil;
+using NUnit.Extensions.Forms;
using NUnit.Framework;
using Rhino.Mocks;
using Ringtoets.Common.Data.AssessmentSection;
@@ -34,12 +42,15 @@
using Ringtoets.Piping.Forms.Properties;
using Ringtoets.Piping.Primitives;
using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources;
+using RingtoetsPipingPluginResources = Ringtoets.Piping.Plugin.Properties.Resources;
namespace Ringtoets.Piping.Plugin.Test.TreeNodeInfos
{
[TestFixture]
- public class StochasticSoilModelCollectionContextTreeNodeInfoTest
+ public class StochasticSoilModelCollectionContextTreeNodeInfoTest : NUnitFormTest
{
+ private const int updateStochasticSoilModelsItemIndex = 1;
+
private MockRepository mocks;
private PipingPlugin plugin;
private TreeNodeInfo info;
@@ -252,12 +263,209 @@
plugin.Gui = gui;
-
// Call
info.ContextMenuStrip(context, null, treeViewControl);
}
// Assert
// Assert expectancies are called in TearDown()
}
+
+ [Test]
+ [TestCase(false)]
+ [TestCase(true)]
+ public void ContextMenuStrip_WithOrWithoutPathToSoilModelsSource_UpdateStochasticSoilModelsItemEnabledWhenPathSet(bool sourcePathSet)
+ {
+ // Setup
+ using (var treeViewControl = new TreeViewControl())
+ {
+ var pipingFailureMechanism = new PipingFailureMechanism();
+ var assessmentSectionMock = mocks.StrictMock();
+
+ var stochasticSoilModelCollection = new StochasticSoilModelCollection();
+ if (sourcePathSet)
+ {
+ stochasticSoilModelCollection.AddRange(Enumerable.Empty(), "some path");
+ }
+
+ var nodeData = new StochasticSoilModelCollectionContext(stochasticSoilModelCollection,
+ pipingFailureMechanism,
+ assessmentSectionMock);
+
+ var menuBuilder = new CustomItemsOnlyContextMenuBuilder();
+
+ var gui = mocks.StrictMock();
+ gui.Expect(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder);
+ gui.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub());
+
+ mocks.ReplayAll();
+
+ plugin.Gui = gui;
+
+ // Call
+ using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, null, treeViewControl))
+ {
+ // Assert
+ TestHelper.AssertContextMenuStripContainsItem(menu, updateStochasticSoilModelsItemIndex,
+ RingtoetsPipingPluginResources.PipingPlugin_UpdateStochasticSoilModelsMenuItem_Text,
+ RingtoetsPipingPluginResources.PipingPlugin_UpdateStochasticSoilModelsMenuItem_ToolTip,
+ RingtoetsPipingPluginResources.RefreshIcon,
+ sourcePathSet);
+ }
+ }
+ }
+
+ [Test]
+ [Apartment(ApartmentState.STA)]
+ public void ContextMenuStrip_ClickOnUpdateStochasticSoilModelsItemCancelClicked_OpenFileDialogShownCancelMessageLogged()
+ {
+ // Setup
+ const string somePath = "some path";
+ using (var treeViewControl = new TreeViewControl())
+ {
+ var pipingFailureMechanism = new PipingFailureMechanism();
+ var assessmentSectionMock = mocks.StrictMock();
+ var stochasticSoilModelCollection = new StochasticSoilModelCollection();
+ stochasticSoilModelCollection.AddRange(Enumerable.Empty(), somePath);
+
+ var nodeData = new StochasticSoilModelCollectionContext(stochasticSoilModelCollection,
+ pipingFailureMechanism,
+ assessmentSectionMock);
+
+ var menuBuilder = new CustomItemsOnlyContextMenuBuilder();
+
+ var gui = mocks.StrictMock();
+ gui.Expect(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder);
+ gui.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub());
+
+ var mainWindow = mocks.Stub();
+ gui.Expect(g => g.MainWindow).Return(mainWindow);
+
+ mocks.ReplayAll();
+
+ plugin.Gui = gui;
+
+ DialogBoxHandler = (name, wnd) =>
+ {
+ var window = new OpenFileDialogTester(wnd);
+ window.ClickCancel();
+ };
+
+ using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, null, treeViewControl))
+ {
+ // Call
+ Action test = () => menu.Items[updateStochasticSoilModelsItemIndex].PerformClick();
+
+ // Assert
+ TestHelper.AssertLogMessageIsGenerated(
+ test,
+ $"Bijwerken van ondergrondschematisaties in '{somePath}' is door de gebruiker geannuleerd.");
+ }
+ }
+ }
+
+ [Test]
+ [Apartment(ApartmentState.STA)]
+ public void ContextMenuStrip_ClickOnUpdateStochasticSoilModelsWithNonExistingSourceFilePathItemOkClicked_OpenFileDialogShownSuccessMessageLogged()
+ {
+ // Setup
+ const string somePath = "some path";
+ string testDirectory = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Piping.IO, "StochasticSoilModelDatabaseReader");
+ string existingFilePath = Path.Combine(testDirectory, "emptyschema.soil");
+
+ using (var treeViewControl = new TreeViewControl())
+ {
+ var pipingFailureMechanism = new PipingFailureMechanism();
+ var assessmentSectionMock = mocks.StrictMock();
+ var stochasticSoilModelCollection = new StochasticSoilModelCollection();
+ stochasticSoilModelCollection.AddRange(Enumerable.Empty(), somePath);
+
+ var nodeData = new StochasticSoilModelCollectionContext(stochasticSoilModelCollection,
+ pipingFailureMechanism,
+ assessmentSectionMock);
+
+ var menuBuilder = new CustomItemsOnlyContextMenuBuilder();
+
+ var gui = mocks.StrictMock();
+ gui.Expect(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder);
+ gui.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub());
+
+ var mainWindow = mocks.Stub();
+ gui.Stub(g => g.MainWindow).Return(mainWindow);
+
+ mocks.ReplayAll();
+
+ plugin.Gui = gui;
+
+ DialogBoxHandler = (name, wnd) =>
+ {
+ var window = new OpenFileDialogTester(wnd);
+ DialogBoxHandler = (s, hWnd) =>
+ {
+ };
+ window.OpenFile(existingFilePath);
+ };
+
+ using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, null, treeViewControl))
+ {
+ // Call
+ Action test = () => menu.Items[updateStochasticSoilModelsItemIndex].PerformClick();
+
+ // Assert
+ TestHelper.AssertLogMessageIsGenerated(
+ test,
+ "Uitvoeren van 'Bijwerken van stochastische ondergrondmodellen.' is gelukt.");
+ }
+ }
+ }
+
+ [Test]
+ [Apartment(ApartmentState.STA)]
+ public void ContextMenuStrip_ClickOnUpdateStochasticSoilModelsWithExistingSourceFilePath_SuccessMessageLogged()
+ {
+ // Setup
+ string testDirectory = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Piping.IO, "StochasticSoilModelDatabaseReader");
+ string existingFilePath = Path.Combine(testDirectory, "emptyschema.soil");
+
+ using (var treeViewControl = new TreeViewControl())
+ {
+ var pipingFailureMechanism = new PipingFailureMechanism();
+ var assessmentSectionMock = mocks.StrictMock();
+ var stochasticSoilModelCollection = new StochasticSoilModelCollection();
+ stochasticSoilModelCollection.AddRange(Enumerable.Empty(), existingFilePath);
+
+ var nodeData = new StochasticSoilModelCollectionContext(stochasticSoilModelCollection,
+ pipingFailureMechanism,
+ assessmentSectionMock);
+
+ var menuBuilder = new CustomItemsOnlyContextMenuBuilder();
+
+ var gui = mocks.StrictMock();
+ gui.Expect(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder);
+ gui.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub());
+
+ var mainWindow = mocks.Stub();
+ gui.Stub(g => g.MainWindow).Return(mainWindow);
+
+ mocks.ReplayAll();
+
+ plugin.Gui = gui;
+
+ DialogBoxHandler = (s, hWnd) =>
+ {
+ // Activity dialog closes by itself
+ };
+
+ using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, null, treeViewControl))
+ {
+ // Call
+ Action test = () => menu.Items[updateStochasticSoilModelsItemIndex].PerformClick();
+
+ // Assert
+ TestHelper.AssertLogMessageIsGenerated(
+ test,
+ "Uitvoeren van 'Bijwerken van stochastische ondergrondmodellen.' is gelukt.");
+ }
+ }
+ }
}
}
\ No newline at end of file