//-----------------------------------------------------------------------
//
// Copyright (c) 2009 Deltares. All rights reserved.
//
// B. Faassen
// Barry.Faassen@deltares.nl
//
// Basic immplementation of IExport
//-----------------------------------------------------------------------
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)
{
}
}
}