private void FindLastLinesInStream(Stream stream) { if (_lastLinesProcessed || Configs.LinesStartFrom != NumLinesStart.End) { return; } if (_startFromNum != 0) { var logicalLinesHistory = new LogicalLinesHistoryQueue( _startFromNum * (Configs.ContextLines + 1)); if (stream.CanSeek) { if (!ProcessStreamInPages(stream, logicalLinesHistory)) { // optimization is not working, try without optimization ResetCounters(); logicalLinesHistory.Clear(); ProcessStreamFromLastPosToEnd(stream, logicalLinesHistory); } } else { ProcessStreamFromLastPosToEnd(stream, logicalLinesHistory); } FlushLogicalLine(logicalLinesHistory); while (logicalLinesHistory.Any()) { var forPrinting = new LogicalLinesHistoryQueue(); PrepareLogicalLineForPrinting(logicalLinesHistory.Dequeue(), forPrinting); PrintLogicalLines(forPrinting); } } LastPos = FileSize; _lastLinesProcessed = true; }
private void PrintLogicalLines(LogicalLinesHistoryQueue logicalLines) { lock (_bl.PrintLock) { PrintFileName(); while (logicalLines.Any()) { var logicalLine = logicalLines.Dequeue(); if (!logicalLine.IsPrinted) { if (Configs.IsContextUsed && Math.Abs(logicalLine.LineNumber - _lastPrintedLine) > 1) { _bl.PrintLogicalLine(TailPbl.GetContextDelimiter(), _fileIndex); } _bl.PrintLogicalLine(logicalLine, _fileIndex); _lastPrintedLine = logicalLine.LineNumber; } } } }