// 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 updating a particular data object. /// public class UpdateInfo { /// /// Gets or sets the data type associated with this update info. /// public Type DataType { get; set; } /// /// Gets or sets the method used to create a used to update data. /// Function arguments: /// /// The data to import. /// The file to import data from. /// out - The created importer. /// /// public Func CreateFileImporter { get; set; } /// /// Gets or sets the method used to determine whether or not the update routine should be enabled. Function arguments: /// /// The data to update. /// out - true if the update should be enabled, false otherwise. /// /// public Func IsEnabled { get; set; } /// /// Gets or sets the method used to verify whether changes that are induced by the importer /// are allowed. /// public Func VerifyUpdates { get; set; } /// /// Gets or sets the current path from which the current data was imported. /// public Func CurrentPath { get; set; } /// /// Gets or sets the name of the update information. /// public string Name { get; set; } /// /// Gets or sets the category of the update information. /// public string Category { get; set; } /// /// Gets or sets the image of the update information. /// public Image Image { get; set; } /// /// Gets or sets the file filter generator of the update information used to make file filters. /// public FileFilterGenerator FileFilterGenerator { get; set; } } /// /// Information for creating an importer for updating a particular data object. /// /// The data type associated with this update info. public class UpdateInfo { /// /// Gets the data type associated with this update info. /// public Type DataType { get { return typeof(TData); } } /// /// Gets or sets the method used to create a used to update data. /// Function arguments: /// /// The data to import. /// The path to the file to import from. /// out - The created importer. /// /// public Func CreateFileImporter { get; set; } /// /// Gets or sets the method used to determine whether or not the update routine should be enabled. Function arguments: /// /// The data to update. /// out - true if the update should be enabled, false otherwise. /// /// public Func IsEnabled { get; set; } /// /// Gets or sets the method used to verify whether changes that are induced by the importer /// are allowed. /// public Func VerifyUpdates { get; set; } /// /// Gets or sets the current path from which the current data was imported. /// public Func CurrentPath { get; set; } /// /// Gets or sets the name of the update information. /// public string Name { get; set; } /// /// Gets or sets the category of the update information. /// public string Category { get; set; } /// /// Gets or sets the image of the update information. /// public Image Image { get; set; } /// /// Gets or sets the file filter generator of the update information used to make file filters. /// public FileFilterGenerator FileFilterGenerator { get; set; } /// /// Performs an implicit conversion from to . /// /// The update information to convert. /// The result of the conversion. public static implicit operator UpdateInfo(UpdateInfo updateInfo) { return new UpdateInfo { DataType = updateInfo.DataType, CreateFileImporter = (data, path) => updateInfo.CreateFileImporter?.Invoke((TData) data, path), IsEnabled = data => updateInfo.IsEnabled == null || updateInfo.IsEnabled((TData) data), VerifyUpdates = data => updateInfo.VerifyUpdates == null || updateInfo.VerifyUpdates((TData) data), CurrentPath = data => updateInfo.CurrentPath?.Invoke((TData) data), Name = updateInfo.Name, Category = updateInfo.Category, Image = updateInfo.Image, FileFilterGenerator = updateInfo.FileFilterGenerator }; } } }