146 lines
4.9 KiB
C#
146 lines
4.9 KiB
C#
/*
|
|
* TDAS.File.cs
|
|
*
|
|
* Copyright © 2010
|
|
* Diversified Technical Systems, Inc.
|
|
* All Rights Reserved
|
|
*/
|
|
|
|
using DTS.Common.Utilities.DotNetProgrammingConstructs;
|
|
|
|
namespace DTS.Serialization.TDAS
|
|
{ ///
|
|
/// <summary>
|
|
/// TDAS File
|
|
/// </summary>
|
|
///
|
|
public partial class File
|
|
: Serialization.File, IWritable<Test>
|
|
{ ///
|
|
/// <summary>
|
|
/// Initialize an instance of the FtssCsv.File class.
|
|
/// </summary>
|
|
///
|
|
public File()
|
|
: base("TDAS")
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get this file format's extension.
|
|
/// </summary>
|
|
public static string Extension => ".tlf";
|
|
|
|
/// <summary>
|
|
/// Get the file writer for this file type.
|
|
/// </summary>
|
|
public IWriter<Test> 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<Test> _Exporter = null;
|
|
|
|
/// <summary>
|
|
/// Get the file reader for this file type.
|
|
/// </summary>
|
|
public IReader<Test> 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<Test> _Importer = null;
|
|
|
|
/// <summary>
|
|
/// File extension for the disk entity that contains the serialized test information.
|
|
/// </summary>
|
|
public static string TestFileExtension
|
|
{
|
|
get => _TestFileExtension.Value;
|
|
private set => _TestFileExtension.Value = value;
|
|
}
|
|
private static readonly Property<string> _TestFileExtension = new Property<string>("TestFileExtension", ".tlf", true);
|
|
|
|
/// <summary>
|
|
/// File extension for the disk entity that contains serialized channel information.
|
|
/// </summary>
|
|
public static string ChannelFileExtension
|
|
{
|
|
get => _ChannelFileExtension.Value;
|
|
private set => _ChannelFileExtension.Value = value;
|
|
}
|
|
private static readonly Property<string> _ChannelFileExtension = new Property<string>("ChannelFileExtension", ".BIN", true);
|
|
|
|
/// <summary>
|
|
/// File extension for the disk entity that contains serialized channel information.
|
|
/// </summary>
|
|
public static string CalculatedChannelFileExtension
|
|
{
|
|
get => _CalculatedChannelFileExtension.Value;
|
|
private set => _CalculatedChannelFileExtension.Value = value;
|
|
}
|
|
private static readonly Property<string> _CalculatedChannelFileExtension = new Property<string>("CalculatedChannelFileExtension", ".cchn", true);
|
|
|
|
/// <summary>
|
|
/// The string that separates the channel numbers from the riffraff.
|
|
/// </summary>
|
|
private const string ChannelNumberDelimiter = ".";
|
|
|
|
/// <summary>
|
|
/// Extract the channel number from the specified channel filename.
|
|
/// </summary>
|
|
///
|
|
/// <param name="channelFileName">
|
|
/// The channel filename <see cref="string"/> to be converted into a channel number.
|
|
/// </param>
|
|
///
|
|
/// <returns>
|
|
/// The <see cref="int"/> channel number represented by the specified file.
|
|
/// </returns>
|
|
///
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
}
|