} // 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
} // 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