Index: Core/Common/src/Core.Common.Base/Plugin/ApplicationCore.cs
===================================================================
diff -u -r8d674ed53ab6a7a21d2673c525b93e501a0def88 -raf42240385db3d3f04bca830513c7464e6f74668
--- Core/Common/src/Core.Common.Base/Plugin/ApplicationCore.cs (.../ApplicationCore.cs) (revision 8d674ed53ab6a7a21d2673c525b93e501a0def88)
+++ Core/Common/src/Core.Common.Base/Plugin/ApplicationCore.cs (.../ApplicationCore.cs) (revision af42240385db3d3f04bca830513c7464e6f74668)
@@ -62,22 +62,6 @@
}
///
- /// This method returns an enumeration of that support the .
- ///
- /// The target to get the enumeration of supported for.
- /// The enumeration of supported .
- public IEnumerable GetSupportedFileImporters(object target)
- {
- if (target == null)
- {
- return Enumerable.Empty();
- }
-
- return plugins.SelectMany(plugin => plugin.GetFileImporters())
- .Where(fileImporter => fileImporter.CanImportOn(target));
- }
-
- ///
/// This method returns an enumeration of that support the .
///
/// The source to get the enumeration of supported for.
Index: Core/Common/src/Core.Common.Base/Plugin/ApplicationPlugin.cs
===================================================================
diff -u -r8d674ed53ab6a7a21d2673c525b93e501a0def88 -raf42240385db3d3f04bca830513c7464e6f74668
--- Core/Common/src/Core.Common.Base/Plugin/ApplicationPlugin.cs (.../ApplicationPlugin.cs) (revision 8d674ed53ab6a7a21d2673c525b93e501a0def88)
+++ Core/Common/src/Core.Common.Base/Plugin/ApplicationPlugin.cs (.../ApplicationPlugin.cs) (revision af42240385db3d3f04bca830513c7464e6f74668)
@@ -30,15 +30,6 @@
public abstract class ApplicationPlugin
{
///
- /// This method returns an enumeration of .
- ///
- /// The enumeration of provided by the .
- public virtual IEnumerable GetFileImporters()
- {
- yield break;
- }
-
- ///
/// This method returns an enumeration of .
///
/// The enumeration of provided by the .
Index: Core/Common/src/Core.Common.Gui/Commands/ExportImportCommandHandler.cs
===================================================================
diff -u -ref1c61d94f2aec3b4ff32fcf03253d7ad386c8e5 -raf42240385db3d3f04bca830513c7464e6f74668
--- Core/Common/src/Core.Common.Gui/Commands/ExportImportCommandHandler.cs (.../ExportImportCommandHandler.cs) (revision ef1c61d94f2aec3b4ff32fcf03253d7ad386c8e5)
+++ Core/Common/src/Core.Common.Gui/Commands/ExportImportCommandHandler.cs (.../ExportImportCommandHandler.cs) (revision af42240385db3d3f04bca830513c7464e6f74668)
@@ -20,13 +20,12 @@
// All rights reserved.
using System;
+using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
-
using Core.Common.Base.IO;
using Core.Common.Base.Plugin;
using Core.Common.Gui.Properties;
-
using log4net;
namespace Core.Common.Gui.Commands
@@ -39,7 +38,7 @@
private static readonly ILog log = LogManager.GetLogger(typeof(ExportImportCommandHandler));
private readonly ApplicationCore applicationCore;
-
+ private readonly IEnumerable fileImporters;
private readonly GuiImportHandler importHandler;
private readonly GuiExportHandler exportHandler;
@@ -48,16 +47,18 @@
///
/// The parent window onto which dialogs should be shown.
/// The host of all application plugins.
- public ExportImportCommandHandler(IWin32Window dialogParent, ApplicationCore applicationCore)
+ /// An enumeration of .
+ public ExportImportCommandHandler(IWin32Window dialogParent, ApplicationCore applicationCore, IEnumerable fileImporters)
{
this.applicationCore = applicationCore;
- importHandler = new GuiImportHandler(dialogParent, this.applicationCore);
+ this.fileImporters = fileImporters;
+ importHandler = new GuiImportHandler(dialogParent, this.fileImporters);
exportHandler = new GuiExportHandler(dialogParent, this.applicationCore);
}
- public bool CanImportOn(object obj)
+ public bool CanImportOn(object target)
{
- return applicationCore.GetSupportedFileImporters(obj).Any();
+ return fileImporters.Any(fileImporter => fileImporter.CanImportOn(target));
}
public void ImportOn(object target, IFileImporter importer = null)
Index: Core/Common/src/Core.Common.Gui/Commands/GuiImportHandler.cs
===================================================================
diff -u -rfa493fef4f3f244664392c28896afb2052596898 -raf42240385db3d3f04bca830513c7464e6f74668
--- Core/Common/src/Core.Common.Gui/Commands/GuiImportHandler.cs (.../GuiImportHandler.cs) (revision fa493fef4f3f244664392c28896afb2052596898)
+++ Core/Common/src/Core.Common.Gui/Commands/GuiImportHandler.cs (.../GuiImportHandler.cs) (revision af42240385db3d3f04bca830513c7464e6f74668)
@@ -19,16 +19,14 @@
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
+using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
-
using Core.Common.Base.IO;
-using Core.Common.Base.Plugin;
using Core.Common.Base.Service;
using Core.Common.Gui.Forms;
using Core.Common.Gui.Forms.ProgressDialog;
using Core.Common.Gui.Properties;
-
using log4net;
namespace Core.Common.Gui.Commands
@@ -41,17 +39,17 @@
private static readonly ILog log = LogManager.GetLogger(typeof(GuiImportHandler));
private readonly IWin32Window dialogParent;
- private readonly ApplicationCore applicationCore;
+ private readonly IEnumerable fileImporters;
///
/// Initializes a new instance of the class.
///
/// The parent window to show dialogs on top.
- /// The application-plugins host.
- public GuiImportHandler(IWin32Window dialogParent, ApplicationCore applicationCore)
+ /// An enumeration of .
+ public GuiImportHandler(IWin32Window dialogParent, IEnumerable fileImporters)
{
this.dialogParent = dialogParent;
- this.applicationCore = applicationCore;
+ this.fileImporters = fileImporters;
}
///
@@ -78,8 +76,8 @@
private IFileImporter GetSupportedImporterForTargetType(object target)
{
- var importers = applicationCore.GetSupportedFileImporters(target).ToArray();
- if (importers.Length == 0)
+ var importers = fileImporters.Where(fileImporter => fileImporter.CanImportOn(target)).ToArray();
+ if (!importers.Any())
{
MessageBox.Show(Resources.GuiImportHandler_GetSupportedImporterForTargetType_No_importer_available_for_this_item,
Resources.GuiImportHandler_GetSupportedImporterForTargetType_Error);
Index: Core/Common/src/Core.Common.Gui/GuiCore.cs
===================================================================
diff -u -r276383b754de8eafea064dd780e118d922379d76 -raf42240385db3d3f04bca830513c7464e6f74668
--- Core/Common/src/Core.Common.Gui/GuiCore.cs (.../GuiCore.cs) (revision 276383b754de8eafea064dd780e118d922379d76)
+++ Core/Common/src/Core.Common.Gui/GuiCore.cs (.../GuiCore.cs) (revision af42240385db3d3f04bca830513c7464e6f74668)
@@ -122,7 +122,7 @@
viewCommandHandler = new ViewCommandHandler(this, this, this, this);
storageCommandHandler = new StorageCommandHandler(projectStore, this, this, this, this, viewCommandHandler);
- exportImportCommandHandler = new ExportImportCommandHandler(MainWindow, ApplicationCore);
+ exportImportCommandHandler = new ExportImportCommandHandler(MainWindow, ApplicationCore, Plugins.SelectMany(p => p.GetFileImporters()));
projectCommandHandler = new ProjectCommandHandler(this, MainWindow, ApplicationCore, this, this);
WindowsApplication.EnableVisualStyles();
@@ -462,6 +462,8 @@
InitializeGuiPlugins();
+
+
CopyDefaultViewsFromUserSettings();
//enable activation AFTER initialization
@@ -867,7 +869,7 @@
private ApplicationFeatureCommandHandler applicationFeatureCommands;
private readonly ViewCommandHandler viewCommandHandler;
private readonly ProjectCommandHandler projectCommandHandler;
- private readonly ExportImportCommandHandler exportImportCommandHandler;
+ private ExportImportCommandHandler exportImportCommandHandler;
private StorageCommandHandler storageCommandHandler;
public IApplicationFeatureCommands ApplicationCommands
Index: Core/Common/src/Core.Common.Gui/Plugin/GuiPlugin.cs
===================================================================
diff -u -r67980a5c3c5cb71c185278e849b123e7f92990eb -raf42240385db3d3f04bca830513c7464e6f74668
--- Core/Common/src/Core.Common.Gui/Plugin/GuiPlugin.cs (.../GuiPlugin.cs) (revision 67980a5c3c5cb71c185278e849b123e7f92990eb)
+++ Core/Common/src/Core.Common.Gui/Plugin/GuiPlugin.cs (.../GuiPlugin.cs) (revision af42240385db3d3f04bca830513c7464e6f74668)
@@ -22,7 +22,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
-
+using Core.Common.Base.IO;
using Core.Common.Controls.TreeView;
using Core.Common.Gui.Forms;
@@ -60,6 +60,15 @@
public virtual void Deactivate() {}
///
+ /// This method returns an enumeration of .
+ ///
+ /// The enumeration of provided by the .
+ public virtual IEnumerable GetFileImporters()
+ {
+ yield break;
+ }
+
+ ///
/// Returns all instances provided for data of this plugin.
///
public virtual IEnumerable GetPropertyInfos()
Index: Core/Common/test/Core.Common.Base.Test/Plugin/ApplicationCoreTest.cs
===================================================================
diff -u -r8d674ed53ab6a7a21d2673c525b93e501a0def88 -raf42240385db3d3f04bca830513c7464e6f74668
--- Core/Common/test/Core.Common.Base.Test/Plugin/ApplicationCoreTest.cs (.../ApplicationCoreTest.cs) (revision 8d674ed53ab6a7a21d2673c525b93e501a0def88)
+++ Core/Common/test/Core.Common.Base.Test/Plugin/ApplicationCoreTest.cs (.../ApplicationCoreTest.cs) (revision af42240385db3d3f04bca830513c7464e6f74668)
@@ -44,195 +44,6 @@
}
[Test]
- public void AddPlugin_SimpleApplicationPluginWithImporter_ShouldExposePluginDefinitions()
- {
- // Setup
- var targetItem = new object();
-
- var mocks = new MockRepository();
-
- var fileImporter = mocks.Stub();
- fileImporter.Stub(i => i.CanImportOn(targetItem)).Return(true);
-
- mocks.ReplayAll();
-
- var applicationCore = new ApplicationCore();
- var applicationPlugin = new SimpleApplicationPlugin
- {
- FileImporters = new[]
- {
- fileImporter
- }
- };
-
- // Call
- applicationCore.AddPlugin(applicationPlugin);
-
- // Assert
- IFileImporter[] supportedFileImporters = applicationCore.GetSupportedFileImporters(targetItem).ToArray();
- Assert.AreEqual(1, supportedFileImporters.Length);
- Assert.AreSame(fileImporter, supportedFileImporters[0]);
- }
-
- [Test]
- public void RemovePlugin_SimpleApplicationPluginWithImport_ShouldNoLongerExposePluginDefinitions()
- {
- // Setup
- var targetItem = new object();
-
- var mocks = new MockRepository();
-
- var fileImporter = mocks.Stub();
- fileImporter.Stub(i => i.CanImportOn(targetItem)).Return(true);
-
- mocks.ReplayAll();
-
- var applicationCore = new ApplicationCore();
- var applicationPlugin = new SimpleApplicationPlugin
- {
- FileImporters = new[]
- {
- fileImporter
- }
- };
-
- applicationCore.AddPlugin(applicationPlugin);
-
- // Preconditions
- Assert.AreEqual(1, applicationCore.GetSupportedFileImporters(targetItem).Count());
-
- // Call
- applicationCore.RemovePlugin(applicationPlugin);
-
- // Assert
- Assert.AreEqual(0, applicationCore.GetSupportedFileImporters(targetItem).Count());
- }
-
- [Test]
- public void GetSupportedFileImporters_SimpleApplicationPluginWithImportersAdded_ShouldOnlyProvideSupportedImporters()
- {
- // Setup
- var targetItem = new B();
-
- var supportedFileImporter1 = new SimpleFileImporter();
- var supportedFileImporter2 = new SimpleFileImporter();
- var unsupportedFileImporter = new SimpleFileImporter();
-
- var applicationCore = new ApplicationCore();
- var applicationPlugin = new SimpleApplicationPlugin
- {
- FileImporters = new IFileImporter[]
- {
- supportedFileImporter1,
- supportedFileImporter2,
- unsupportedFileImporter
- }
- };
-
- applicationCore.AddPlugin(applicationPlugin);
-
- // Call
- var supportedImporters = applicationCore.GetSupportedFileImporters(targetItem).ToArray();
-
- // Assert
- Assert.AreEqual(2, supportedImporters.Length);
- Assert.AreSame(supportedFileImporter1, supportedImporters[0]);
- Assert.AreSame(supportedFileImporter2, supportedImporters[1]);
- }
-
- [Test]
- public void GetSupportedFileImporters_SimpleApplicationPluginWithImportersAdded_ShouldProvideNoImportersWhenTargetEqualsNull()
- {
- // Setup
- var mocks = new MockRepository();
-
- var fileImporter = mocks.Stub();
- fileImporter.Stub(i => i.CanImportOn(Arg