Ejemplo n.º 1
0
 private string GetLogEntryText(LogEntry logEntry)
 {
     using (var mmf = MemoryMappedFile.CreateFromFile(filePath, FileMode.Open))
     using (var viewStream = mmf.CreateViewStream(logEntry.Position, logEntry.Size, MemoryMappedFileAccess.Read))
     using (var reader = new StreamReader(viewStream))
     {
         return reader.ReadToEnd();
     }
 }
Ejemplo n.º 2
0
        private void ReadFileToEnd()
        {
            var fileSize = new FileInfo(filePath).Length;
            var size = fileSize - currentFilePosition;
            if (size <= 0) return;

            var newEntries = new List<LogEntry>();

            using (var mmf = MemoryMappedFile.CreateFromFile(filePath, FileMode.Open))
            using (var viewStream = mmf.CreateViewStream(currentFilePosition, size, MemoryMappedFileAccess.Read))
            using(var reader = new BinaryReader(viewStream))
            {
                var startPosition = currentFilePosition;
                var lastChar = ' ';

                while (reader.PeekChar() != -1)
                {
                    var newChar = reader.ReadChar();
                    if (lastChar == '\r' && newChar == '\n')
                    {
                        newEntries.Add(new LogEntry(startPosition, currentFilePosition - startPosition, logEntryIndex++));
                        startPosition = currentFilePosition;
                    }
                    lastChar = newChar;
                    currentFilePosition++;
                }
            }
            foreach (var newEntry in newEntries)
            {
                Entries.Add(newEntry);
            }
            SelectedLogEntry = Entries.LastOrDefault();
        }
Ejemplo n.º 3
0
 void FileDeleted(object sender, FileSystemEventArgs e)
 {
     dispatcher.Invoke(() =>
     {
         Entries.Clear();
         SelectedLogEntry = null;
         currentFilePosition = 0;
         logEntryIndex = 0;
     });
 }