public ParsedLine ParseAndAddSingleLine(LineTemplate lineTemplate, byte[] lineBytes, int flushThreshhold) { bool isSingleLine = true; this.ValidateInputParameters(lineTemplate, lineBytes, isSingleLine); ParsedLine parsedLine = new ParsedLine(lineTemplate, lineBytes); ParsedLine[] parsed = this.ParsedLines; if (parsed == null) { parsed = new ParsedLine[1]; } else { if (parsed.Length == flushThreshhold) { Array.Resize(ref parsed, 1); } else { Array.Resize(ref parsed, (parsed == null ? 0 : parsed.Length) + 1); } } parsed[parsed.Length - 1] = parsedLine; this.ParsedLines = parsed; return(parsedLine); }
/// <summary> /// Parses single line of binary data. /// </summary> /// <param name="lineTemplate">Template</param> /// <param name="lineBytes">Source bytes</param> /// <returns>Single parsed line</returns> public ParsedLine ParseSingleLine(LineTemplate lineTemplate, byte[] lineBytes) { bool isSingleLine = true; this.ValidateInputParameters(lineTemplate, lineBytes, isSingleLine); ParsedLine parsedLine = new ParsedLine(lineTemplate, lineBytes); return(parsedLine); }
/// <summary> /// Parses multiple lines of binary data. /// </summary> /// <param name="lineTemplate">Template</param> /// <param name="allBytes">Source file bytes</param> /// <returns>Array of parsed lines</returns> public ParsedLine[] ParseAllLines(LineTemplate lineTemplate, byte[] allBytes) { Console.WriteLine("{0}: Parsing...", DateTime.Now); this.ValidateInputParameters(lineTemplate, allBytes, false); double expectedRows = (double)allBytes.Length / lineTemplate.LineSize; if (expectedRows % 1 == 0) { Console.WriteLine("{1}: Line count est {0:#,###.00}", expectedRows, DateTime.Now); } byte[] lineBytes = new byte[lineTemplate.LineSize]; ParsedLine[] linesList = new ParsedLine[Convert.ToInt32(expectedRows)]; ParsedLine parsedLine = null; int lineIndex = 0; for (int i = 0; i < allBytes.Length; i += lineTemplate.LineSize) { try { Array.Copy(allBytes, i, lineBytes, 0, lineTemplate.LineSize); parsedLine = this.ParseSingleLine(lineTemplate, lineBytes); if (parsedLine != null) { linesList[lineIndex] = parsedLine; } lineIndex++; if (lineIndex % 1000 == 0) { Console.Write(lineIndex + "\r"); } } catch (Exception ex) { //Used for dubugging Console.WriteLine("Exception at line index {0}", lineIndex); throw ex; } } Console.WriteLine("{1}: {0} line(s) have been parsed", linesList.Count(), DateTime.Now); return(linesList); }
public ParsedLine ParseSingleLine(LineTemplate lineTemplate, byte[] lineBytes) { bool isSingleLine = true; this.ValidateInputParameters(lineTemplate, lineBytes, isSingleLine); ParsedLine parsedLine = new ParsedLine(lineTemplate, lineBytes); return parsedLine; }