Ejemplo n.º 1
0
        public void TestContainsAny()
        {
            var buffer = new LogBufferList(Core.Columns.LineNumber);

            buffer.Resize(3);
            buffer[0].LineNumber = 1;
            buffer[1].LineNumber = 2;
            buffer[2].LineNumber = 3;

            buffer.ContainsAny(Core.Columns.LineNumber, 1, new Int32Range(0, 1)).Should().BeTrue();
            buffer.ContainsAny(Core.Columns.LineNumber, 1, new Int32Range(0, 2)).Should().BeTrue();
            buffer.ContainsAny(Core.Columns.LineNumber, 1, new Int32Range(0, 3)).Should().BeTrue();

            buffer.ContainsAny(Core.Columns.LineNumber, 1, new Int32Range(1, 1)).Should().BeFalse();
            buffer.ContainsAny(Core.Columns.LineNumber, 1, new Int32Range(1, 2)).Should().BeFalse();
            buffer.ContainsAny(Core.Columns.LineNumber, 1, new Int32Range(2, 1)).Should().BeFalse();

            buffer.ContainsAny(Core.Columns.LineNumber, 2, new Int32Range(0, 3)).Should().BeTrue();
            buffer.ContainsAny(Core.Columns.LineNumber, 2, new Int32Range(0, 1)).Should().BeFalse();
            buffer.ContainsAny(Core.Columns.LineNumber, 2, new Int32Range(2, 1)).Should().BeFalse();
        }
Ejemplo n.º 2
0
        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);
            }
        }