public static FeederRecord FromLogLine(String logLine) { var result = new FeederRecord(); try { if (String.IsNullOrWhiteSpace(logLine)) { return(null); } string[] fields = logLine.Split(','); if (fields[(int)FeederRecordField.FeederId] == "0") { return(null); } if (fields.Length == 8) { result.FeederName = fields[(int)FeederRecordField.FeederName]; result.Name = fields[(int)FeederRecordField.Name - 1]; result.PickupAmount = TryParse(fields[(int)FeederRecordField.PickupAmount - 1]); result.PickupMissedAmount = TryParse(fields[(int)FeederRecordField.PickupMissedAmount - 1]); result.PlacedAmount = TryParse(fields[(int)FeederRecordField.PlacedAmount - 1]); result.DumpedAmount = TryParse(fields[(int)FeederRecordField.DumpedAmount - 1]); result.Unknown1 = TryParse(fields[(int)FeederRecordField.Unknown1 - 1]); result.PartNG = TryParse(fields[(int)FeederRecordField.PartNG - 1]); } else if (fields.Length == 9) { result.FeederName = fields[(int)FeederRecordField.FeederName]; result.Name = fields[(int)FeederRecordField.Name]; result.PickupAmount = TryParse(fields[(int)FeederRecordField.PickupAmount]); result.PickupMissedAmount = TryParse(fields[(int)FeederRecordField.PickupMissedAmount]); result.PlacedAmount = TryParse(fields[(int)FeederRecordField.PlacedAmount]); result.DumpedAmount = TryParse(fields[(int)FeederRecordField.DumpedAmount]); result.Unknown1 = TryParse(fields[(int)FeederRecordField.Unknown1]); result.PartNG = TryParse(fields[(int)FeederRecordField.PartNG]); } else { throw new FormatException(); } } catch (Exception e) { throw new FormatException("Fail to parse log record: " + logLine + "; 8 or 9 fields expected"); } return(result); }
public void AppendRecord(FeederRecordType recordType, FeederRecord record) { switch (recordType) { case FeederRecordType.TapeSection: this.TapeRecords.Add(record); break; case FeederRecordType.StickSection: this.StickRecords.Add(record); break; case FeederRecordType.TraySection: this.TrayRecords.Add(record); break; } }
public FeedersInfo ParseLogFile(string pathToLogFile) { var result = new FeedersInfo(); using (FileStream fs = File.OpenRead(pathToLogFile)) { string[] logFileLines = File.ReadAllLines(pathToLogFile, System.Text.Encoding.GetEncoding(1251)); if (IsSM421RawLog(logFileLines) == false) { String ErrMsg = "Input file " + pathToLogFile + " has incorrect format. "; ErrMsg += "Correct log identified by 'Power Time' text on first row. "; ErrMsg += "Second row is also a possibility if first row contains VERSION label"; throw new FormatException(ErrMsg); } FeederRecordType?currentSection = null; foreach (String line in logFileLines) { var lineType = GetRecordType(line); if (lineType != FeederRecordType.Record) { currentSection = lineType; continue; } if (currentSection == null || currentSection == FeederRecordType.NozzleSection) { continue; } else { var record = FeederRecord.FromLogLine(line); if (record != null && currentSection.HasValue) { result.AppendRecord(currentSection.Value, record); } } } } return(result); }