/// /// Copyright (c) 2019 Sensus Slovensko a.s. /// using System; using System.Globalization; using System.IO; using System.Xml; using log4net; using Oracle.DataAccess.Client; namespace RecordProcessing.Records { public class FlowtubeTestAirRecord : IRecord { static readonly ILog log = LogManager.GetLogger(typeof(FlowtubeTestAirRecord)); 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 ResultStr { get { return string.Format("({0} {1})", string.IsNullOrEmpty(Leakage_Value) ? "" : Leakage_Value, string.IsNullOrEmpty(Leakage_Unit) ? "" : Leakage_Unit); } } public string Remark { get { return string.IsNullOrEmpty(remark) ? string.Empty : remark; } } string fileName; string sn; DateTime timeStamp; Status status; string productName; string remark; public double TestTime; /// [s] public string Leakage_Value; public string Leakage_LoLim; public string Leakage_HiLim; public string Leakage_Unit; public int ReferenceRecordsCount; public FlowtubeTestAirRecord() { sn = null; /// Initially there is no PCB number } /// /// Load a record from an xml-file /// /// xml-filename /// Record or null public static FlowtubeTestAirRecord FromFile(string fileName) { try { string bareFileName = System.IO.Path.GetFileName(fileName).Replace(".xml", ""); using (Stream inputStream = File.OpenRead(fileName)) { return FromFile(inputStream, bareFileName); } } catch (Exception exc) { log.ErrorFormat("Cannot open file {0}: {1}", fileName, exc.Message); return null; } } /// /// Load a record from a file stream (XML file format) /// /// Input stream /// Filename for doc. purpose only /// Record public static FlowtubeTestAirRecord FromFile(Stream inputStream, string bareFileName) { FlowtubeTestAirRecord record = new FlowtubeTestAirRecord(); record.fileName = bareFileName; try { string[] fields = record.fileName.Split(new char[] { '_' }); string dateTimeEtc = fields[fields.Length - 2]; int yyyy = int.Parse(dateTimeEtc.Substring(0, 4)); int mo = int.Parse(dateTimeEtc.Substring(4, 2)); int dd = int.Parse(dateTimeEtc.Substring(6, 2)); int hh = int.Parse(dateTimeEtc.Substring(8, 2)); int mi = int.Parse(dateTimeEtc.Substring(10, 2)); int ss = int.Parse(dateTimeEtc.Substring(12, 2)); record.timeStamp = new DateTime(yyyy, mo, dd, hh, mi, ss); XmlDocument xDoc = new XmlDocument(); xDoc.Load(inputStream); bool testResultFound = false; foreach (XmlNode node in xDoc.DocumentElement.ChildNodes) { if (node.Name == "PRODUCT") { record.productName = node.Attributes["NAME"].Value; } else if (node.Name == "REFS") { record.remark = node.Attributes["SEQ_REF"].Value; } else if (node.Name == "PANEL") { foreach (XmlNode sNode in node.ChildNodes) { if (sNode.Name != "DUT") continue; record.sn = sNode.Attributes["ID"].Value; string statusStr = sNode.Attributes["STATUS"].Value; if (statusStr.ToLower().Equals("passed")) { record.status = Status.Passed; } else if (statusStr.ToLower().Equals("failed")) { record.status = Status.Failed; } else { record.status = Status.Interrupted; } record.TestTime = double.Parse(sNode.Attributes["TESTTIME"].Value, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture); if (testResultFound) continue; /// /// Search for RF_Power test result /// foreach (XmlNode ssNode in sNode.ChildNodes) { if (ssNode.Name != "GROUP") continue; foreach (XmlNode sssNode in ssNode.ChildNodes) { if (sssNode.Name != "GROUP" || !sssNode.HasChildNodes) continue; foreach (XmlNode ssssNode in sssNode.ChildNodes) { if (ssssNode.Name != "GROUP" || !ssssNode.HasChildNodes || !ssssNode.Attributes["NAME"].Value.Contains("Leakage")) continue; foreach (XmlNode terminalNode in ssssNode.ChildNodes) { if ((terminalNode.Name == "TEST") && (terminalNode.Attributes["NAME"].Value.Contains("Leakage")) && !string.IsNullOrEmpty(terminalNode.Attributes["UNIT"].Value) && !string.IsNullOrEmpty(terminalNode.Attributes["VALUE"].Value) && !string.IsNullOrEmpty(terminalNode.Attributes["LOLIM"].Value) && !string.IsNullOrEmpty(terminalNode.Attributes["HILIM"].Value) && !string.IsNullOrEmpty(terminalNode.Attributes["STATUS"].Value)) { record.Leakage_Unit = terminalNode.Attributes["UNIT"].Value; record.Leakage_Value = terminalNode.Attributes["VALUE"].Value; record.Leakage_LoLim = terminalNode.Attributes["LOLIM"].Value; record.Leakage_HiLim = terminalNode.Attributes["HILIM"].Value; testResultFound = true; break; } } } } if (testResultFound) break; } } } } } catch (Exception exc) { log.ErrorFormat("Cannot parse file {0}: {1}", record.fileName, exc.Message); return null; } return record; } public bool CanSaveRecordToOracle() { return false; } public bool SaveRecordToOracle(OracleConnection oraConn) { return false; } public bool CanPrintRecord() { return false; } public bool PrintRecord() { return false; } public override string ToString() { return string.Format("File={0} PcbNr={1}({2}), Rslt={3}, RF_Power={4} {5}", fileName, sn, ReferenceRecordsCount, status, Leakage_Value, Leakage_Unit); } } }