Index: Core/Common/src/Core.Common.Base/Plugin/ApplicationCore.cs =================================================================== diff -u -raf42240385db3d3f04bca830513c7464e6f74668 -r5b9a225deb21ddb302ddfd070154f61cd2d1b091 --- Core/Common/src/Core.Common.Base/Plugin/ApplicationCore.cs (.../ApplicationCore.cs) (revision af42240385db3d3f04bca830513c7464e6f74668) +++ Core/Common/src/Core.Common.Base/Plugin/ApplicationCore.cs (.../ApplicationCore.cs) (revision 5b9a225deb21ddb302ddfd070154f61cd2d1b091) @@ -23,8 +23,6 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; -using Core.Common.Base.IO; -using Core.Common.Utils.Reflection; namespace Core.Common.Base.Plugin { @@ -62,24 +60,6 @@ } /// - /// This method returns an enumeration of that support the . - /// - /// The source to get the enumeration of supported for. - /// The enumeration of supported . - public IEnumerable GetSupportedFileExporters(object source) - { - if (source == null) - { - return Enumerable.Empty(); - } - - var sourceType = source.GetType(); - - return plugins.SelectMany(plugin => plugin.GetFileExporters()) - .Where(fileExporter => (fileExporter.SupportedItemType == sourceType || sourceType.Implements(fileExporter.SupportedItemType))); - } - - /// /// This method returns an enumeration of that are supported for . /// /// The owner to get the enumeration of supported for. Index: Core/Common/src/Core.Common.Base/Plugin/ApplicationPlugin.cs =================================================================== diff -u -raf42240385db3d3f04bca830513c7464e6f74668 -r5b9a225deb21ddb302ddfd070154f61cd2d1b091 --- Core/Common/src/Core.Common.Base/Plugin/ApplicationPlugin.cs (.../ApplicationPlugin.cs) (revision af42240385db3d3f04bca830513c7464e6f74668) +++ Core/Common/src/Core.Common.Base/Plugin/ApplicationPlugin.cs (.../ApplicationPlugin.cs) (revision 5b9a225deb21ddb302ddfd070154f61cd2d1b091) @@ -25,20 +25,11 @@ namespace Core.Common.Base.Plugin { /// - /// Class that provides application plugin objects (file importers, file exporters and data items). + /// Class that provides application plugin objects (data items). /// public abstract class ApplicationPlugin { /// - /// This method returns an enumeration of . - /// - /// The enumeration of provided by the . - public virtual IEnumerable GetFileExporters() - { - 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 -raf42240385db3d3f04bca830513c7464e6f74668 -r5b9a225deb21ddb302ddfd070154f61cd2d1b091 --- Core/Common/src/Core.Common.Gui/Commands/ExportImportCommandHandler.cs (.../ExportImportCommandHandler.cs) (revision af42240385db3d3f04bca830513c7464e6f74668) +++ Core/Common/src/Core.Common.Gui/Commands/ExportImportCommandHandler.cs (.../ExportImportCommandHandler.cs) (revision 5b9a225deb21ddb302ddfd070154f61cd2d1b091) @@ -24,8 +24,8 @@ using System.Linq; using System.Windows.Forms; using Core.Common.Base.IO; -using Core.Common.Base.Plugin; using Core.Common.Gui.Properties; +using Core.Common.Utils.Reflection; using log4net; namespace Core.Common.Gui.Commands @@ -37,23 +37,23 @@ { private static readonly ILog log = LogManager.GetLogger(typeof(ExportImportCommandHandler)); - private readonly ApplicationCore applicationCore; private readonly IEnumerable fileImporters; + private readonly IEnumerable fileExporters; private readonly GuiImportHandler importHandler; private readonly GuiExportHandler exportHandler; /// /// Initializes a new instance of the class. /// /// The parent window onto which dialogs should be shown. - /// The host of all application plugins. /// An enumeration of . - public ExportImportCommandHandler(IWin32Window dialogParent, ApplicationCore applicationCore, IEnumerable fileImporters) + /// An enumeration of . + public ExportImportCommandHandler(IWin32Window dialogParent, IEnumerable fileImporters, IEnumerable fileExporters) { - this.applicationCore = applicationCore; this.fileImporters = fileImporters; + this.fileExporters = fileExporters; importHandler = new GuiImportHandler(dialogParent, this.fileImporters); - exportHandler = new GuiExportHandler(dialogParent, this.applicationCore); + exportHandler = new GuiExportHandler(dialogParent, this.fileExporters); } public bool CanImportOn(object target) @@ -82,7 +82,7 @@ public bool CanExportFrom(object obj) { - return applicationCore.GetSupportedFileExporters(obj).Any(); + return GetSupportedFileExporters(obj).Any(); } public void ExportFrom(object data, IFileExporter exporter = null) @@ -96,5 +96,17 @@ exportHandler.GetExporterDialog(exporter, data); } } + + private IEnumerable GetSupportedFileExporters(object source) + { + if (source == null) + { + return Enumerable.Empty(); + } + + var sourceType = source.GetType(); + + return fileExporters.Where(fe => (fe.SupportedItemType == sourceType || sourceType.Implements(fe.SupportedItemType))); + } } } \ No newline at end of file Index: Core/Common/src/Core.Common.Gui/Commands/GuiExportHandler.cs =================================================================== diff -u -ref1c61d94f2aec3b4ff32fcf03253d7ad386c8e5 -r5b9a225deb21ddb302ddfd070154f61cd2d1b091 --- Core/Common/src/Core.Common.Gui/Commands/GuiExportHandler.cs (.../GuiExportHandler.cs) (revision ef1c61d94f2aec3b4ff32fcf03253d7ad386c8e5) +++ Core/Common/src/Core.Common.Gui/Commands/GuiExportHandler.cs (.../GuiExportHandler.cs) (revision 5b9a225deb21ddb302ddfd070154f61cd2d1b091) @@ -19,15 +19,14 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Windows.Forms; - using Core.Common.Base.IO; -using Core.Common.Base.Plugin; using Core.Common.Gui.Forms; using Core.Common.Gui.Properties; - +using Core.Common.Utils.Reflection; using log4net; namespace Core.Common.Gui.Commands @@ -41,17 +40,17 @@ private static readonly Bitmap brickImage = Resources.brick; private readonly IWin32Window dialogParent; - private readonly ApplicationCore applicationCore; + private readonly IEnumerable fileExporter; /// /// Initializes a new instance of the class. /// /// The parent window to show dialogs on top. - /// The application-plugins host. - public GuiExportHandler(IWin32Window dialogParent, ApplicationCore applicationCore) + /// An enumeration of . + public GuiExportHandler(IWin32Window dialogParent, IEnumerable fileExporter) { this.dialogParent = dialogParent; - this.applicationCore = applicationCore; + this.fileExporter = fileExporter; } /// @@ -83,7 +82,7 @@ private IFileExporter GetSupportedExporterForItemUsingDialog(object itemToExport) { - var fileExporters = applicationCore.GetSupportedFileExporters(itemToExport).ToArray(); + var fileExporters = GetSupportedFileExporters(itemToExport).ToArray(); if (fileExporters.Length == 0) { @@ -113,6 +112,18 @@ return null; } + private IEnumerable GetSupportedFileExporters(object source) + { + if (source == null) + { + return Enumerable.Empty(); + } + + var sourceType = source.GetType(); + + return fileExporter.Where(fe => (fe.SupportedItemType == sourceType || sourceType.Implements(fe.SupportedItemType))); + } + private void ExporterItemUsingFileOpenDialog(IFileExporter exporter, object item) { log.Info(Resources.GuiExportHandler_ExporterItemUsingFileOpenDialog_Start_exporting); Index: Core/Common/src/Core.Common.Gui/GuiCore.cs =================================================================== diff -u -raf42240385db3d3f04bca830513c7464e6f74668 -r5b9a225deb21ddb302ddfd070154f61cd2d1b091 --- Core/Common/src/Core.Common.Gui/GuiCore.cs (.../GuiCore.cs) (revision af42240385db3d3f04bca830513c7464e6f74668) +++ Core/Common/src/Core.Common.Gui/GuiCore.cs (.../GuiCore.cs) (revision 5b9a225deb21ddb302ddfd070154f61cd2d1b091) @@ -122,7 +122,9 @@ viewCommandHandler = new ViewCommandHandler(this, this, this, this); storageCommandHandler = new StorageCommandHandler(projectStore, this, this, this, this, viewCommandHandler); - exportImportCommandHandler = new ExportImportCommandHandler(MainWindow, ApplicationCore, Plugins.SelectMany(p => p.GetFileImporters())); + exportImportCommandHandler = new ExportImportCommandHandler(MainWindow, + Plugins.SelectMany(p => p.GetFileImporters()), + Plugins.SelectMany(p => p.GetFileExporters())); projectCommandHandler = new ProjectCommandHandler(this, MainWindow, ApplicationCore, this, this); WindowsApplication.EnableVisualStyles(); @@ -462,8 +464,6 @@ InitializeGuiPlugins(); - - CopyDefaultViewsFromUserSettings(); //enable activation AFTER initialization @@ -869,7 +869,7 @@ private ApplicationFeatureCommandHandler applicationFeatureCommands; private readonly ViewCommandHandler viewCommandHandler; private readonly ProjectCommandHandler projectCommandHandler; - private ExportImportCommandHandler exportImportCommandHandler; + private readonly ExportImportCommandHandler exportImportCommandHandler; private StorageCommandHandler storageCommandHandler; public IApplicationFeatureCommands ApplicationCommands Index: Core/Common/src/Core.Common.Gui/Plugin/GuiPlugin.cs =================================================================== diff -u -raf42240385db3d3f04bca830513c7464e6f74668 -r5b9a225deb21ddb302ddfd070154f61cd2d1b091 --- Core/Common/src/Core.Common.Gui/Plugin/GuiPlugin.cs (.../GuiPlugin.cs) (revision af42240385db3d3f04bca830513c7464e6f74668) +++ Core/Common/src/Core.Common.Gui/Plugin/GuiPlugin.cs (.../GuiPlugin.cs) (revision 5b9a225deb21ddb302ddfd070154f61cd2d1b091) @@ -69,6 +69,15 @@ } /// + /// This method returns an enumeration of . + /// + /// The enumeration of provided by the . + public virtual IEnumerable GetFileExporters() + { + 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 -raf42240385db3d3f04bca830513c7464e6f74668 -r5b9a225deb21ddb302ddfd070154f61cd2d1b091 --- Core/Common/test/Core.Common.Base.Test/Plugin/ApplicationCoreTest.cs (.../ApplicationCoreTest.cs) (revision af42240385db3d3f04bca830513c7464e6f74668) +++ Core/Common/test/Core.Common.Base.Test/Plugin/ApplicationCoreTest.cs (.../ApplicationCoreTest.cs) (revision 5b9a225deb21ddb302ddfd070154f61cd2d1b091) @@ -44,70 +44,6 @@ } [Test] - public void GetSupportedFileExporters_SimpleApplicationPluginWithExportersAdded_ShouldOnlyProvideSupportedExporters() - { - // Setup - var mocks = new MockRepository(); - var targetItem = new B(); - var supportedFileExporter1 = mocks.Stub(); - var supportedFileExporter2 = mocks.Stub(); - var unsupportedFileExporter = mocks.Stub(); - - supportedFileExporter1.Stub(i => i.SupportedItemType).Return(typeof(B)); - supportedFileExporter2.Stub(i => i.SupportedItemType).Return(typeof(A)); - unsupportedFileExporter.Stub(i => i.SupportedItemType).Return(typeof(C)); // Wrong type - - mocks.ReplayAll(); - - var applicationCore = new ApplicationCore(); - var applicationPlugin = new SimpleApplicationPlugin - { - FileExporters = new[] - { - supportedFileExporter1, - supportedFileExporter2, - unsupportedFileExporter - } - }; - - applicationCore.AddPlugin(applicationPlugin); - - // Call - var supportedExporters = applicationCore.GetSupportedFileExporters(targetItem).ToArray(); - - // Assert - Assert.AreEqual(2, supportedExporters.Length); - Assert.AreSame(supportedFileExporter1, supportedExporters[0]); - Assert.AreSame(supportedFileExporter2, supportedExporters[1]); - } - - [Test] - public void GetSupportedFileExporters_SimpleApplicationPluginWithExportersAdded_ShouldProvideNoExportersWhenSourceEqualsNull() - { - // Setup - var mocks = new MockRepository(); - var fileExporter = mocks.Stub(); - - fileExporter.Stub(e => e.SupportedItemType).Return(null); - - mocks.ReplayAll(); - - var applicationCore = new ApplicationCore(); - var applicationPlugin = new SimpleApplicationPlugin - { - FileExporters = new[] - { - fileExporter - } - }; - - applicationCore.AddPlugin(applicationPlugin); - - // Call / Assert - CollectionAssert.IsEmpty(applicationCore.GetSupportedFileExporters(null)); - } - - [Test] public void GetSupportedDataItemInfos_SimpleApplicationPluginWithDataItemInfosAdded_ShouldOnlyProvideSupportedDataItemInfos() { // Setup @@ -173,11 +109,6 @@ public IEnumerable DataItemInfos { private get; set; } - public override IEnumerable GetFileExporters() - { - return FileExporters; - } - public override IEnumerable GetDataItemInfos() { return DataItemInfos; Index: Core/Common/test/Core.Common.Base.Test/Plugin/ApplicationPluginTest.cs =================================================================== diff -u -raf42240385db3d3f04bca830513c7464e6f74668 -r5b9a225deb21ddb302ddfd070154f61cd2d1b091 --- Core/Common/test/Core.Common.Base.Test/Plugin/ApplicationPluginTest.cs (.../ApplicationPluginTest.cs) (revision af42240385db3d3f04bca830513c7464e6f74668) +++ Core/Common/test/Core.Common.Base.Test/Plugin/ApplicationPluginTest.cs (.../ApplicationPluginTest.cs) (revision 5b9a225deb21ddb302ddfd070154f61cd2d1b091) @@ -29,19 +29,6 @@ public class ApplicationPluginTest { [Test] - public void GetFileExporters_ReturnEmptyEnumerable() - { - // Setup - var applicationPlugin = new SimpleApplicationPlugin(); - - // Call - var importers = applicationPlugin.GetFileExporters().ToArray(); - - // Assert - CollectionAssert.IsEmpty(importers); - } - - [Test] public void GetDataItemInfos_ReturnEmptyEnumerable() { // Setup Index: Core/Common/test/Core.Common.Gui.Test/Commands/ExportImportCommandHandlerTest.cs =================================================================== diff -u -raf42240385db3d3f04bca830513c7464e6f74668 -r5b9a225deb21ddb302ddfd070154f61cd2d1b091 --- Core/Common/test/Core.Common.Gui.Test/Commands/ExportImportCommandHandlerTest.cs (.../ExportImportCommandHandlerTest.cs) (revision af42240385db3d3f04bca830513c7464e6f74668) +++ Core/Common/test/Core.Common.Gui.Test/Commands/ExportImportCommandHandlerTest.cs (.../ExportImportCommandHandlerTest.cs) (revision 5b9a225deb21ddb302ddfd070154f61cd2d1b091) @@ -20,6 +20,7 @@ // All rights reserved. using System.Collections.Generic; +using System.Linq; using System.Windows.Forms; using Core.Common.Base.IO; using Core.Common.Base.Plugin; @@ -38,12 +39,13 @@ // Setup var mocks = new MockRepository(); var dialogParent = mocks.Stub(); - var fileImporters = new List(); + var fileImporters = Enumerable.Empty(); + var fileExporters = Enumerable.Empty(); mocks.ReplayAll(); var applicationCore = new ApplicationCore(); - var commandHandler = new ExportImportCommandHandler(dialogParent, applicationCore, fileImporters); + var commandHandler = new ExportImportCommandHandler(dialogParent, fileImporters, fileExporters); // Call var isImportPossible = commandHandler.CanImportOn(new object()); @@ -69,9 +71,9 @@ { objectImporter }; + var fileExporters = Enumerable.Empty(); - var applicationCore = new ApplicationCore(); - var commandHandler = new ExportImportCommandHandler(dialogParent, applicationCore, fileImporters); + var commandHandler = new ExportImportCommandHandler(dialogParent, fileImporters, fileExporters); // Call var isImportPossible = commandHandler.CanImportOn(target); @@ -96,9 +98,9 @@ { objectImporter }; + var fileExporters = Enumerable.Empty(); - var applicationCore = new ApplicationCore(); - var commandHandler = new ExportImportCommandHandler(dialogParent, applicationCore, fileImporters); + var commandHandler = new ExportImportCommandHandler(dialogParent, fileImporters, fileExporters); // Call var isImportPossible = commandHandler.CanImportOn(target); @@ -125,9 +127,9 @@ { objectImporter1, objectImporter2 }; + var fileExporters = Enumerable.Empty(); - var applicationCore = new ApplicationCore(); - var commandHandler = new ExportImportCommandHandler(dialogParent, applicationCore, fileImporters); + var commandHandler = new ExportImportCommandHandler(dialogParent, fileImporters, fileExporters); // Call var isImportPossible = commandHandler.CanImportOn(target); @@ -154,9 +156,9 @@ { objectImporter1, objectImporter2 }; + var fileExporters = Enumerable.Empty(); - var applicationCore = new ApplicationCore(); - var commandHandler = new ExportImportCommandHandler(dialogParent, applicationCore, fileImporters); + var commandHandler = new ExportImportCommandHandler(dialogParent, fileImporters, fileExporters); // Call var isImportPossible = commandHandler.CanImportOn(target); @@ -174,12 +176,11 @@ var dialogParent = mocks.Stub(); mocks.ReplayAll(); - var fileImporters = new List(); + var fileImporters = Enumerable.Empty(); + var fileExporters = Enumerable.Empty(); - var applicationCore = new ApplicationCore(); + var commandHandler = new ExportImportCommandHandler(dialogParent, fileImporters, fileExporters); - var commandHandler = new ExportImportCommandHandler(dialogParent, applicationCore, fileImporters); - // Call var isExportPossible = commandHandler.CanExportFrom(new object()); @@ -193,25 +194,20 @@ { // Setup var target = new object(); - var fileImporters = new List(); var mocks = new MockRepository(); var dialogParent = mocks.Stub(); var objectExporter = mocks.Stub(); objectExporter.Stub(i => i.SupportedItemType) .Return(target.GetType()); - - var objectApplicationPluginMock = mocks.Stub(); - objectApplicationPluginMock.Expect(p => p.GetFileExporters()) - .Return(new[] - { - objectExporter - }); mocks.ReplayAll(); - var applicationCore = new ApplicationCore(); - applicationCore.AddPlugin(objectApplicationPluginMock); + var fileImporters = Enumerable.Empty(); + var fileExporters = new List + { + objectExporter + }; - var commandHandler = new ExportImportCommandHandler(dialogParent, applicationCore, fileImporters); + var commandHandler = new ExportImportCommandHandler(dialogParent, fileImporters, fileExporters); // Call var isExportPossible = commandHandler.CanExportFrom(new object()); @@ -226,7 +222,6 @@ { // Setup var target = new object(); - var fileImporters = new List(); var mocks = new MockRepository(); var dialogParent = mocks.Stub(); var objectExporter1 = mocks.Stub(); @@ -236,19 +231,16 @@ objectExporter2.Stub(i => i.SupportedItemType) .Return(target.GetType()); - var objectApplicationPluginMock = mocks.Stub(); - objectApplicationPluginMock.Expect(p => p.GetFileExporters()) - .Return(new[] - { - objectExporter1, - objectExporter2 - }); mocks.ReplayAll(); - var applicationCore = new ApplicationCore(); - applicationCore.AddPlugin(objectApplicationPluginMock); + var fileImporters = Enumerable.Empty(); + var fileExporters = new List + { + objectExporter1, + objectExporter2 + }; - var commandHandler = new ExportImportCommandHandler(dialogParent, applicationCore, fileImporters); + var commandHandler = new ExportImportCommandHandler(dialogParent, fileImporters, fileExporters); // Call var isExportPossible = commandHandler.CanExportFrom(new object()); Index: Core/Common/test/Core.Common.Gui.Test/Plugin/GuiPluginTest.cs =================================================================== diff -u -raf42240385db3d3f04bca830513c7464e6f74668 -r5b9a225deb21ddb302ddfd070154f61cd2d1b091 --- Core/Common/test/Core.Common.Gui.Test/Plugin/GuiPluginTest.cs (.../GuiPluginTest.cs) (revision af42240385db3d3f04bca830513c7464e6f74668) +++ Core/Common/test/Core.Common.Gui.Test/Plugin/GuiPluginTest.cs (.../GuiPluginTest.cs) (revision 5b9a225deb21ddb302ddfd070154f61cd2d1b091) @@ -214,6 +214,28 @@ } [Test] + public void GetFileExporters_ReturnsEmptyEnumerable() + { + // Setup + var mocks = new MockRepository(); + var gui = mocks.StrictMock(); + mocks.ReplayAll(); + + using (var plugin = new SimpleGuiPlugin + { + Gui = gui + }) + { + // Call + var infos = plugin.GetFileExporters(); + + // Assert + CollectionAssert.IsEmpty(infos); + } + mocks.VerifyAll(); + } + + [Test] public void Dispose_SetGuiToNull() { // Setup