/*
* TDAS.File.cs
*
* Copyright © 2010
* Diversified Technical Systems, Inc.
* All Rights Reserved
*/
using DTS.Common.Utilities.DotNetProgrammingConstructs;
namespace DTS.Serialization.TDAS
{ ///
///
/// TDAS File
///
///
public partial class File
: Serialization.File, IWritable
{ ///
///
/// Initialize an instance of the FtssCsv.File class.
///
///
public File()
: base("TDAS")
{
}
///
/// Get this file format's extension.
///
public static string Extension => ".tlf";
///
/// Get the file writer for this file type.
///
public IWriter Exporter
{
get
{
try
{
if (_Exporter == null)
_Exporter = new Writer(this, DefaultEncoding);
return _Exporter;
}
catch (System.Exception ex)
{
throw new Exception("encountered problem getting exporter", ex);
}
}
}
private IWriter _Exporter = null;
///
/// Get the file reader for this file type.
///
public IReader Importer
{
get
{
try
{
if (_Importer == null)
_Importer = new Reader(this);
return _Importer;
}
catch (System.Exception ex)
{
throw new Exception("encountered problem getting importer", ex);
}
}
}
private IReader _Importer = null;
///
/// File extension for the disk entity that contains the serialized test information.
///
public static string TestFileExtension
{
get => _TestFileExtension.Value;
private set => _TestFileExtension.Value = value;
}
private static readonly Property _TestFileExtension = new Property("TestFileExtension", ".tlf", true);
///
/// File extension for the disk entity that contains serialized channel information.
///
public static string ChannelFileExtension
{
get => _ChannelFileExtension.Value;
private set => _ChannelFileExtension.Value = value;
}
private static readonly Property _ChannelFileExtension = new Property("ChannelFileExtension", ".BIN", true);
///
/// File extension for the disk entity that contains serialized channel information.
///
public static string CalculatedChannelFileExtension
{
get => _CalculatedChannelFileExtension.Value;
private set => _CalculatedChannelFileExtension.Value = value;
}
private static readonly Property _CalculatedChannelFileExtension = new Property("CalculatedChannelFileExtension", ".cchn", true);
///
/// The string that separates the channel numbers from the riffraff.
///
private const string ChannelNumberDelimiter = ".";
///
/// Extract the channel number from the specified channel filename.
///
///
///
/// The channel filename to be converted into a channel number.
///
///
///
/// The channel number represented by the specified file.
///
///
public override int GetChannelNumberFromChannelFileName(string channelFileName)
{
try
{
var indexOfExtension = channelFileName.LastIndexOf(ChannelFileExtension);
if (indexOfExtension == -1)
{
indexOfExtension = channelFileName.LastIndexOf(ChannelFileExtension.ToLower());
}
var indexOfFirstChannelNumberCharacter = indexOfExtension - 3; //901, 001, etc. but could be _C001 (not a problem)
var intResult = -1;
int.TryParse(channelFileName.Substring(indexOfFirstChannelNumberCharacter, 3), out intResult);
return intResult;
}
catch (System.Exception ex)
{
throw new Exception("encountered problem getting channel number from channel file name", ex);
}
}
}
}