// Copyright (C) Stichting Deltares 2023. All rights reserved. // // This file is part of the application DAM - UI. // // DAM - UI is free software: you can redistribute it and/or modify // it under the terms of the GNU 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 General Public License for more details. // // You should have received a copy of the GNU 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 SPath = System.IO.Path; namespace Deltares.Dam.Data.IO; public abstract class AbstractExporter : IExport { protected AbstractExporter(string name) : this(name, ".") {} protected AbstractExporter(string name, string outputPath) : this(name, outputPath, default) {} protected AbstractExporter(string name, string outputPath, T data) { Name = name; Path = outputPath; Data = data; } protected virtual void Export(string fileName, T data) {} #region Implementation of IExport /// /// Sets the name of the file without extension /// public string Name { get; set; } /// /// Sets the path of the output folder /// public string Path { set; get; } /// /// Sets the data to export /// object IExport.Data { set { Data = (T) value; } } /// /// Sets the data to export /// public T Data { set; protected get; } /// /// Gets or sets the name of the file which will be set/combined by Path + Name + Extension in the export method /// public string FileName { get; private set; } /// /// Gets or sets the file extension /// protected string FileExtension { private get; set; } /// /// Exports the data to files in the current folder /// public void Export() { if (string.IsNullOrEmpty(Path)) { throw new InvalidOperationException("path"); } if (string.IsNullOrEmpty(Name) || Name.Trim() == "") { throw new InvalidOperationException("No name given for the file to export to"); } FileName = SPath.Combine(Path, Name + FileExtension); Export(FileName, Data); } #endregion }