Exemplo n.º 1
0
 private void IndexLines()
 {
     encoding = LogReader.DetectEncoding(FilePath);
     lines    = new List <Line>();
     using (var reader = new LogReader(FilePath, encoding))
     {
         encoding = reader.Encoding;
         IndexLines(reader);
     }
 }
Exemplo n.º 2
0
        private void AddLine(long currentLineIndex, LogReader reader)
        {
            var line = new Line {
                Index = currentLineIndex, Length = (int)(reader.Index - currentLineIndex)
            };

            lines.Add(line);
            if (line.Length > maxLineLength)
            {
                maxLineLength = line.Length;
            }
        }
Exemplo n.º 3
0
        private void UpdateIndex()
        {
            if (lines.Count == 0 || lines[lines.Count - 1].Index == 0)
            {
                IndexLines();
                return;
            }

            using (var reader = new LogReader(FilePath, encoding, lines[lines.Count - 1].Index))
            {
                lines.RemoveAt(lines.Count - 1);
                IndexLines(reader);
            }
        }
Exemplo n.º 4
0
        private void IndexLines(LogReader reader)
        {
            long currentLineIndex = reader.Index;

            reader.ReadLine();
            while (reader.CurrentByte != -1)
            {
                AddLine(currentLineIndex, reader);
                currentLineIndex = reader.Index;
                reader.ReadLine();
            }

            if (reader.Index > currentLineIndex)
            {
                // Last data is a line, even if there is no newline
                AddLine(currentLineIndex, reader);
            }
        }