Files
DP44/DataPRO/SensorDB/TSF/TSFDIMSection.cs
2026-04-17 14:55:32 -04:00

122 lines
6.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DTS.SensorDB.TSF
{
/// <summary>
/// the DIM section of a TSF
/// we currently do nothing with the DIM section other than parse it
/// DIMs are not officially supported in DataPRO yet
/// </summary>
public class TSFDIMSection
{
private const string SECTION_START_HEADER = "---- DIM Begin (1.0) ----";
private const string COLUMN_HEADER = "Datachan,Rack,Module,Chan,Description,Serial No,Mode,Inverted,EID,Filename,Scale,Filter Mode,Filter Threshold,ISO CODE,Cable Test";
private const string SECTION_END_HEADER = "---- DIM End ----";
private List<TSFDIMEntry> _dimEntries = new List<TSFDIMEntry>();
public TSFDIMEntry[] DIMEntries
{
get { return _dimEntries.ToArray(); }
set { _dimEntries = new List<TSFDIMEntry>(value); }
}
public void ReadFrom(List<string> lines, ref int currentLine, ref List<ReadTSFError> errors)
{
if (currentLine == lines.Count)
{
//errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_UNEXPECTED_EOF, currentLine));
return;
}
string sectionStart = lines[currentLine++];
if (false == sectionStart.Contains(SECTION_START_HEADER))
{
//DIM Section may not be defined for this TSF. Bail and dont error.
currentLine--;
return;
}
if (currentLine == lines.Count)
{
errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_UNEXPECTED_EOF, currentLine));
return;
}
string columnHeaders = lines[currentLine++];
if (columnHeaders != COLUMN_HEADER)
{
errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_DIM_INVALID_COLUMNSECTIONHEADER, currentLine, columnHeaders));
return;
}
bool done = false;
List<TSFDIMEntry> dims = new List<TSFDIMEntry>();
while (!done)
{
if (currentLine == lines.Count) { errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_UNEXPECTED_EOF, currentLine)); return; }
string line = lines[currentLine++];
if (!line.Contains("DIM End"))
{
TSFDIMEntry entry = new TSFDIMEntry();
string[] tokens = line.Split(new char[] { ',' });
for (int iCurField = 0; iCurField < tokens.Length; iCurField++)
{
string s = tokens[iCurField];
TSFDIMEntry.Fields field = (TSFDIMEntry.Fields)iCurField;
switch (field)
{
case TSFDIMEntry.Fields.CableTest:
try { entry.CableTest = Convert.ToInt32(s); }
catch (System.Exception) { errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_DIM_INVALID_CABLETEST, currentLine, s)); }
break;
case TSFDIMEntry.Fields.Chan:
try { entry.Chan = Convert.ToInt32(s); }
catch (System.Exception) { errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_DIM_INVALID_CHAN, currentLine, s)); }
break;
case TSFDIMEntry.Fields.Datachan:
try { entry.DataChan = Convert.ToInt32(s); }
catch (System.Exception) { errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_DIM_INVALID_DATACHAN, currentLine, s)); }
break;
case TSFDIMEntry.Fields.Description: entry.Description = s; break;
case TSFDIMEntry.Fields.EID: entry.EID = s; break;
case TSFDIMEntry.Fields.Filename: entry.FileName = s; break;
case TSFDIMEntry.Fields.FilterMode:
try { entry.FilterMode = Convert.ToInt32(s); }
catch (System.Exception) { errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_DIM_INVALID_FILTERMODE, currentLine, s)); }
break;
case TSFDIMEntry.Fields.FilterThreshold:
try { entry.FilterThreshold = Convert.ToDouble(s); }
catch (System.Exception) { errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_DIM_INVALID_FILTERTHRESHOLD, currentLine, s)); }
break;
case TSFDIMEntry.Fields.Inverted:
try { entry.Inverted = Convert.ToInt32(s); }
catch (System.Exception) { errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_DIM_INVALID_INVERTED, currentLine, s)); }
break;
case TSFDIMEntry.Fields.ISOCODE: entry.ISOCode = s; break;
case TSFDIMEntry.Fields.Mode: entry.Mode = s; break;
case TSFDIMEntry.Fields.Module:
try { entry.Module = Convert.ToInt32(s); }
catch (System.Exception) { errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_DIM_INVALID_MODULE, currentLine, s)); }
break;
case TSFDIMEntry.Fields.Rack:
try { entry.Rack = Convert.ToInt32(s); }
catch (System.Exception) { errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_DIM_INVALID_RACK, currentLine, s)); }
break;
case TSFDIMEntry.Fields.Scale:
try { entry.Scale = Convert.ToDouble(s); }
catch (System.Exception) { errors.Add(new ReadTSFError(ReadTSFError.TSF_ERRORS.TSF_DIM_INVALID_SCALE, currentLine, s)); }
break;
case TSFDIMEntry.Fields.SerialNo: entry.SerialNumber = s; break;
default: throw new NotSupportedException("TSFFile::ReadTSF unknown DIM field: " + field.ToString());
}
}
dims.Add(entry);
}
else { done = true; }
}
DIMEntries = dims.ToArray();
}
}
}