tbf/RecordProcessing/Records/LaserNanjingRecord.cs

92 lines
2.9 KiB
C#

///
/// Copyright (c) 2022 Sensus Slovensko a.s.
///
using System;
using System.Globalization;
using System.IO;
using System.Text;
using log4net;
namespace RecordProcessing.Records
{
public class LaserNanjingRecord : IRecord
{
static readonly ILog log = LogManager.GetLogger(typeof(LaserNanjingRecord));
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; }
public static string Path;
public string FileName { get { return fileName; } }
public string SN { get { return sn; } set { sn = value; } }
public DateTime TimeStamp { get { return timeStamp; } }
public Status Status { get { return status; } }
public string Remark { get { return string.Empty; } }
public string ResultStr { get { return string.Empty; } }
string fileName;
string sn;
DateTime timeStamp;
Status status;
string remark;
public LaserNanjingRecord()
{
sn = null;
status = Status.Interrupted;
}
/// <summary>
/// Load a record from an xml-file
/// </summary>
/// <param name="fileName">xml-filename</param>
/// <returns>Record or null</returns>
public static LaserNanjingRecord FromFile(string fileName)
{
try
{
string bareFileName = System.IO.Path.GetFileName(fileName).Replace(".csv", "");
LaserNanjingRecord record = new LaserNanjingRecord();
record.fileName = bareFileName;
record.timeStamp = DateTime.Now;
using (StreamReader iStream = new StreamReader(fileName))
{
string firstLine = iStream.ReadLine();
while (true)
{
string nextLine = iStream.ReadLine();
if (nextLine == null) break;
string[] fields = nextLine.Split(',');
if (fields.Length >= 6)
{
record.sn = fields[1];
record.status = (fields[5] == "OK") ? Status.Passed : Status.Failed;
}
}
log.InfoFormat("Succesfully parsed: {0}", record);
return record;
}
}
catch (Exception exc)
{
log.ErrorFormat("Cannot open or parse file {0}: {1}", fileName, exc.Message);
return null;
}
}
public override string ToString()
{
return string.Format("File={0} Housing s/n={1}, Rslt={2}", fileName, sn, status);
}
}
}