// Copyright (C) Stichting Deltares 2018. 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
{
private string name;
private string path;
protected AbstractExporter(string name)
: this(name, ".")
{
}
protected AbstractExporter(string name, string outputPath)
: this(name, outputPath, default(T))
{
}
protected AbstractExporter(string name, string outputPath, T data)
{
this.name = name;
this.path = outputPath;
this.Data = data;
}
#region Implementation of IExport
///
/// Sets the name of the file without extension
///
public string Name
{
protected get { return this.name; }
set { this.name = value; }
}
///
/// Sets the path of the output folder
///
public string Path
{
set { this.path = value; }
protected get { return this.path; }
}
///
/// Sets the data to export
///
object IExport.Data { set { this.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(this.path))
throw new InvalidOperationException("path");
if (string.IsNullOrEmpty(this.name) || this.name.Trim() == "")
throw new InvalidOperationException("No name given for the file to export to");
this.FileName = SPath.Combine(path, name + this.FileExtension);
Export(this.FileName, this.Data);
}
#endregion
protected virtual void Export(string fileName, T data)
{
}
}
}