tbf/RecordProcessing/Records/FlowtubeTestHeRecord.cs

80 lines
2.8 KiB
C#

///
/// Copyright (c) 2019 Sensus Slovensko a.s.
///
using System;
using System.IO;
using log4net;
namespace RecordProcessing.Records
{
public class FlowtubeTestHeRecord : IRecord
{
static readonly ILog log = LogManager.GetLogger(typeof(FlowtubeTestHeRecord));
public string FileName { get { return fileName; } }
public string SN { get { return sn; } set { } }
public DateTime TimeStamp { get { return timeStamp; } }
public Status Status { get { return status; } }
public string ResultStr { get { return resultStr; } }
public string Remark { get { return string.Empty; } }
string fileName;
string sn;
DateTime timeStamp;
Status status;
string resultStr;
public FlowtubeTestHeRecord()
{
}
/// <summary>
/// Load a record from Helium tester.
/// </summary>
/// <param name="fileName">Full file pathname</param>
/// <returns>Record or null</returns>
public static FlowtubeTestHeRecord FromFile(string fileName)
{
try
{
string bareFileName = System.IO.Path.GetFileName(fileName).Replace(".csv", "");
using (TextReader reader = new StreamReader(fileName))
{
FlowtubeTestHeRecord record = new FlowtubeTestHeRecord();
string line2 = null;
string line1 = reader.ReadLine();
if (line1 != null) line2 = reader.ReadLine();
if (line2 != null)
{
string[] fields = line2.Split(new char[] { ';' });
if (fields.Length <= 4) return null; /// Not enough fields in the file
record.fileName = bareFileName;
record.timeStamp = DateTime.Now; /// TODO: Get it from file
record.sn = fields[3];
record.status = fields[4].ToLower().Equals("ok") ? Status.Passed : Status.Failed;
record.resultStr = (fields.Length > 17) ? string.Format("({0} {1})", fields[17], "mbar l/s") : string.Empty;
reader.Close();
return record;
}
return null;
}
}
catch (Exception exc)
{
log.ErrorFormat("Cannot open file {0}: {1}", fileName, exc.Message);
return null;
}
}
public bool CanSaveRecordToOracle() { return false; }
public bool SaveRecordToOracle(Oracle.DataAccess.Client.OracleConnection oraConn) { return false; }
public bool CanPrintRecord() { return false; }
public bool PrintRecord() { return false; }
}
}