public void TestGetLineNumbersByIndices() { var source1 = new InMemoryLogSource(); source1.Add(new LogEntry { Timestamp = new DateTime(2017, 12, 20, 23, 1, 0) }); var source2 = new InMemoryLogSource(); source1.Add(new LogEntry { Timestamp = new DateTime(2017, 12, 20, 23, 0, 0) }); var logFile = new MergedLogSource(_taskScheduler, TimeSpan.Zero, source1, source2); _taskScheduler.RunOnce(); logFile.GetProperty(Core.Properties.LogEntryCount).Should().Be(2); var lineNumbers = logFile.GetColumn(new LogLineIndex[] { 1, 0 }, Core.Columns.LineNumber); lineNumbers[0].Should().Be(2); lineNumbers[1].Should().Be(1); lineNumbers = logFile.GetColumn(new LogLineIndex[] { 1, 0 }, Core.Columns.OriginalLineNumber); lineNumbers[0].Should().Be(2); lineNumbers[1].Should().Be(1); }
public void TestUpdateLineNumbers3() { var canvas = new DataSourceCanvas(TextSettings.Default); var multiDataSource = new Mock <IMultiDataSource>(); var dataSource0 = new Mock <IDataSource>(); dataSource0.Setup(x => x.FullFileName).Returns(@"A:\foo\bar.txt"); var dataSource1 = new Mock <IDataSource>(); dataSource1.Setup(x => x.FullFileName).Returns(@"B:\a really long file name.log"); multiDataSource.Setup(x => x.OriginalSources).Returns(new[] { dataSource0.Object, dataSource1.Object }); var mergedLogFile = new InMemoryLogSource(Columns.SourceId); mergedLogFile.Add(new Dictionary <IColumnDescriptor, object> { { Columns.SourceId, new LogEntrySourceId(1) }, { Columns.RawContent, "foo" } }); mergedLogFile.Add(new Dictionary <IColumnDescriptor, object> { { Columns.SourceId, new LogEntrySourceId(0) }, { Columns.RawContent, "bar" } }); multiDataSource.Setup(x => x.FilteredLogSource).Returns(mergedLogFile); canvas.UpdateDataSources(multiDataSource.Object, new LogSourceSection(0, 2), 0); canvas.DataSources.Should().HaveCount(2); canvas.DataSources[0].Should().NotBeNull(); canvas.DataSources[0].Text.Should().Be("a really long file nam"); canvas.DataSources[1].Should().NotBeNull(); canvas.DataSources[1].Text.Should().Be("bar.txt"); }
public void TestAddSeveralEntries() { var logFile = new InMemoryLogSource(); var index = new PresentationLogSource(_scheduler, logFile, TimeSpan.Zero, TextSettings.Default); logFile.Add(new LogEntry { RawContent = "Foo" }); _scheduler.RunOnce(); index.MaximumWidth.Should().BeApproximately(19.8, 0.1); index.LineCount.Should().Be(1); logFile.Add(new LogEntry { RawContent = "Hello,\r\nWorld!" }); _scheduler.RunOnce(); index.MaximumWidth.Should().BeApproximately(46.2, 0.1); index.LineCount.Should().Be(3); logFile.Add(new LogEntry { RawContent = "Bar" }); _scheduler.RunOnce(); index.MaximumWidth.Should().BeApproximately(46.2, 0.1); index.LineCount.Should().Be(4); }
public void TestOriginalDataSourceName1() { var source1 = new InMemoryLogSource(Core.Columns.OriginalDataSourceName); var source2 = new InMemoryLogSource(Core.Columns.OriginalDataSourceName); var merged = new MergedLogSource(_taskScheduler, TimeSpan.Zero, source1, source2); source1.Add(new Dictionary <IColumnDescriptor, object> { { Core.Columns.OriginalDataSourceName, "important_document.txt" }, { Core.Columns.Timestamp, new DateTime(2021, 02, 11, 23, 33, 10) } }); source2.Add(new Dictionary <IColumnDescriptor, object> { { Core.Columns.OriginalDataSourceName, "rubbish.log" }, { Core.Columns.Timestamp, new DateTime(2021, 02, 11, 23, 29, 10) } }); _taskScheduler.RunOnce(); merged.GetProperty(Core.Properties.LogEntryCount).Should().Be(2); var entries = merged.GetEntries(new LogSourceSection(0, 2)); entries[0].GetValue(Core.Columns.OriginalDataSourceName).Should().Be("rubbish.log"); entries[0].GetValue(Core.Columns.SourceId).Should().Be(new LogEntrySourceId(1)); entries[1].GetValue(Core.Columns.OriginalDataSourceName).Should().Be("important_document.txt"); entries[1].GetValue(Core.Columns.SourceId).Should().Be(new LogEntrySourceId(0)); entries = merged.GetEntries(new [] { new LogLineIndex(1), new LogLineIndex(0) }); entries[0].GetValue(Core.Columns.OriginalDataSourceName).Should().Be("important_document.txt"); entries[0].GetValue(Core.Columns.SourceId).Should().Be(new LogEntrySourceId(0)); entries[1].GetValue(Core.Columns.OriginalDataSourceName).Should().Be("rubbish.log"); entries[1].GetValue(Core.Columns.SourceId).Should().Be(new LogEntrySourceId(1)); }
public void TestFollowTail2() { _control.RaiseEvent(new RoutedEventArgs(FrameworkElement.LoadedEvent)); _control.LogSource = _logSource; DispatcherExtensions.ExecuteAllEvents(); var entries = new List <IReadOnlyLogEntry>(); for (int i = 0; i < 51; ++i) { entries.Add(new ReadOnlyLogEntry(new Dictionary <IColumnDescriptor, object> { { Columns.RawContent, "Foobar" }, { Columns.LogLevel, LevelFlags.Info } })); } _logSource.AddRange(entries); Thread.Sleep((int)(2 * LogEntryListView.MaximumRefreshInterval.TotalMilliseconds)); DispatcherExtensions.ExecuteAllEvents(); _control.FollowTail = true; _logSource.Add(new ReadOnlyLogEntry(new Dictionary <IColumnDescriptor, object> { { Columns.RawContent, "Foobar" }, { Columns.LogLevel, LevelFlags.Info } })); _control.OnLogFileModified(_logSource, LogSourceModification.Appended(0, _logSource.Count)); Thread.Sleep((int)(2 * LogEntryListView.MaximumRefreshInterval.TotalMilliseconds)); DispatcherExtensions.ExecuteAllEvents(); _control.VerticalScrollBar.Maximum.Should().Be(15, "Because the view is missing 15 pixels to fully display the last row"); _control.VerticalScrollBar.Value.Should().Be(15, "Because the vertical scrollbar should've moved in order to bring the last line *fully* into view"); }
public void TestDeltaTime() { var source = new InMemoryLogSource(); source.Add(new LogEntry { Timestamp = new DateTime(2021, 02, 20, 16, 45, 01) }); source.Add(new LogEntry { Timestamp = new DateTime(2021, 02, 20, 16, 46, 02) }); source.Add(new LogEntry { Timestamp = new DateTime(2021, 02, 20, 16, 46, 05) }); var adorner = new LogSourceColumnAdorner(source); var entries = adorner.GetEntries(new IColumnDescriptor[] { Core.Columns.DeltaTime }); entries.Should().HaveCount(3); entries[0].DeltaTime.Should().Be(null); entries[1].DeltaTime.Should().Be(TimeSpan.FromSeconds(61)); entries[2].DeltaTime.Should().Be(TimeSpan.FromSeconds(3)); }
public void TestOneLine() { var logFile = new InMemoryLogSource(); var index = new PresentationLogSource(_scheduler, logFile, TimeSpan.Zero, TextSettings.Default); logFile.Add(new LogEntry { RawContent = "Hello, World!" }); _scheduler.RunOnce(); index.MaximumWidth.Should().BeApproximately(85, 1); index.LineCount.Should().Be(1); }
public void TestUpdateLineNumbers4() { var canvas = new DataSourceCanvas(TextSettings.Default) { DisplayMode = DataSourceDisplayMode.CharacterCode }; var multiDataSource = new Mock <IMultiDataSource>(); var dataSource0 = new Mock <IDataSource>(); dataSource0.Setup(x => x.CharacterCode).Returns("FB"); var dataSource1 = new Mock <IDataSource>(); dataSource1.Setup(x => x.CharacterCode).Returns(@"TH"); multiDataSource.Setup(x => x.OriginalSources).Returns(new[] { dataSource0.Object, dataSource1.Object }); var mergedLogFile = new InMemoryLogSource(Columns.SourceId); mergedLogFile.Add(new Dictionary <IColumnDescriptor, object> { { Columns.SourceId, new LogEntrySourceId(1) }, { Columns.RawContent, "foo" } }); mergedLogFile.Add(new Dictionary <IColumnDescriptor, object> { { Columns.SourceId, new LogEntrySourceId(0) }, { Columns.RawContent, "bar" } }); multiDataSource.Setup(x => x.FilteredLogSource).Returns(mergedLogFile); canvas.UpdateDataSources(multiDataSource.Object, new LogSourceSection(0, 2), 0); canvas.DataSources.Should().HaveCount(2); canvas.DataSources[0].Should().NotBeNull(); canvas.DataSources[0].Text.Should().Be("TH"); canvas.DataSources[1].Should().NotBeNull(); canvas.DataSources[1].Text.Should().Be("FB"); }
public void TestAddEntry6() { var logFile = new InMemoryLogSource(Core.Columns.LogLevel); var logEntry = new LogEntry { LogLevel = LevelFlags.Error }; logFile.Add(logEntry); var buffer = new LogBufferArray(1, Core.Columns.LogLevel); logFile.GetEntries(new LogSourceSection(0, 1), buffer); buffer[0].LogLevel.Should().Be(LevelFlags.Error); }
public void TestCustomColumn() { var myCustomColumn = CreateCustomColumn <string>(null); var source1 = new InMemoryLogSource(); source1.Add(new LogEntry { RawContent = "What is up Munich?", Timestamp = new DateTime(2021, 02, 11, 22, 16, 49) }); var source2 = new InMemoryLogSource(myCustomColumn); var entry2 = new LogEntry { RawContent = "Everything", Timestamp = new DateTime(2021, 02, 11, 22, 15, 11) }; entry2.SetValue(myCustomColumn, "A very important piece of information"); source2.Add(entry2); var merged = new MergedLogSource(_taskScheduler, TimeSpan.Zero, new[] { source1, source2 }); _taskScheduler.RunOnce(); merged.GetProperty(Core.Properties.LogEntryCount).Should().Be(2); var entries = merged.GetEntries(new LogSourceSection(0, 2), new IColumnDescriptor[] { Core.Columns.RawContent, Core.Columns.Timestamp, Core.Columns.SourceId, myCustomColumn }); entries.Count.Should().Be(2); entries[0].RawContent.Should().Be("Everything"); entries[0].Timestamp.Should().Be(new DateTime(2021, 02, 11, 22, 15, 11)); entries[0].GetValue(Core.Columns.SourceId).Should().Be(new LogEntrySourceId(1), "because this log entry is from the second source of the log file"); entries[0].GetValue(myCustomColumn).Should().Be("A very important piece of information"); entries[1].RawContent.Should().Be("What is up Munich?"); entries[1].Timestamp.Should().Be(new DateTime(2021, 02, 11, 22, 16, 49)); entries[1].GetValue(Core.Columns.SourceId).Should().Be(new LogEntrySourceId(0), "because this log entry is from the first source of the log file"); entries[1].GetValue(myCustomColumn).Should().Be(myCustomColumn.DefaultValue, "because the first source doesn't have this column"); }