private void OnViewModelLogMessage(object sender, LogEntryEventArgs e) { Dispatcher.BeginInvoke(new Action(() => { var vm = (LogViewerViewModel)sender; var logEntries = e.LogEntries; foreach (var logEntry in logEntries) { if (vm.IsValidLogEntry(logEntry)) { var document = LogRecordsRichTextBox.Document; var lastLogMessage = (DateTime)document.Tag; if (logEntry.Time < lastLogMessage) { // Always ignore, old message return; } else if (logEntry.Time == lastLogMessage) { // This looks like hurting for performance, but there aren't many messages on exactly the same time for (int i = document.Blocks.Count - 1; i >= 0; i--) { var existingParagraph = document.Blocks.ElementAt(i) as RichTextBoxParagraph; if (existingParagraph != null) { var paragraphLogEntry = existingParagraph.LogEntry; if (paragraphLogEntry.Time < logEntry.Time) { // We hit an older one, the message is not yet added break; } if (ReferenceEquals(paragraphLogEntry, logEntry)) { // Already added, ignore return; } } } } var paragraph = CreateLogEntryParagraph(logEntry); if (paragraph != null) { document.Blocks.Add(paragraph); document.Tag = logEntry.Time; } } } ScrollToEnd(); })); }
private void OnViewModelLogMessage(object sender, LogEntryEventArgs e) { Dispatcher.BeginInvoke(new Action(() => { var vm = (LogViewerViewModel)sender; var logEntries = e.LogEntries; foreach (var logEntry in logEntries) { if (vm.IsValidLogEntry(logEntry)) { var document = LogRecordsRichTextBox.Document; var lastLogMessage = (DateTime) document.Tag; if (logEntry.Time < lastLogMessage) { // Always ignore, old message return; } else if (logEntry.Time == lastLogMessage) { // This looks like hurting for performance, but there aren't many messages on exactly the same time for (int i = document.Blocks.Count - 1; i >= 0; i--) { var existingParagraph = document.Blocks.ElementAt(i) as RichTextBoxParagraph; if (existingParagraph != null) { var paragraphLogEntry = existingParagraph.LogEntry; if (paragraphLogEntry.Time < logEntry.Time) { // We hit an older one, the message is not yet added break; } if (ReferenceEquals(paragraphLogEntry, logEntry)) { // Already added, ignore return; } } } } var paragraph = CreateLogEntryParagraph(logEntry); if (paragraph != null) { document.Blocks.Add(paragraph); document.Tag = logEntry.Time; } } } ScrollToEnd(); })); }
private void OnViewModelLogMessage(object sender, LogEntryEventArgs e) { UpdateControl(false, e.FilteredLogEntries); }