Index: Core/Common/src/Core.Common.Base/IO/IFileExporter.cs
===================================================================
diff -u -r4512af7782ee31b36941bb280b54d9da2953dd71 -rdd84dcabe5561e637e4ade45457437d9c037535b
--- Core/Common/src/Core.Common.Base/IO/IFileExporter.cs (.../IFileExporter.cs) (revision 4512af7782ee31b36941bb280b54d9da2953dd71)
+++ Core/Common/src/Core.Common.Base/IO/IFileExporter.cs (.../IFileExporter.cs) (revision dd84dcabe5561e637e4ade45457437d9c037535b)
@@ -19,9 +19,6 @@
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
-using System;
-using System.Drawing;
-
namespace Core.Common.Base.IO
{
///
@@ -30,42 +27,10 @@
public interface IFileExporter
{
///
- /// Gets the name of the .
+ /// This method performs the export routine.
///
- string Name { get; }
-
- ///
- /// Gets the category of the .
- ///
- string Category { get; }
-
- ///
- /// Gets the image of the .
- ///
- /// This image can be used in selection and/or progress dialogs.
- Bitmap Image { get; }
-
- ///
- /// Gets the of the item supported by the .
- ///
- Type SupportedItemType { get; }
-
- ///
- /// Gets the file filter of the .
- ///
- ///
- /// An example string would be:
- /// "My file format1 (*.ext1)|*.ext1|My file format2 (*.ext2)|*.ext2"
- ///
- string FileFilter { get; }
-
- ///
- /// This method exports the data of an item to a file at the given location.
- ///
- /// The item to export the data from.
- /// The path of the file to export the data to.
- /// true if the export was successful. false otherwise.
+ /// true if the export was successful, false otherwise.
/// Implementations of this export method are allowed to throw exceptions of any kind.
- bool Export(object sourceItem, string filePath);
+ bool Export();
}
}
\ No newline at end of file
Index: Core/Common/src/Core.Common.Gui/Commands/ExportImportCommandHandler.cs
===================================================================
diff -u -r5b9a225deb21ddb302ddfd070154f61cd2d1b091 -rdd84dcabe5561e637e4ade45457437d9c037535b
--- Core/Common/src/Core.Common.Gui/Commands/ExportImportCommandHandler.cs (.../ExportImportCommandHandler.cs) (revision 5b9a225deb21ddb302ddfd070154f61cd2d1b091)
+++ Core/Common/src/Core.Common.Gui/Commands/ExportImportCommandHandler.cs (.../ExportImportCommandHandler.cs) (revision dd84dcabe5561e637e4ade45457437d9c037535b)
@@ -24,8 +24,8 @@
using System.Linq;
using System.Windows.Forms;
using Core.Common.Base.IO;
+using Core.Common.Gui.Plugin;
using Core.Common.Gui.Properties;
-using Core.Common.Utils.Reflection;
using log4net;
namespace Core.Common.Gui.Commands
@@ -38,7 +38,6 @@
private static readonly ILog log = LogManager.GetLogger(typeof(ExportImportCommandHandler));
private readonly IEnumerable fileImporters;
- private readonly IEnumerable fileExporters;
private readonly GuiImportHandler importHandler;
private readonly GuiExportHandler exportHandler;
@@ -47,13 +46,12 @@
///
/// The parent window onto which dialogs should be shown.
/// An enumeration of .
- /// An enumeration of .
- public ExportImportCommandHandler(IWin32Window dialogParent, IEnumerable fileImporters, IEnumerable fileExporters)
+ /// An enumeration of .
+ public ExportImportCommandHandler(IWin32Window dialogParent, IEnumerable fileImporters, IEnumerable exportInfos)
{
this.fileImporters = fileImporters;
- this.fileExporters = fileExporters;
importHandler = new GuiImportHandler(dialogParent, this.fileImporters);
- exportHandler = new GuiExportHandler(dialogParent, this.fileExporters);
+ exportHandler = new GuiExportHandler(dialogParent, exportInfos);
}
public bool CanImportOn(object target)
@@ -82,31 +80,12 @@
public bool CanExportFrom(object obj)
{
- return GetSupportedFileExporters(obj).Any();
+ return exportHandler.GetSupportedExportInfos(obj).Any();
}
- public void ExportFrom(object data, IFileExporter exporter = null)
+ public void ExportFrom(object data)
{
- if (exporter == null)
- {
- exportHandler.ExportFrom(data);
- }
- else
- {
- exportHandler.GetExporterDialog(exporter, data);
- }
+ exportHandler.ExportFrom(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 -r3e0ac8e7988d37424638e2b768e15a783897e126 -rdd84dcabe5561e637e4ade45457437d9c037535b
--- Core/Common/src/Core.Common.Gui/Commands/GuiExportHandler.cs (.../GuiExportHandler.cs) (revision 3e0ac8e7988d37424638e2b768e15a783897e126)
+++ Core/Common/src/Core.Common.Gui/Commands/GuiExportHandler.cs (.../GuiExportHandler.cs) (revision dd84dcabe5561e637e4ade45457437d9c037535b)
@@ -23,8 +23,8 @@
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
-using Core.Common.Base.IO;
using Core.Common.Gui.Forms;
+using Core.Common.Gui.Plugin;
using Core.Common.Gui.Properties;
using Core.Common.Utils.Reflection;
using log4net;
@@ -40,17 +40,17 @@
private static readonly Bitmap brickImage = Resources.brick;
private readonly IWin32Window dialogParent;
- private readonly IEnumerable fileExporter;
+ private readonly IEnumerable exportInfos;
///
/// Initializes a new instance of the class.
///
/// The parent window to show dialogs on top.
- /// An enumeration of .
- public GuiExportHandler(IWin32Window dialogParent, IEnumerable fileExporter)
+ /// An enumeration of .
+ public GuiExportHandler(IWin32Window dialogParent, IEnumerable exportInfos)
{
this.dialogParent = dialogParent;
- this.fileExporter = fileExporter;
+ this.exportInfos = exportInfos;
}
///
@@ -61,30 +61,31 @@
/// The export source.
public void ExportFrom(object item)
{
- var exporter = GetSupportedExporterForItemUsingDialog(item);
- if (exporter == null)
+ var exportInfo = GetSupportedExportInfoUsingDialog(item);
+ if (exportInfo == null)
{
return;
}
- GetExporterDialog(exporter, item);
+
+ GetExporterDialog(exportInfo, item);
}
///
- /// Ask the user for the target file to export data to, then perform the export
+ /// Asks the user for the target file to export data to, then performs the export
/// using the source object.
///
- /// The importer to use.
- /// The import target.
- public void GetExporterDialog(IFileExporter exporter, object selectedItem)
+ /// The export information to use.
+ /// The export source.
+ public void GetExporterDialog(ExportInfo exportInfo, object selectedItem)
{
- ExporterItemUsingFileOpenDialog(exporter, selectedItem);
+ ExportItemUsingFileOpenDialog(exportInfo, selectedItem);
}
- private IFileExporter GetSupportedExporterForItemUsingDialog(object itemToExport)
+ private ExportInfo GetSupportedExportInfoUsingDialog(object itemToExport)
{
- var fileExporters = GetSupportedFileExporters(itemToExport).ToArray();
+ var supportedExportInfos = GetSupportedExportInfos(itemToExport).ToArray();
- if (fileExporters.Length == 0)
+ if (supportedExportInfos.Length == 0)
{
MessageBox.Show(Resources.GuiExportHandler_GetSupportedExporterForItemUsingDialog_No_exporter_for_this_item_available,
Resources.GuiExportHandler_GetSupportedExporterForItemUsingDialog_Error);
@@ -93,54 +94,60 @@
return null;
}
- // If there is only one available exporter use that:
- if (fileExporters.Length == 1)
+ if (supportedExportInfos.Length == 1)
{
- return fileExporters[0];
+ return supportedExportInfos[0];
}
- using (var selectExporterDialog = new SelectItemDialog(dialogParent))
+ using (var selectExportInfoDialog = new SelectItemDialog(dialogParent))
{
- foreach (var fileExporter in fileExporters)
+ foreach (var exportInfo in supportedExportInfos)
{
- selectExporterDialog.AddItemType(fileExporter.Name, fileExporter.Category, fileExporter.Image ?? brickImage, null);
+ selectExportInfoDialog.AddItemType(exportInfo.Name, exportInfo.Category, exportInfo.Image ?? brickImage, null);
}
- if (selectExporterDialog.ShowDialog() == DialogResult.OK)
+ if (selectExportInfoDialog.ShowDialog() == DialogResult.OK)
{
- return fileExporters.First(i => i.Name == selectExporterDialog.SelectedItemTypeName);
+ return supportedExportInfos.First(info => info.Name == selectExportInfoDialog.SelectedItemTypeName);
}
}
return null;
}
- private IEnumerable GetSupportedFileExporters(object source)
+ ///
+ /// Gets an enumeration of supported objects for the provided .
+ ///
+ /// The data object to get the supported objects for.
+ /// An enumeration of supported objects.
+ public IEnumerable GetSupportedExportInfos(object source)
{
if (source == null)
{
- return Enumerable.Empty();
+ return Enumerable.Empty();
}
var sourceType = source.GetType();
- return fileExporter.Where(fe => (fe.SupportedItemType == sourceType || sourceType.Implements(fe.SupportedItemType)));
+ return exportInfos.Where(info => info.DataType == sourceType || sourceType.Implements(info.DataType));
}
- private void ExporterItemUsingFileOpenDialog(IFileExporter exporter, object item)
+ private void ExportItemUsingFileOpenDialog(ExportInfo exportInfo, object item)
{
log.Info(Resources.GuiExportHandler_ExporterItemUsingFileOpenDialog_Start_exporting);
- var windowTitle = string.Format(Resources.GuiExportHandler_ExporterItemUsingFileOpenDialog_Select_a_DataType_0_file_to_export_to, exporter.Name);
+ var windowTitle = string.Format(Resources.GuiExportHandler_ExporterItemUsingFileOpenDialog_Select_a_DataType_0_file_to_export_to, exportInfo.Name);
using (var saveFileDialog = new SaveFileDialog
{
- Filter = exporter.FileFilter,
+ Filter = exportInfo.FileFilter,
Title = windowTitle,
FilterIndex = 2
})
{
if (saveFileDialog.ShowDialog(dialogParent) == DialogResult.OK)
{
- if (exporter.Export(item, saveFileDialog.FileName))
+ var exporter = exportInfo.CreateFileExporter(item, saveFileDialog.FileName);
+
+ if (exporter.Export())
{
log.Info(Resources.GuiExportHandler_ExporterItemUsingFileOpenDialog_Finished_exporting);
}
Index: Core/Common/src/Core.Common.Gui/Commands/IExportImportCommandHandler.cs
===================================================================
diff -u -ref1c61d94f2aec3b4ff32fcf03253d7ad386c8e5 -rdd84dcabe5561e637e4ade45457437d9c037535b
--- Core/Common/src/Core.Common.Gui/Commands/IExportImportCommandHandler.cs (.../IExportImportCommandHandler.cs) (revision ef1c61d94f2aec3b4ff32fcf03253d7ad386c8e5)
+++ Core/Common/src/Core.Common.Gui/Commands/IExportImportCommandHandler.cs (.../IExportImportCommandHandler.cs) (revision dd84dcabe5561e637e4ade45457437d9c037535b)
@@ -65,7 +65,6 @@
///
///
/// The data to export.
- /// Optional: The specific exporter to use.
- void ExportFrom(object data, IFileExporter exporter = null);
+ void ExportFrom(object data);
}
}
\ No newline at end of file
Index: Core/Common/src/Core.Common.Gui/Core.Common.Gui.csproj
===================================================================
diff -u -ra32bbe3919b6babd74ae4867e8337662aed0dad2 -rdd84dcabe5561e637e4ade45457437d9c037535b
--- Core/Common/src/Core.Common.Gui/Core.Common.Gui.csproj (.../Core.Common.Gui.csproj) (revision a32bbe3919b6babd74ae4867e8337662aed0dad2)
+++ Core/Common/src/Core.Common.Gui/Core.Common.Gui.csproj (.../Core.Common.Gui.csproj) (revision dd84dcabe5561e637e4ade45457437d9c037535b)
@@ -136,6 +136,7 @@
+
Index: Core/Common/src/Core.Common.Gui/GuiCore.cs
===================================================================
diff -u -ra5a1a727ccd295ebb9f22e661eaba874e025718c -rdd84dcabe5561e637e4ade45457437d9c037535b
--- Core/Common/src/Core.Common.Gui/GuiCore.cs (.../GuiCore.cs) (revision a5a1a727ccd295ebb9f22e661eaba874e025718c)
+++ Core/Common/src/Core.Common.Gui/GuiCore.cs (.../GuiCore.cs) (revision dd84dcabe5561e637e4ade45457437d9c037535b)
@@ -119,7 +119,7 @@
storageCommandHandler = new StorageCommandHandler(projectStore, this, MainWindow);
exportImportCommandHandler = new ExportImportCommandHandler(MainWindow,
Plugins.SelectMany(p => p.GetFileImporters()),
- Plugins.SelectMany(p => p.GetFileExporters()));
+ Plugins.SelectMany(p => p.GetExportInfos()));
WindowsApplication.EnableVisualStyles();
ViewPropertyEditor.ViewCommands = ViewCommands;
Index: Core/Common/src/Core.Common.Gui/Plugin/ExportInfo.cs
===================================================================
diff -u
--- Core/Common/src/Core.Common.Gui/Plugin/ExportInfo.cs (revision 0)
+++ Core/Common/src/Core.Common.Gui/Plugin/ExportInfo.cs (revision dd84dcabe5561e637e4ade45457437d9c037535b)
@@ -0,0 +1,144 @@
+// 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 Lesser 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 Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser 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.Drawing;
+using Core.Common.Base.IO;
+
+namespace Core.Common.Gui.Plugin
+{
+ ///
+ /// Information for creating an exporter for a particular data object.
+ ///
+ public class ExportInfo
+ {
+ ///
+ /// Gets or sets the data type associated with this export info.
+ ///
+ public Type DataType { get; set; }
+
+ ///
+ /// Gets or sets the method used to create a . Function arguments:
+ ///
+ /// The data to export.
+ /// The output file path.
+ /// out - The created exporter.
+ ///
+ ///
+ public Func