107 lines
4.2 KiB
C#
107 lines
4.2 KiB
C#
|
|
/*
|
|||
|
|
* File.Reader.cs
|
|||
|
|
*
|
|||
|
|
* Copyright © 2009
|
|||
|
|
* Diversified Technical Systems, Inc.
|
|||
|
|
* All Rights Reserved
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
using DTS.Common.Utilities;
|
|||
|
|
using DTS.Common.Utilities.DotNetProgrammingConstructs;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
|
|||
|
|
namespace DTS.Serialization
|
|||
|
|
{
|
|||
|
|
// *** see File.cs ***
|
|||
|
|
public abstract partial class File
|
|||
|
|
{ ///
|
|||
|
|
/// <summary>
|
|||
|
|
/// A class for reading files of this type. There can be several reader types in a
|
|||
|
|
/// File-based class -- one for each "type" that the reader target is to be read/converted
|
|||
|
|
/// into.
|
|||
|
|
/// </summary>
|
|||
|
|
///
|
|||
|
|
/// <typeparam name="T">
|
|||
|
|
/// The file type that this reader belongs to.
|
|||
|
|
/// </typeparam>
|
|||
|
|
///
|
|||
|
|
public abstract class Reader<T> : Exceptional, IReader
|
|||
|
|
where T : File
|
|||
|
|
{ ///
|
|||
|
|
/// <summary>
|
|||
|
|
/// Constructor for the DTS.Export.File.Reader class. Note that access restrictions require that
|
|||
|
|
/// readers be constructed by the hosting DTS.Export.File class only. Use a File-level property or
|
|||
|
|
/// factory function to create/pass reader objects to outside parties.
|
|||
|
|
/// </summary>
|
|||
|
|
///
|
|||
|
|
/// <param name="fileType">
|
|||
|
|
/// The associated DTS.Serialization.File-based class.
|
|||
|
|
/// </param>
|
|||
|
|
///
|
|||
|
|
protected Reader(T fileType)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
FileType = fileType;
|
|||
|
|
ChFileCompare = new ChannelFilenameComparer(fileType);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
catch (System.Exception ex)
|
|||
|
|
{
|
|||
|
|
throw new Exception("encountered problem constructing " + GetType().FullName, ex);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Get the <see cref="DTS.Serialization.File"/>-type associated with this reader.
|
|||
|
|
/// </summary>
|
|||
|
|
protected T FileType
|
|||
|
|
{
|
|||
|
|
get => _FileType.Value;
|
|||
|
|
private set => _FileType.Value = value;
|
|||
|
|
}
|
|||
|
|
private readonly Property<T> _FileType
|
|||
|
|
= new Property<T>(
|
|||
|
|
typeof(Reader<T>).Namespace + ".File.Reader.FileType",
|
|||
|
|
null,
|
|||
|
|
false
|
|||
|
|
);
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Channel Filename comparer used by some file types.
|
|||
|
|
/// </summary>
|
|||
|
|
protected ChannelFilenameComparer ChFileCompare
|
|||
|
|
{
|
|||
|
|
get => _ChFileCompare.Value;
|
|||
|
|
private set => _ChFileCompare.Value = value;
|
|||
|
|
}
|
|||
|
|
private readonly Property<ChannelFilenameComparer> _ChFileCompare
|
|||
|
|
= new Property<ChannelFilenameComparer>(
|
|||
|
|
typeof(ChannelFilenameComparer).Namespace + ".File.Reader.ChFileCompare",
|
|||
|
|
null,
|
|||
|
|
false
|
|||
|
|
);
|
|||
|
|
|
|||
|
|
protected class ChannelFilenameComparer : IComparer<string>
|
|||
|
|
{
|
|||
|
|
public File file { get; private set; }
|
|||
|
|
public int Compare(string left, string right)
|
|||
|
|
{
|
|||
|
|
return file.GetChannelNumberFromChannelFileName(left) != file.GetChannelNumberFromChannelFileName(right) ?
|
|||
|
|
file.GetChannelNumberFromChannelFileName(left) - file.GetChannelNumberFromChannelFileName(right) :
|
|||
|
|
string.Compare(left, right); // 19044 only dual-cal sensors will have repeat channel numbers (nonlinear then linear),
|
|||
|
|
// so do a straight compare to put nonlinear .chn before linear .lin.chn
|
|||
|
|
// if a non-SLICE or TDAS file type uses this, will be a regular string compare as GetChannelNumber... returns -1 always
|
|||
|
|
}
|
|||
|
|
public ChannelFilenameComparer(T fileType)
|
|||
|
|
{
|
|||
|
|
if (fileType is File f)
|
|||
|
|
{
|
|||
|
|
file = f;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|