Пример #1
0
        public void TestDataSourceOrder()
        {
            var logFile2 = new InMemoryLogSource();
            var source2  = new FileDataSource(_taskScheduler,
                                              new DataSource {
                Id = DataSourceId.CreateNew()
            },
                                              logFile2,
                                              TimeSpan.Zero);

            var logFile1 = new InMemoryLogSource();
            var source1  = new FileDataSource(_taskScheduler,
                                              new DataSource {
                Id = DataSourceId.CreateNew()
            },
                                              logFile1,
                                              TimeSpan.Zero);

            var logFile3 = new InMemoryLogSource();
            var source3  = new FileDataSource(_taskScheduler,
                                              new DataSource {
                Id = DataSourceId.CreateNew()
            },
                                              logFile3,
                                              TimeSpan.Zero);

            _merged.SetDataSources(new [] { source1, source2, source3 });
            var mergedLogFile = GetMergedLogFile();

            mergedLogFile.Sources.Should().Equal(logFile1, logFile2, logFile3);
        }
Пример #2
0
        public void TestSelectMultipleLinesWithKeyboard4()
        {
            var logFile = new InMemoryLogSource(_columns);

            logFile.AddEntry("Hello", LevelFlags.Other);
            logFile.AddEntry("World", LevelFlags.Other);
            logFile.AddEntry("How's it going?", LevelFlags.Other);

            _control.LogSource = logFile;
            _control.UpdateVisibleSection();
            _control.UpdateVisibleLines();

            _mouse.LeftClickAt(_control, new Point(10, 40));
            _control.SelectedIndices.Should().Equal(new LogLineIndex(2));

            _keyboard.Press(Key.LeftShift);
            _keyboard.Click(_control, Key.Up);
            _control.SelectedIndices.Should().Equal(new LogLineIndex(1), new LogLineIndex(2));

            _keyboard.Click(_control, Key.Up);
            _control.SelectedIndices.Should().Equal(new LogLineIndex(0), new LogLineIndex(1), new LogLineIndex(2));

            // We're now moving "beyond" the first item
            _keyboard.Click(_control, Key.Up);
            _control.SelectedIndices.Should().Equal(new LogLineIndex(0), new LogLineIndex(1), new LogLineIndex(2));

            _keyboard.Click(_control, Key.Down);
            _control.SelectedIndices.Should().Equal(new LogLineIndex(1), new LogLineIndex(2));
        }
Пример #3
0
        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");
        }
Пример #4
0
        public void TestAppendOneSourceThreeOneLinesOneWithoutTimestamp()
        {
            var source = new InMemoryLogSource();

            source.AddEntry("A", LevelFlags.Other, new DateTime(2019, 5, 28, 19, 30, 1));
            source.AddEntry("B", LevelFlags.Other);
            source.AddEntry("C", LevelFlags.Other, new DateTime(2019, 5, 28, 19, 30, 42));

            var index   = new MergedLogSourceIndex(source);
            var changes = index.Process(new MergedLogSourcePendingModification(source, LogSourceModification.Appended(0, 3)));

            changes.Should().Equal(new object[] { LogSourceModification.Appended(0, 2) });

            index.Count.Should().Be(2);

            var indices = index.Get(new LogSourceSection(0, 2));

            indices.Count.Should().Be(2);
            indices[0].SourceId.Should().Be(0);
            indices[0].SourceLineIndex.Should().Be(0);
            indices[0].OriginalLogEntryIndex.Should().Be(0);
            indices[0].MergedLogEntryIndex.Should().Be(0);
            indices[0].Timestamp.Should().Be(new DateTime(2019, 5, 28, 19, 30, 1));

            indices[1].SourceId.Should().Be(0);
            indices[1].SourceLineIndex.Should().Be(2);
            indices[1].OriginalLogEntryIndex.Should().Be(2);
            indices[1].MergedLogEntryIndex.Should().Be(1);
            indices[1].Timestamp.Should().Be(new DateTime(2019, 5, 28, 19, 30, 42));
        }
Пример #5
0
 public void Setup()
 {
     _logSource  = new InMemoryLogSource();
     _dataSource = new Mock <IDataSource>();
     _dataSource.Setup(x => x.UnfilteredLogSource).Returns(_logSource);
     _bookmarks = new Mock <IBookmarks>();
 }
Пример #6
0
        public void TestAppendOneSourceTwoIdenticalTimestamps()
        {
            var source = new InMemoryLogSource();

            source.AddEntry("A", LevelFlags.Other, new DateTime(2019, 5, 29, 00, 11, 0));
            source.AddEntry("B", LevelFlags.Other, new DateTime(2019, 5, 29, 00, 11, 2));
            source.AddEntry("C1", LevelFlags.Other, new DateTime(2019, 5, 29, 00, 11, 4));
            source.AddEntry("C2", LevelFlags.Other, new DateTime(2019, 5, 29, 00, 11, 4));
            source.AddEntry("D", LevelFlags.Other, new DateTime(2019, 5, 29, 00, 11, 6));
            source.AddEntry("E", LevelFlags.Other, new DateTime(2019, 5, 29, 00, 11, 8));

            var index = new MergedLogSourceIndex(source);

            index.Process(new MergedLogSourcePendingModification(source, LogSourceModification.Appended(0, 6)));

            var indices = index.Get(new LogSourceSection(0, 6));

            indices[0].SourceId.Should().Be(0);
            indices[0].SourceLineIndex.Should().Be(0);

            indices[1].SourceId.Should().Be(0);
            indices[1].SourceLineIndex.Should().Be(1);

            indices[2].SourceId.Should().Be(0);
            indices[2].SourceLineIndex.Should().Be(2);

            indices[3].SourceId.Should().Be(0);
            indices[3].SourceLineIndex.Should().Be(3);

            indices[4].SourceId.Should().Be(0);
            indices[4].SourceLineIndex.Should().Be(4);

            indices[5].SourceId.Should().Be(0);
            indices[5].SourceLineIndex.Should().Be(5);
        }
Пример #7
0
        public void TestOneSourceManySameTimestamps()
        {
            var source = new InMemoryLogSource();

            source.AddEntry("A", LevelFlags.Other, new DateTime(2017, 9, 20, 15, 09, 02, 053));
            source.AddEntry("B", LevelFlags.Other, new DateTime(2017, 9, 20, 15, 09, 02, 100));
            source.AddEntry("C", LevelFlags.Other, new DateTime(2017, 9, 20, 15, 09, 02, 100));
            source.AddEntry("D", LevelFlags.Other, new DateTime(2017, 9, 20, 15, 09, 02, 100));
            source.AddEntry("E", LevelFlags.Other, new DateTime(2017, 9, 20, 15, 09, 02, 115));
            source.AddEntry("F", LevelFlags.Other, new DateTime(2017, 9, 20, 15, 09, 02, 115));
            source.AddEntry("G", LevelFlags.Other, new DateTime(2017, 9, 20, 15, 09, 02, 115));
            source.AddEntry("H", LevelFlags.Other, new DateTime(2017, 9, 20, 15, 09, 02, 115));

            var index = new MergedLogSourceIndex(source);

            index.Process(new MergedLogSourcePendingModification(source, LogSourceModification.Appended(0, 8)));

            var indices = index.Get(new LogSourceSection(0, 8));

            indices[0].SourceLineIndex.Should().Be(0);
            indices[1].SourceLineIndex.Should().Be(1);
            indices[2].SourceLineIndex.Should().Be(2);
            indices[3].SourceLineIndex.Should().Be(3);
            indices[4].SourceLineIndex.Should().Be(4);
            indices[5].SourceLineIndex.Should().Be(5);
            indices[6].SourceLineIndex.Should().Be(6);
            indices[7].SourceLineIndex.Should().Be(7);
        }
Пример #8
0
        public void TestMerge5()
        {
            var source0 = new InMemoryLogSource();
            var source1 = new InMemoryLogSource();

            var merged  = new MergedLogSource(_taskScheduler, TimeSpan.Zero, source0, source1);
            var entries = Listen(merged);

            var later   = new DateTime(2016, 2, 16);
            var earlier = new DateTime(2016, 2, 15);

            source0.AddEntry("a", LevelFlags.Warning, later);

            _taskScheduler.RunOnce();
            merged.GetProperty(Core.Properties.PercentageProcessed).Should().Be(Percentage.HundredPercent);

            source1.AddEntry("c", LevelFlags.Error, earlier);

            _taskScheduler.RunOnce();
            merged.GetProperty(Core.Properties.PercentageProcessed).Should().Be(Percentage.HundredPercent);
            merged.GetProperty(Core.Properties.LogEntryCount).Should().Be(2);
            entries.Count.Should().Be(2);
            entries[0].Index.Should().Be(0);
            entries[0].LogEntryIndex.Should().Be(0);
            entries[0].GetValue(Core.Columns.SourceId).Should().Be(new LogEntrySourceId(1));
            entries[0].RawContent.Should().Be("c");
            entries[0].LogLevel.Should().Be(LevelFlags.Error);
            entries[0].Timestamp.Should().Be(earlier);
            entries[1].Index.Should().Be(1);
            entries[1].LogEntryIndex.Should().Be(1);
            entries[1].GetValue(Core.Columns.SourceId).Should().Be(new LogEntrySourceId(0));
            entries[1].RawContent.Should().Be("a");
            entries[1].LogLevel.Should().Be(LevelFlags.Warning);
            entries[1].Timestamp.Should().Be(later);
        }
Пример #9
0
        public void TestMergeResetOneSource()
        {
            var source1 = new InMemoryLogSource();

            var source2 = new InMemoryLogSource();

            var merged  = new MergedLogSource(_taskScheduler, TimeSpan.Zero, source1, source2);
            var entries = Listen(merged);
            var changes = ListenToChanges(merged, 100);

            source2.AddEntry("a", LevelFlags.Warning, new DateTime(2021, 2, 28, 22, 15, 0));
            source1.AddEntry("b", LevelFlags.Info, new DateTime(2021, 2, 28, 22, 16, 0));
            source2.AddEntry("c", LevelFlags.Error, new DateTime(2021, 2, 28, 22, 17, 0));

            _taskScheduler.RunOnce();
            merged.GetProperty(Core.Properties.PercentageProcessed).Should().Be(Percentage.HundredPercent);
            entries.Count.Should().Be(3);
            changes.Should().Equal(new object[] { LogSourceModification.Reset(), LogSourceModification.Appended(0, 3) });


            source1.Clear();
            _taskScheduler.RunOnce();
            entries.Count.Should().Be(2, "because the one entry from source should have been removed from the merged source");
            changes.Should().Equal(new object[] { LogSourceModification.Reset(), LogSourceModification.Appended(0, 3), LogSourceModification.Removed(1, 2), LogSourceModification.Appended(1, 1) });
        }
Пример #10
0
        public void TestMerge3()
        {
            var source0 = new InMemoryLogSource();
            var source1 = new InMemoryLogSource();
            var merged  = new MergedLogSource(_taskScheduler, TimeSpan.Zero, source0, source1);
            var entries = Listen(merged);

            DateTime timestamp = DateTime.Now;

            source0.AddEntry("a", LevelFlags.Info, timestamp);

            _taskScheduler.RunOnce();
            merged.GetProperty(Core.Properties.PercentageProcessed).Should().Be(Percentage.HundredPercent);

            source1.AddEntry("b", LevelFlags.Debug, timestamp);

            _taskScheduler.RunOnce();
            merged.GetProperty(Core.Properties.PercentageProcessed).Should().Be(Percentage.HundredPercent);
            merged.GetProperty(Core.Properties.LogEntryCount).Should().Be(2);
            entries.Count.Should().Be(2);
            entries[0].Index.Should().Be(0);
            entries[0].OriginalIndex.Should().Be(0);
            entries[0].LogEntryIndex.Should().Be(0);
            entries[0].GetValue(Core.Columns.SourceId).Should().Be(new LogEntrySourceId(0));
            entries[0].RawContent.Should().Be("a");
            entries[0].LogLevel.Should().Be(LevelFlags.Info);
            entries[0].Timestamp.Should().Be(timestamp);
            entries[1].Index.Should().Be(1);
            entries[1].OriginalIndex.Should().Be(1);
            entries[1].LogEntryIndex.Should().Be(1);
            entries[1].GetValue(Core.Columns.SourceId).Should().Be(new LogEntrySourceId(1));
            entries[1].RawContent.Should().Be("b");
            entries[1].LogLevel.Should().Be(LevelFlags.Debug);
            entries[1].Timestamp.Should().Be(timestamp);
        }
Пример #11
0
        public void TestMerge4()
        {
            var source1 = new InMemoryLogSource();
            var source2 = new InMemoryLogSource();
            var merged  = new MergedLogSource(_taskScheduler, TimeSpan.Zero, source1, source2);
            var entries = Listen(merged);

            source1.AddEntry("a", LevelFlags.Warning, new DateTime(2019, 5, 28, 22, 40, 0));
            source1.AddEntry("b", LevelFlags.Info);
            source1.AddEntry("c", LevelFlags.Error, new DateTime(2019, 5, 28, 22, 41, 0));

            _taskScheduler.RunOnce();
            merged.GetProperty(Core.Properties.LogEntryCount).Should().Be(2);
            entries.Count.Should().Be(2);
            entries[0].Index.Should().Be(0);
            entries[0].OriginalIndex.Should().Be(0);
            entries[0].LogEntryIndex.Should().Be(0);
            entries[0].RawContent.Should().Be("a");
            entries[0].LogLevel.Should().Be(LevelFlags.Warning);
            entries[0].Timestamp.Should().Be(new DateTime(2019, 5, 28, 22, 40, 0));
            entries[1].Index.Should().Be(1);
            entries[1].OriginalIndex.Should().Be(1);
            entries[1].LogEntryIndex.Should().Be(1);
            entries[1].RawContent.Should().Be("c");
            entries[1].LogLevel.Should().Be(LevelFlags.Error);
            entries[1].Timestamp.Should().Be(new DateTime(2019, 5, 28, 22, 41, 0));
        }
Пример #12
0
        public void TestMerge2()
        {
            var source1 = new InMemoryLogSource();
            var source2 = new InMemoryLogSource();
            var merged  = new MergedLogSource(_taskScheduler, TimeSpan.Zero, source1, source2);
            var entries = Listen(merged);

            source1.AddEntry("a", LevelFlags.Info, new DateTime(2019, 5, 28, 21, 59, 0));
            source1.AddEntry("b", LevelFlags.Debug, new DateTime(2019, 5, 28, 22, 0, 0));

            _taskScheduler.RunOnce();
            merged.GetProperty(Core.Properties.LogEntryCount).Should().Be(2);
            entries.Count.Should().Be(2);
            entries[0].Index.Should().Be(0);
            entries[0].LogEntryIndex.Should().Be(0);
            entries[0].RawContent.Should().Be("a");
            entries[0].LogLevel.Should().Be(LevelFlags.Info);
            entries[0].Timestamp.Should().Be(new DateTime(2019, 5, 28, 21, 59, 0));
            entries[0].ElapsedTime.Should().Be(TimeSpan.Zero);
            entries[0].DeltaTime.Should().BeNull();
            entries[1].Index.Should().Be(1);
            entries[1].LogEntryIndex.Should().Be(1);
            entries[1].RawContent.Should().Be("b");
            entries[1].LogLevel.Should().Be(LevelFlags.Debug);
            entries[1].Timestamp.Should().Be(new DateTime(2019, 5, 28, 22, 0, 0));
            entries[1].ElapsedTime.Should().Be(TimeSpan.FromMinutes(1));
            entries[1].DeltaTime.Should().Be(TimeSpan.FromMinutes(1));
        }
Пример #13
0
        public void TestCopyFromLogFile_Contiguous()
        {
            var entries = new LogBufferList(Core.Columns.RawContent);

            entries.Add(new ReadOnlyLogEntry(new Dictionary <IColumnDescriptor, object> {
                { Core.Columns.RawContent, "I" }
            }));
            entries.Add(new ReadOnlyLogEntry(new Dictionary <IColumnDescriptor, object> {
                { Core.Columns.RawContent, "want" }
            }));
            entries.Add(new ReadOnlyLogEntry(new Dictionary <IColumnDescriptor, object> {
                { Core.Columns.RawContent, "a" }
            }));
            entries.Add(new ReadOnlyLogEntry(new Dictionary <IColumnDescriptor, object> {
                { Core.Columns.RawContent, "Clondyke" }
            }));
            entries.Add(new ReadOnlyLogEntry(new Dictionary <IColumnDescriptor, object> {
                { Core.Columns.RawContent, "Bar" }
            }));

            var logFile = new InMemoryLogSource();

            logFile.AddEntry("Hello", LevelFlags.Debug);
            logFile.AddEntry("World!", LevelFlags.Info);

            entries.CopyFrom(Core.Columns.RawContent, 3, logFile, new LogSourceSection(0, 2));
            entries.Count.Should().Be(5, "because the count shouldn't have been modified");
            entries[0].RawContent.Should().Be("I", "because the first entry's raw content should not have been overwritten");
            entries[1].RawContent.Should().Be("want", "because the second entry's raw content should not have been overwritten");
            entries[2].RawContent.Should().Be("a", "because the third entry's raw content should not have been overwritten");
            entries[3].RawContent.Should().Be("Hello", "because the fourth entry's raw content should have been overwritten");
            entries[4].RawContent.Should().Be("World!", "because the fifth entry's raw content should have been overwritten");
        }
Пример #14
0
        public void TestExcludeDataSource1()
        {
            var logFile1 = new InMemoryLogSource();
            var source1  = new FileDataSource(_taskScheduler,
                                              new DataSource {
                Id = DataSourceId.CreateNew()
            },
                                              logFile1,
                                              TimeSpan.Zero);

            var logFile2 = new InMemoryLogSource();
            var source2  = new FileDataSource(_taskScheduler,
                                              new DataSource {
                Id = DataSourceId.CreateNew()
            },
                                              logFile2,
                                              TimeSpan.Zero);

            _merged.SetDataSources(new [] { source1, source2 });
            GetMergedLogFile().Sources.Should().Equal(logFile1, logFile2);

            _merged.SetExcluded(source1, true);
            GetMergedLogFile().Sources.Should().NotContain(logFile1, "because we've just excluded the first source");

            _merged.SetExcluded(source1, false);
            GetMergedLogFile().Sources.Should().Equal(logFile1, logFile2);
        }
Пример #15
0
        public void TestAppendTwoSourcesWrongOrder()
        {
            var source1 = new InMemoryLogSource();

            source1.AddEntry("B", LevelFlags.Other, new DateTime(2019, 5, 27, 23, 10, 0));
            var source2 = new InMemoryLogSource();

            source2.AddEntry("A", LevelFlags.Other, new DateTime(2019, 5, 27, 23, 09, 0));

            var index   = new MergedLogSourceIndex(source1, source2);
            var changes = index.Process(new MergedLogSourcePendingModification(source1, LogSourceModification.Appended(0, 1)),
                                        new MergedLogSourcePendingModification(source2, LogSourceModification.Appended(0, 1)));

            changes.Should().Equal(new object[]
            {
                LogSourceModification.Appended(0, 2)
            });

            var indices = index.Get(new LogSourceSection(0, 2));

            indices.Count.Should().Be(2);
            indices[0].SourceId.Should().Be(1);
            indices[0].SourceLineIndex.Should().Be(0);
            indices[0].OriginalLogEntryIndex.Should().Be(0);
            indices[0].MergedLogEntryIndex.Should().Be(0);
            indices[0].Timestamp.Should().Be(new DateTime(2019, 5, 27, 23, 9, 0));

            indices[1].SourceId.Should().Be(0);
            indices[1].SourceLineIndex.Should().Be(0);
            indices[1].OriginalLogEntryIndex.Should().Be(0);
            indices[1].MergedLogEntryIndex.Should().Be(1);
            indices[1].Timestamp.Should().Be(new DateTime(2019, 5, 27, 23, 10, 0));
        }
Пример #16
0
        public void TestMergeMultiline4()
        {
            var source = new InMemoryLogSource();
            var merged = new MergedLogSource(_taskScheduler, TimeSpan.Zero, source);

            source.AddMultilineEntry(LevelFlags.Other, new DateTime(2017, 12, 3, 11, 59, 30), new []
            {
                "2017-12-03 11:59:30 Hello, ",
                "World!"
            });
            _taskScheduler.RunOnce();

            merged.GetProperty(Core.Properties.LogEntryCount).Should().Be(2);

            var entries = merged.GetEntries(new[] { new LogLineIndex(0), new LogLineIndex(1) },
                                            new IColumnDescriptor[]
            {
                Core.Columns.LineNumber, Core.Columns.LogEntryIndex, Core.Columns.Timestamp,
                Core.Columns.RawContent
            });
            var line = entries[0];

            line.GetValue(Core.Columns.LineNumber).Should().Be(1);
            line.GetValue(Core.Columns.LogEntryIndex).Should().Be(0);
            line.RawContent.Should().Be("2017-12-03 11:59:30 Hello, ");

            line = entries[1];
            line.GetValue(Core.Columns.LineNumber).Should().Be(2);
            line.GetValue(Core.Columns.LogEntryIndex).Should().Be(0);
            line.RawContent.Should().Be("World!");
        }
Пример #17
0
        public void TestAppendTwoSourcesWrongOrderSeparateChangesPartialInvalidation()
        {
            var source1 = new InMemoryLogSource();

            source1.AddEntry("A", LevelFlags.Other, new DateTime(2019, 5, 28, 00, 34, 0));
            source1.AddEntry("C", LevelFlags.Other, new DateTime(2019, 5, 28, 00, 36, 0));
            var source2 = new InMemoryLogSource();

            source2.AddEntry("B", LevelFlags.Other, new DateTime(2019, 5, 28, 00, 35, 0));
            source2.AddEntry("D", LevelFlags.Other, new DateTime(2019, 5, 28, 00, 37, 0));

            var index   = new MergedLogSourceIndex(source1, source2);
            var changes = index.Process(new MergedLogSourcePendingModification(source1, LogSourceModification.Appended(0, 2)));

            changes.Should().Equal(new object[]
            {
                LogSourceModification.Appended(0, 2)
            });

            changes = index.Process(new MergedLogSourcePendingModification(source2, LogSourceModification.Appended(0, 2)));
            changes.Should().Equal(new object[]
            {
                LogSourceModification.Removed(1, 1),
                LogSourceModification.Appended(1, 3)
            });
        }
Пример #18
0
        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));
        }
Пример #19
0
        public void TestOneSourceAppendReset()
        {
            var source1 = new InMemoryLogSource();

            source1.AddEntry("A", LevelFlags.Other, new DateTime(2019, 5, 28, 00, 34, 0));

            var index   = new MergedLogSourceIndex(source1);
            var changes = index.Process(new MergedLogSourcePendingModification(source1, LogSourceModification.Appended(0, 1)));

            changes.Should().Equal(new object[]
            {
                LogSourceModification.Appended(0, 1)
            });

            changes = index.Process(new MergedLogSourcePendingModification(source1, LogSourceModification.Reset()));
            changes.Should().Equal(new object[]
            {
                LogSourceModification.Reset()
            });
            index.Count.Should().Be(0);
            index.Get(new LogSourceSection(0, 1)).Should().Equal(new object[]
            {
                MergedLogLineIndex.Invalid
            });
        }
Пример #20
0
        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);
        }
Пример #21
0
        public void TestClear()
        {
            var source = new InMemoryLogSource();

            source.AddEntry("A", LevelFlags.Other, new DateTime(2017, 9, 20, 15, 09, 02, 053));
            source.AddEntry("B", LevelFlags.Other, new DateTime(2017, 9, 20, 15, 09, 02, 100));
            source.AddEntry("C", LevelFlags.Other, new DateTime(2017, 9, 20, 15, 09, 02, 100));

            var index = new MergedLogSourceIndex(source);

            index.Process(new MergedLogSourcePendingModification(source, LogSourceModification.Appended(0, 3)));

            index.Count.Should().Be(3);
            var indices = index.Get(new LogSourceSection(0, 3));

            indices[0].SourceLineIndex.Should().Be(0);
            indices[1].SourceLineIndex.Should().Be(1);
            indices[2].SourceLineIndex.Should().Be(2);

            index.Clear();
            index.Count.Should().Be(0);
            indices = index.Get(new LogSourceSection(0, 3));
            indices[0].SourceLineIndex.Should().Be(-1);
            indices[1].SourceLineIndex.Should().Be(-1);
            indices[2].SourceLineIndex.Should().Be(-1);
        }
Пример #22
0
        public void TestGetTimestampsOneSource2([Range(0, 3)] int offset)
        {
            var source  = new InMemoryLogSource();
            var logFile = new MergedLogSource(_taskScheduler, TimeSpan.Zero, source);

            source.AddEntry("", LevelFlags.Other, new DateTime(2017, 12, 14, 23, 27, 0));
            source.AddEntry("", LevelFlags.Other, new DateTime(2017, 12, 14, 23, 28, 23));
            source.AddEntry("", LevelFlags.Other, new DateTime(2017, 12, 14, 23, 29, 1));
            int count = source.Count;

            _taskScheduler.Run(2);

            var buffer = new DateTime?[offset + count];

            for (int i = 0; i < offset + count; ++i)
            {
                buffer[i] = DateTime.MinValue;
            }

            logFile.GetColumn(new LogLineIndex[] { 2, 1 }, Core.Columns.Timestamp, buffer, offset);

            for (int i = 0; i < offset; ++i)
            {
                buffer[i].Should().Be(DateTime.MinValue, "because we've specified an offset and thus values before that offset shouldn't have been touched");
            }
            buffer[offset + 0].Should().Be(source.GetEntry(2).Timestamp);
            buffer[offset + 1].Should().Be(source.GetEntry(1).Timestamp);
        }
Пример #23
0
        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);
        }
Пример #24
0
        public void TestAddMultilineEntry2()
        {
            var logFile = new InMemoryLogSource();

            logFile.AddEntry("Hello, World!", LevelFlags.Debug);
            var t1 = new DateTime(2017, 11, 26, 11, 56, 0);

            logFile.AddMultilineEntry(LevelFlags.Info, t1, "foo", "bar");
            logFile.Count.Should().Be(3);
            var entry1 = logFile.GetEntry(0);

            entry1.Index.Should().Be(0);
            entry1.LogEntryIndex.Should().Be(0);
            entry1.RawContent.Should().Be("Hello, World!");
            entry1.LogLevel.Should().Be(LevelFlags.Debug);
            entry1.Timestamp.Should().Be(null);

            var entry2 = logFile.GetEntry(1);

            entry2.Index.Should().Be(1);
            entry2.LogEntryIndex.Should().Be(1);
            entry2.RawContent.Should().Be("foo");
            entry2.LogLevel.Should().Be(LevelFlags.Info);
            entry2.Timestamp.Should().Be(t1);

            var entry3 = logFile.GetEntry(2);

            entry3.Index.Should().Be(2);
            entry3.LogEntryIndex.Should().Be(1);
            entry3.RawContent.Should().Be("bar");
            entry3.LogLevel.Should().Be(LevelFlags.Info);
            entry3.Timestamp.Should().Be(t1);
        }
Пример #25
0
        public void TestSelectMultipleLinesWithKeyboard1()
        {
            var logFile = new InMemoryLogSource(_columns);

            logFile.AddEntry("Hello", LevelFlags.Other);
            logFile.AddEntry("World", LevelFlags.Other);
            logFile.AddEntry("How's it going?", LevelFlags.Other);

            _control.LogSource = logFile;
            _control.UpdateVisibleSection();
            _control.UpdateVisibleLines();

            // This time we'll do the first selection programatically (which happens when
            // switching between data sources, for example)
            _control.SelectedIndices = new List <LogLineIndex> {
                new LogLineIndex(0)
            };
            _keyboard.Press(Key.LeftShift);
            _keyboard.Click(_control, Key.Down);

            _control.SelectedIndices.Should().Equal(new LogLineIndex(0), new LogLineIndex(1));

            _keyboard.Click(_control, Key.Down);
            _control.SelectedIndices.Should().Equal(new LogLineIndex(0), new LogLineIndex(1), new LogLineIndex(2));

            _keyboard.Click(_control, Key.Up);
            _control.SelectedIndices.Should().Equal(new LogLineIndex(0), new LogLineIndex(1));

            _keyboard.Click(_control, Key.Up);
            _control.SelectedIndices.Should().Equal(new LogLineIndex(0));
        }
Пример #26
0
        public void TestAddListener1()
        {
            var logFile = new InMemoryLogSource();

            logFile.AddListener(_listener.Object, TimeSpan.Zero, 1);
            _modifications.Should().Equal(new object[] { LogSourceModification.Reset() });
        }
Пример #27
0
        public void TestSelectMultipleLinesWithKeyboard5()
        {
            var logFile = new InMemoryLogSource(_columns);

            logFile.AddEntry("Hello", LevelFlags.Other);
            logFile.AddEntry("World", LevelFlags.Other);
            logFile.AddEntry("How's it going?", LevelFlags.Other);

            _control.LogSource = logFile;
            _control.UpdateVisibleSection();
            _control.UpdateVisibleLines();

            _mouse.LeftClickAt(_control, new Point(10, 20));
            _control.SelectedIndices.Should().Equal(new LogLineIndex(1));

            var indices = new List <LogLineIndex>();

            _control.RequestBringIntoView += (index, match) => indices.Add(index);

            _keyboard.Press(Key.LeftShift);
            _keyboard.Click(_control, Key.Up);
            indices.Should().Equal(new object[] { new LogLineIndex(0) }, "because the newly selected log line should've been brought into view");

            indices.Clear();
            _keyboard.Click(_control, Key.Down);
            indices.Should().Equal(new object[] { new LogLineIndex(1) }, "because the newly selected log line should've been brought into view");
        }
Пример #28
0
        public void TestAddEntry2()
        {
            var logFile = new InMemoryLogSource();

            logFile.AddEntry("Hello,", LevelFlags.Info, new DateTime(2017, 4, 29, 14, 56, 0));
            logFile.AddEntry(" World!", LevelFlags.Warning, new DateTime(2017, 4, 29, 14, 56, 2));
            logFile.Count.Should().Be(2);

            var entry1 = logFile.GetEntry(0);

            entry1.Index.Should().Be(0);
            entry1.LogEntryIndex.Should().Be(0);
            entry1.LogLevel.Should().Be(LevelFlags.Info);
            entry1.RawContent.Should().Be("Hello,");
            entry1.Timestamp.Should().Be(new DateTime(2017, 4, 29, 14, 56, 0));

            var entry2 = logFile.GetEntry(1);

            entry2.Index.Should().Be(1);
            entry2.LogEntryIndex.Should().Be(1);
            entry2.LogLevel.Should().Be(LevelFlags.Warning);
            entry2.RawContent.Should().Be(" World!");
            entry2.Timestamp.Should().Be(new DateTime(2017, 4, 29, 14, 56, 2));

            logFile.GetProperty(Core.Properties.StartTimestamp).Should().Be(new DateTime(2017, 4, 29, 14, 56, 0));
            logFile.GetProperty(Core.Properties.Duration).Should().Be(TimeSpan.FromSeconds(2));
        }
        public void TestChangeFilter1()
        {
            var model = new LogViewMainPanelViewModel(_services, _actionCenter.Object, _dataSources.Object, _quickFilters.Object, _highlighters.Object, _settings.Object);
            var dataSourceViewModel = new Mock <IDataSourceViewModel>();

            dataSourceViewModel.SetupProperty(x => x.QuickFilterChain);

            var dataSource = CreateDataSource();

            var logFile = new InMemoryLogSource();

            dataSource.Setup(x => x.UnfilteredLogSource).Returns(logFile);
            var filteredLogFile = new InMemoryLogSource();

            dataSource.Setup(x => x.FilteredLogSource).Returns(filteredLogFile);
            dataSourceViewModel.Setup(x => x.DataSource).Returns(dataSource.Object);
            model.CurrentDataSource = dataSourceViewModel.Object;

            dataSourceViewModel.Object.QuickFilterChain.Should().BeNull("because no filter should be set right now");

            var filter = model.AddQuickFilter();

            filter.Value    = "Foobar";
            filter.IsActive = true;

            dataSourceViewModel.Object.QuickFilterChain.Should()
            .NotBeNull("because a filter chain should've been created for the 'Foobar' filter");
        }
Пример #30
0
        public void TestSetDataSourcesOneLessSource()
        {
            var logFile1 = new InMemoryLogSource();
            var source1  = new FileDataSource(_taskScheduler,
                                              new DataSource {
                Id = DataSourceId.CreateNew()
            },
                                              logFile1,
                                              TimeSpan.Zero);

            var logFile2 = new InMemoryLogSource();
            var source2  = new FileDataSource(_taskScheduler,
                                              new DataSource {
                Id = DataSourceId.CreateNew()
            },
                                              logFile2,
                                              TimeSpan.Zero);

            _merged.SetDataSources(new [] { source1, source2 });
            _merged.OriginalSources.Should().BeEquivalentTo(new object[] { source1, source2 });
            source1.ParentId.Should().Be(_merged.Id);
            source2.ParentId.Should().Be(_merged.Id);

            _merged.SetDataSources(new [] { source2 });
            _merged.OriginalSources.Should().BeEquivalentTo(new object[] { source2 });
            source1.ParentId.Should().Be(DataSourceId.Empty);
            source2.ParentId.Should().Be(_merged.Id);
        }