public void TestOneEntryTimestampReset() { var adorner = new LogSourcePropertyAdorner(_scheduler, _source.Object, TimeSpan.Zero); _sourceEntries.Add(new LogEntry { Index = 0, Timestamp = new DateTime(2021, 02, 20, 17, 52, 31) }); _listeners.OnRead(_sourceEntries.Count); _scheduler.RunOnce(); adorner.GetProperty(Core.Properties.StartTimestamp).Should().Be(new DateTime(2021, 02, 20, 17, 52, 31)); adorner.GetProperty(Core.Properties.EndTimestamp).Should().Be(new DateTime(2021, 02, 20, 17, 52, 31)); adorner.GetProperty(Core.Properties.Duration).Should().Be(TimeSpan.Zero); var buffer = new PropertiesBufferList(Core.Properties.StartTimestamp, Core.Properties.EndTimestamp); adorner.GetAllProperties(buffer); buffer.GetValue(Core.Properties.StartTimestamp).Should().Be(new DateTime(2021, 02, 20, 17, 52, 31)); buffer.GetValue(Core.Properties.EndTimestamp).Should().Be(new DateTime(2021, 02, 20, 17, 52, 31)); buffer.GetValue(Core.Properties.Duration).Should().Be(TimeSpan.Zero); _sourceEntries.Clear(); _listeners.Reset(); _scheduler.RunOnce(); adorner.GetProperty(Core.Properties.StartTimestamp).Should().BeNull(); adorner.GetProperty(Core.Properties.EndTimestamp).Should().BeNull(); adorner.GetProperty(Core.Properties.Duration).Should().BeNull(); adorner.GetAllProperties(buffer); buffer.GetValue(Core.Properties.StartTimestamp).Should().BeNull(); buffer.GetValue(Core.Properties.EndTimestamp).Should().BeNull(); buffer.GetValue(Core.Properties.Duration).Should().BeNull(); }
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); }
private void Clear() { lock (_syncRoot) { _indices.Clear(); _maxWidth = 0; } }
public void TestClearOneEntry() { var entries = new LogBufferList(); entries.Add(); entries.Count.Should().Be(1); entries.Clear(); entries.Count.Should().Be(0); }
public void TestClearEmpty() { var entries = new LogBufferList(Core.Columns.ElapsedTime); entries.Count.Should().Be(0); entries.Columns.Should().Equal(Core.Columns.ElapsedTime); entries.Clear(); entries.Count.Should().Be(0); entries.Columns.Should().Equal(Core.Columns.ElapsedTime); }
public void TestClearMany() { var entries = new LogBufferList(Core.Columns.LineNumber); entries.Add(42); entries.Add(9001); entries.Count.Should().Be(2); entries.Clear(); entries.Count.Should().Be(0); entries.AddEmpty(); entries.AddEmpty(); entries.Count.Should().Be(2); entries[0].LineNumber.Should().Be(0); entries[1].LineNumber.Should().Be(0); }
public void TestCacheRemovesEntriesWhenNeeded() { var buffer = new PagedLogBuffer(4, 2, Core.Columns.RawContent); buffer.ResizeTo(16); var data = new LogBufferList(Core.Columns.Index, Core.Columns.RawContent) { new LogEntry { RawContent = "A" }, new LogEntry { RawContent = "B" }, new LogEntry { RawContent = "C" }, new LogEntry { RawContent = "D" }, new LogEntry { RawContent = "E" }, new LogEntry { RawContent = "F" }, new LogEntry { RawContent = "G" }, new LogEntry { RawContent = "H" }, }; buffer.TryAdd(new LogSourceSection(0, 8), data, 0); var destination = new LogBufferArray(8, Core.Columns.Index, Core.Columns.RawContent, PageBufferedLogSource.RetrievalState); buffer.TryGetEntries(new[] { new LogLineIndex(3) }, destination, 0).Should().BeTrue("because the data is still in the cache"); destination[0].RawContent.Should().Be("D"); data.Clear(); data.AddRange(new [] { new LogEntry { RawContent = "I" }, new LogEntry { RawContent = "J" }, new LogEntry { RawContent = "K" }, new LogEntry { RawContent = "L" }, new LogEntry { RawContent = "M" }, new LogEntry { RawContent = "N" }, new LogEntry { RawContent = "O" }, new LogEntry { RawContent = "P" }, }); //< We deliberately add data that fills the entire cache because we don't want to verify the specific caching algorithm (i.e. which // data get's removed), we just want to make sure that it *does* get removed once the cache grows too big. buffer.TryAdd(new LogSourceSection(8, 8), data, 0); buffer.TryGetEntries(new LogSourceSection(0, 8), destination, 0).Should().BeFalse("because we've added so much data than none of the previously added data may still be part of the cache"); for (int i = 0; i < destination.Count; ++i) { destination[i].RawContent.Should().Be(Core.Columns.RawContent.DefaultValue); destination[i].GetValue(PageBufferedLogSource.RetrievalState).Should().Be(RetrievalState.NotCached); } }
public void UpdateVisibleLines() { _visibleTextLines.Clear(); if (_logSource == null) { return; } try { _visibleBufferBuffer.Clear(); _visibleBufferBuffer.Resize(_currentlyVisibleSection.Count); if (_currentlyVisibleSection.Count > 0) { // We don't want to block the UI thread for very long at all so we instruct the log source to only // fetch data from the cache, but to fetch missing data for later (from the source). var queryOptions = new LogSourceQueryOptions(LogSourceQueryMode.FromCache | LogSourceQueryMode.FetchForLater, TimeSpan.Zero); _logSource.GetEntries(_currentlyVisibleSection, _visibleBufferBuffer, 0, queryOptions); // Now comes the fun part. We need to detect if we could fetch *all* the data. // This is done by inspecting the BufferedLogSource.RetrievalState - if we encounter any NotCached value, // then the entry is part of the source, but was not cached at the time of trying to access it. // If that's the case, we will instruct this canvas to re-fetch the once more in a bit. This loop will terminate once the // cache has managed to fetch the desired data which should happen some time... if (_visibleBufferBuffer.ContainsAny(PageBufferedLogSource.RetrievalState, RetrievalState.NotCached, new Int32Range(offset: 0, _currentlyVisibleSection.Count))) { if (!_requiresFurtherUpdate) { Log.DebugFormat("Requires further update (at least one entry is not in cache)"); _requiresFurtherUpdate = true; _updateStart = DateTime.Now; } } else { if (_requiresFurtherUpdate) { var elapsed = DateTime.Now - _updateStart; Log.DebugFormat("No longer requires further update (all retrieved log entries are in cache), took {0:F1}ms", elapsed.TotalMilliseconds); _requiresFurtherUpdate = false; } } for (int i = 0; i < _currentlyVisibleSection.Count; ++i) { var line = new TextLine(_visibleBufferBuffer[i], _hoveredIndices, _selectedIndices, _colorByLevel, _textSettings, _textBrushes) { IsFocused = IsFocused, SearchResults = _searchResults }; _visibleTextLines.Add(line); } } Action fn = VisibleLinesChanged; fn?.Invoke(); InvalidateVisual(); } catch (ArgumentOutOfRangeException e) { Log.DebugFormat("Caught exception while trying to update text: {0}", e); } catch (IndexOutOfRangeException e) { Log.DebugFormat("Caught exception while trying to update text: {0}", e); } }