/* * 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 { /// /// /// 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. /// /// /// /// The file type that this reader belongs to. /// /// public abstract class Reader : Exceptional, IReader where T : File { /// /// /// 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. /// /// /// /// The associated DTS.Serialization.File-based class. /// /// protected Reader(T fileType) { try { FileType = fileType; ChFileCompare = new ChannelFilenameComparer(fileType); } catch (System.Exception ex) { throw new Exception("encountered problem constructing " + GetType().FullName, ex); } } /// /// Get the -type associated with this reader. /// protected T FileType { get => _FileType.Value; private set => _FileType.Value = value; } private readonly Property _FileType = new Property( typeof(Reader).Namespace + ".File.Reader.FileType", null, false ); /// /// Channel Filename comparer used by some file types. /// protected ChannelFilenameComparer ChFileCompare { get => _ChFileCompare.Value; private set => _ChFileCompare.Value = value; } private readonly Property _ChFileCompare = new Property( typeof(ChannelFilenameComparer).Namespace + ".File.Reader.ChFileCompare", null, false ); protected class ChannelFilenameComparer : IComparer { 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; } } } } } }