예제 #1
0
        private static ILogBuffer Listen(ILogSource logSource)
        {
            var data     = new LogBufferList(logSource.Columns);
            var listener = new Mock <ILogSourceListener>();

            listener.Setup(x => x.OnLogFileModified(It.IsAny <ILogSource>(), It.IsAny <LogSourceModification>()))
            .Callback((ILogSource file, LogSourceModification modification) =>
            {
                if (modification.IsReset())
                {
                    data.Clear();
                }
                else if (modification.IsRemoved(out var removedSection))
                {
                    data.RemoveRange((int)removedSection.Index, removedSection.Count);
                }
                else if (modification.IsAppended(out var appendedSection))
                {
                    var destinationIndex = data.Count;
                    data.Resize(data.Count + appendedSection.Count);
                    file.GetEntries(appendedSection, data, destinationIndex);
                }
            });
            logSource.AddListener(listener.Object, TimeSpan.Zero, 1);
            return(data);
        }
예제 #2
0
        public void TestRemoveRangeInvalidIndex2([Values(3, 42)] int invalidIndex)
        {
            var entries = new LogBufferList(Core.Columns.RawContent);

            entries.Add("foo");
            entries.Add("bar");
            entries.Count.Should().Be(2);

            new Action(() => entries.RemoveRange(invalidIndex, 1)).Should().Throw <ArgumentException>();
            entries.Count.Should().Be(2);
            entries[0].RawContent.Should().Be("foo");
            entries[1].RawContent.Should().Be("bar");
        }
예제 #3
0
        public void TestRemoveRange()
        {
            var entries = new LogBufferList(Core.Columns.RawContent);

            entries.Add("foo");
            entries.Add("clondyke");
            entries.Add("bar");
            entries.Count.Should().Be(3);

            entries.RemoveRange(1, 1);
            entries.Count.Should().Be(2);
            entries[0].RawContent.Should().Be("foo", "because the first message shouldn't have been modified");
            entries[1].RawContent.Should().Be("bar", "because the second cell should have been removed, the third cell should have moved down");
        }
예제 #4
0
        public void TestRemoveRangePartiallyInvalidRange([Values(0, 1, 2)] int index)
        {
            var entries = new LogBufferList(Core.Columns.RawContent);

            entries.Add("f");
            entries.Add("o");
            entries.Add("o");
            entries.Add("b");
            entries.Add("a");
            entries.Add("r");
            entries.Count.Should().Be(6);

            new Action(() => entries.RemoveRange(index, 7)).Should().Throw <ArgumentException>();
            entries.Count.Should().Be(6);
            entries[0].RawContent.Should().Be("f");
            entries[1].RawContent.Should().Be("o");
            entries[2].RawContent.Should().Be("o");
            entries[3].RawContent.Should().Be("b");
            entries[4].RawContent.Should().Be("a");
            entries[5].RawContent.Should().Be("r");
        }
예제 #5
0
 private void Remove(ILogSource logSource, LogLineIndex index)
 {
     lock (_syncRoot)
     {
         if (!ReferenceEquals(logSource, _source))
         {
             Log.WarnFormat("Ignoring invalidation from '{0}' onwards: It's probably from a previous log file",
                            index);
         }
         else
         {
             var count = _indices.Count - index;
             if (count > 0)
             {
                 _indices.RemoveRange((int)index, count);
                 DetermineMaxWidthAndLineNumbers();
             }
             else
             {
                 Log.WarnFormat("Ignoring reset: index is completely out of bounds");
             }
         }
     }
 }