Index: Core/Common/src/Core.Common.Gui/Core.Common.Gui.csproj
===================================================================
diff -u -rd1c832128168938c7cb5ed4b1ac54382e0fc96fe -rc625517c051161c0b306e3a554d2227fce06e614
--- Core/Common/src/Core.Common.Gui/Core.Common.Gui.csproj (.../Core.Common.Gui.csproj) (revision d1c832128168938c7cb5ed4b1ac54382e0fc96fe)
+++ Core/Common/src/Core.Common.Gui/Core.Common.Gui.csproj (.../Core.Common.Gui.csproj) (revision c625517c051161c0b306e3a554d2227fce06e614)
@@ -138,6 +138,7 @@
+
Index: Core/Common/src/Core.Common.Gui/Plugin/ImportInfo.cs
===================================================================
diff -u
--- Core/Common/src/Core.Common.Gui/Plugin/ImportInfo.cs (revision 0)
+++ Core/Common/src/Core.Common.Gui/Plugin/ImportInfo.cs (revision c625517c051161c0b306e3a554d2227fce06e614)
@@ -0,0 +1,163 @@
+// 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 importer for a particular data object.
+ ///
+ public class ImportInfo
+ {
+ ///
+ /// Gets or sets the data type associated with this import info.
+ ///
+ public Type DataType { get; set; }
+
+ ///
+ /// Gets or sets the method used to create a . Function arguments:
+ ///
+ /// - The data to import.
+ /// - The input file path.
+ /// - out - The created importer.
+ ///
+ ///
+ public Func CreateFileImporter { get; set; }
+
+ ///
+ /// Gets or sets the method used to determine whether or not the import routine should be enabled. Function arguments:
+ ///
+ /// - The data to import.
+ /// - out -
true if the import should be enabled, false otherwise.
+ ///
+ ///
+ public Func IsEnabled { get; set; }
+
+ ///
+ /// Gets or sets the name of the import information.
+ ///
+ public string Name { get; set; }
+
+ ///
+ /// Gets or sets the category of the import information.
+ ///
+ public string Category { get; set; }
+
+ ///
+ /// Gets or sets the image of the import information.
+ ///
+ public Image Image { get; set; }
+
+ ///
+ /// Gets or sets the file filter of the import information.
+ ///
+ ///
+ /// An example string would be:
+ /// "My file format1 (*.ext1)|*.ext1|My file format2 (*.ext2)|*.ext2"
+ ///
+ public string FileFilter { get; set; }
+ }
+
+ ///
+ /// Information for creating an importer for a particular data object.
+ ///
+ /// The data type associated with this import info.
+ public class ImportInfo
+ {
+ ///
+ /// Gets the data type associated with this import info.
+ ///
+ public Type DataType
+ {
+ get
+ {
+ return typeof(TData);
+ }
+ }
+
+ ///
+ /// Gets or sets the method used to create a . Function arguments:
+ ///
+ /// - The data to import.
+ /// - The input file path.
+ /// - out - The created importer.
+ ///
+ ///
+ public Func CreateFileImporter { get; set; }
+
+ ///
+ /// Gets or sets the method used to determine whether or not the import routine should be enabled. Function arguments:
+ ///
+ /// - The data to import.
+ /// - out -
true if the import should be enabled, false otherwise.
+ ///
+ ///
+ public Func IsEnabled { get; set; }
+
+ ///
+ /// Gets or sets the name of the import information.
+ ///
+ public string Name { get; set; }
+
+ ///
+ /// Gets or sets the category of the import information.
+ ///
+ public string Category { get; set; }
+
+ ///
+ /// Gets or sets the image of the import information.
+ ///
+ public Image Image { get; set; }
+
+ ///
+ /// Gets or sets the file filter of the import information.
+ ///
+ ///
+ /// An example string would be:
+ /// "My file format1 (*.ext1)|*.ext1|My file format2 (*.ext2)|*.ext2"
+ ///
+ public string FileFilter { get; set; }
+
+ ///
+ /// Performs an implicit conversion from to .
+ ///
+ /// The import information to convert.
+ /// The result of the conversion.
+ public static implicit operator ImportInfo(ImportInfo importInfo)
+ {
+ return new ImportInfo
+ {
+ DataType = importInfo.DataType,
+ CreateFileImporter = (data, filePath) => importInfo.CreateFileImporter != null ?
+ importInfo.CreateFileImporter((TData)data, filePath) :
+ null,
+ IsEnabled = data => importInfo.IsEnabled == null || importInfo.IsEnabled((TData)data),
+ Name = importInfo.Name,
+ Category = importInfo.Category,
+ Image = importInfo.Image,
+ FileFilter = importInfo.FileFilter
+ };
+ }
+ }
+}
\ No newline at end of file
Index: Core/Common/test/Core.Common.Gui.Test/Core.Common.Gui.Test.csproj
===================================================================
diff -u -r3d84064b23186da3fb11f19ff0d07f41e1209bbb -rc625517c051161c0b306e3a554d2227fce06e614
--- Core/Common/test/Core.Common.Gui.Test/Core.Common.Gui.Test.csproj (.../Core.Common.Gui.Test.csproj) (revision 3d84064b23186da3fb11f19ff0d07f41e1209bbb)
+++ Core/Common/test/Core.Common.Gui.Test/Core.Common.Gui.Test.csproj (.../Core.Common.Gui.Test.csproj) (revision c625517c051161c0b306e3a554d2227fce06e614)
@@ -112,6 +112,7 @@
+
Index: Core/Common/test/Core.Common.Gui.Test/Plugin/ImportInfoTest.cs
===================================================================
diff -u
--- Core/Common/test/Core.Common.Gui.Test/Plugin/ImportInfoTest.cs (revision 0)
+++ Core/Common/test/Core.Common.Gui.Test/Plugin/ImportInfoTest.cs (revision c625517c051161c0b306e3a554d2227fce06e614)
@@ -0,0 +1,134 @@
+// 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.Drawing;
+using Core.Common.Base.IO;
+using Core.Common.Gui.Plugin;
+using NUnit.Framework;
+using Rhino.Mocks;
+
+namespace Core.Common.Gui.Test.Plugin
+{
+ [TestFixture]
+ public class ImportInfoTest
+ {
+ [Test]
+ public void DefaultConstructor_ExpectedValues()
+ {
+ // Call
+ var info = new ImportInfo();
+
+ // Assert
+ Assert.IsNull(info.DataType);
+ Assert.IsNull(info.CreateFileImporter);
+ Assert.IsNull(info.IsEnabled);
+ Assert.IsNullOrEmpty(info.Name);
+ Assert.IsNullOrEmpty(info.Category);
+ Assert.IsNull(info.Image);
+ Assert.IsNullOrEmpty(info.FileFilter);
+ }
+
+ [Test]
+ public void DefaultGenericConstructor_ExpectedValues()
+ {
+ // Call
+ var info = new ImportInfo();
+
+ // Assert
+ Assert.AreEqual(typeof(int), info.DataType);
+ Assert.IsNull(info.CreateFileImporter);
+ Assert.IsNull(info.IsEnabled);
+ Assert.IsNullOrEmpty(info.Name);
+ Assert.IsNullOrEmpty(info.Category);
+ Assert.IsNull(info.Image);
+ Assert.IsNullOrEmpty(info.FileFilter);
+ }
+
+ [Test]
+ public void ImplicitOperator_OptionalDelegatesAndPropertiesSet_ImportInfoFullyConverted()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var fileImporter = mocks.StrictMock();
+ mocks.ReplayAll();
+
+ const string name = "name";
+ const string category = "category";
+ Bitmap image = new Bitmap(16, 16);
+ const string fileFilter = "fileFilter";
+
+ var info = new ImportInfo
+ {
+ CreateFileImporter = (data, filePath) => fileImporter,
+ IsEnabled = data => false,
+ Name = name,
+ Category = category,
+ Image = image,
+ FileFilter = fileFilter
+ };
+
+ // Precondition
+ Assert.IsInstanceOf>(info);
+
+ // Call
+ ImportInfo convertedInfo = info;
+
+ // Assert
+ Assert.IsInstanceOf(convertedInfo);
+ Assert.AreEqual(typeof(int), convertedInfo.DataType);
+ Assert.IsNotNull(convertedInfo.CreateFileImporter);
+ Assert.AreSame(fileImporter, convertedInfo.CreateFileImporter(12, string.Empty));
+ Assert.IsNotNull(convertedInfo.IsEnabled);
+ Assert.IsFalse(convertedInfo.IsEnabled(12));
+ Assert.AreEqual(name, info.Name);
+ Assert.AreEqual(category, info.Category);
+ Assert.AreSame(image, info.Image);
+ Assert.AreEqual(fileFilter, info.FileFilter);
+
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void ImplicitOperator_NoneOfTheOptionalDelegatesAndPropertiesSet_ImportInfoFullyConverted()
+ {
+ // Setup
+ var info = new ImportInfo();
+
+ // Precondition
+ Assert.IsInstanceOf>(info);
+
+ // Call
+ ImportInfo convertedInfo = info;
+
+ // Assert
+ Assert.IsInstanceOf(convertedInfo);
+ Assert.AreEqual(typeof(int), convertedInfo.DataType);
+ Assert.IsNotNull(convertedInfo.CreateFileImporter);
+ Assert.IsNull(convertedInfo.CreateFileImporter(new object(), string.Empty));
+ Assert.IsNotNull(convertedInfo.IsEnabled);
+ Assert.IsTrue(convertedInfo.IsEnabled(new object()));
+ Assert.IsNullOrEmpty(info.Name);
+ Assert.IsNullOrEmpty(info.Category);
+ Assert.IsNull(info.Image);
+ Assert.IsNullOrEmpty(info.FileFilter);
+ }
+ }
+}
\ No newline at end of file