} // ctor private async Task FetchLinesAsync() { var buffer = new LogLineBuffer(this); await LogLine.GetLogLinesAsync(http, path, 0, Int32.MaxValue, (_, log) => buffer.Add(log)); lastLineCount = Count; buffer.Flush(); } // proc FetchLinesAsync
private static bool TryParseLogcat(string line, LogLineBuffer buffer) { if (line.StartsWith("--------- beginning of")) { buffer.Stage(new LogLine(LogMsgType.Information, DateTime.MinValue, line.TrimStart('-', ' '))); return(true); } else { var m = logcatLine.Match(line); if (m.Success) { var dt = new DateTime( year: DateTime.Now.Year, month: Int32.Parse(m.Groups["mo"].Value), day: Int32.Parse(m.Groups["d"].Value), hour: Int32.Parse(m.Groups["h"].Value), minute: Int32.Parse(m.Groups["mi"].Value), second: Int32.Parse(m.Groups["s"].Value), millisecond: Int32.Parse(m.Groups["f"].Value) ); LogMsgType typ; switch (m.Groups["typ"].Value) { case "E": typ = LogMsgType.Error; break; case "W": typ = LogMsgType.Warning; break; case "D": typ = LogMsgType.Debug; break; default: typ = LogMsgType.Information; break; } buffer.PatchDate(dt); buffer.Add(new LogLine(typ, dt, m.Groups["text"].Value)); return(true); } else { return(false); } } } // func TryParseLogcat
} // func TryParseLogcat private async Task FetchLinesAsync(string fileName) { using (var src = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) using (var tr = new StreamReader(src, Encoding.Default, true)) { var buf = new LogLineBuffer(this); var state = 0; string line; while ((line = await tr.ReadLineAsync()) != null) { if (state == 0) { if (TryParseLogcat(line, buf)) { state = 2; } else { LogLineParser.Parse(line, out var typ, out var stamp, out var text); if (text != null) // valid log format { buf.Add(new LogLine(typ, stamp, text)); state = 1; } else { buf.Add(new LogLine(LogMsgType.Information, DateTime.MinValue, line)); state = 10; } } } else if (state == 1) // parse valid log { LogLineParser.Parse(line, out var typ, out var stamp, out var text); buf.Add(new LogLine(typ, stamp, text)); } else if (state == 2) { TryParseLogcat(line, buf); } else { buf.Add(new LogLine(LogMsgType.Information, DateTime.MinValue, line)); } } buf.Flush(); } } // proc FetchLinesAsync
} // proc FetchLinesAsync private async Task FetchNextAsync(int nextLineCount) { if (lastLineCount < nextLineCount) // log not truncated calculate difference { var count = nextLineCount - lastLineCount; if (count > 0) { var buffer = new LogLineBuffer(this); await LogLine.GetLogLinesAsync(http, path, lastLineCount, count, (_, log) => buffer.Add(log)); lastLineCount = count + lastLineCount; buffer.Flush(); } } else // fetch all { Clear(); await FetchLinesAsync(); } } // func FetchNextAsync