public PresentationLogSource(ITaskScheduler scheduler, ILogSource source, TimeSpan maximumWaitTime, TextSettings textSettings)
            : base(scheduler)
        {
            if (scheduler == null)
            {
                throw new ArgumentNullException(nameof(scheduler));
            }
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            _maximumWaitTime = maximumWaitTime;
            _textSettings    = textSettings;
            _source          = source;

            _indices = new LogBufferList(IndexedColumns);

            _array = new LogBufferArray(MaximumLineCount, Core.Columns.RawContent);
            _pendingModifications = new ConcurrentQueue <PendingModification>();
            _syncRoot             = new object();

            _source.AddListener(this, _maximumWaitTime, MaximumLineCount);
            StartTask();
        }
Beispiel #2
0
        public LogSourceSearch(ITaskScheduler taskScheduler, ILogSource logSource, string searchTerm, TimeSpan maximumWaitTime)
        {
            if (taskScheduler == null)
            {
                throw new ArgumentNullException(nameof(taskScheduler));
            }
            if (logSource == null)
            {
                throw new ArgumentNullException(nameof(logSource));
            }
            if (string.IsNullOrEmpty(searchTerm))
            {
                throw new ArgumentException("searchTerm may not be empty");
            }

            _logSource            = logSource;
            _filter               = new SubstringFilter(searchTerm, true);
            _matches              = new List <LogMatch>();
            _syncRoot             = new object();
            _listeners            = new LogFileSearchListenerCollection(this);
            _pendingModifications = new ConcurrentQueue <LogSourceModification>();
            _scheduler            = taskScheduler;

            const int maximumLineCount = 1000;

            _maximumWaitTime = maximumWaitTime;
            _logLinesArray   = new LogBufferArray(maximumLineCount, Columns.Index, Columns.RawContent);
            _matchesBuffer   = new List <LogLineMatch>();
            _logSource.AddListener(this, _maximumWaitTime, maximumLineCount);

            _task = _scheduler.StartPeriodic(FilterAllPending,
                                             TimeSpan.FromMilliseconds(100),
                                             string.Format("Search {0}", logSource));
        }
        private void OnLogFileChanged(ILogSource oldValue, ILogSource newValue)
        {
            oldValue?.RemoveListener(this);

            PartTextCanvas.LogSource = newValue;

            if (newValue != null)
            {
                newValue.AddListener(this, TimeSpan.FromMilliseconds(value: 100), maximumLineCount: 10000);

                _maxLineWidth = (int)Math.Ceiling(_textSettings.EstimateWidthUpperLimit(newValue.GetProperty(TextProperties.MaxCharactersInLine)));
                UpdateScrollViewerRegions();
                PartTextCanvas.DetermineVerticalOffset();
                PartTextCanvas.UpdateVisibleSection();
                PartTextCanvas.UpdateVisibleLines();
            }
            else
            {
                _maxLineWidth = 0;
                TextCanvasOnVisibleLinesChanged();
                UpdateScrollViewerRegions();
            }

            MatchScrollbarValueToCurrentLine();
        }
        /// <summary>
        ///     Initializes this object.
        /// </summary>
        /// <remarks>
        ///    Plugin authors are deliberately prevented from calling this constructor directly because it's signature may change
        ///    over time. In order to create an instance of this type, simply call <see cref="ILogSourceFactory.CreateMultiLineLogFile"/>.
        /// </remarks>
        /// <param name="taskScheduler"></param>
        /// <param name="source"></param>
        /// <param name="maximumWaitTime"></param>
        public MultiLineLogSource(ITaskScheduler taskScheduler, ILogSource source, TimeSpan maximumWaitTime)
            : base(taskScheduler)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            _maximumWaitTime      = maximumWaitTime;
            _pendingModifications = new ConcurrentQueue <LogSourceModification>();
            _syncRoot             = new object();
            _specialColumns       = new HashSet <IColumnDescriptor> {
                Core.Columns.LogEntryIndex, Core.Columns.Timestamp, Core.Columns.LogLevel
            };
            _indices = new List <LogEntryInfo>();

            // The log file we were given might offer even more properties than the minimum set and we
            // want to expose those as well.
            _propertiesBuffer = new PropertiesBufferList(Core.Properties.CombineWithMinimum(source.Properties));
            _propertiesBuffer.SetValue(Core.Properties.EmptyReason, null);

            _properties = new ConcurrentPropertiesList(Core.Properties.CombineWithMinimum(source.Properties));
            _properties.CopyFrom(_propertiesBuffer);

            _currentLogEntry = new LogEntryInfo(-1, 0);

            _source = source;
            _source.AddListener(this, maximumWaitTime, MaximumBatchSize);
            StartTask();
        }
Beispiel #5
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);
        }
Beispiel #6
0
        private static List <LogSourceModification> ListenToChanges(ILogSource logSource, int maximumLineCount)
        {
            var modifications = new List <LogSourceModification>();
            var listener      = new Mock <ILogSourceListener>();

            listener.Setup(x => x.OnLogFileModified(It.IsAny <ILogSource>(), It.IsAny <LogSourceModification>()))
            .Callback((ILogSource file, LogSourceModification modification) => { modifications.Add(modification); });
            logSource.AddListener(listener.Object, TimeSpan.Zero, maximumLineCount);
            return(modifications);
        }
 /// <inheritdoc />
 public void AddListener(ILogSourceListener listener, TimeSpan maximumWaitTime, int maximumLineCount)
 {
     try
     {
         _logSource.AddListener(listener, maximumWaitTime, maximumLineCount);
     }
     catch (Exception e)
     {
         BlameExceptionOnPlugin(e);
     }
 }
Beispiel #8
0
        public void AddListener(ILogSourceListener listener, TimeSpan maximumWaitTime, int maximumLineCount)
        {
            // We need to make sure that whoever registers with us is getting OUR reference through
            // their listener, not the source we're wrapping (or they might discard events since they're
            // coming not from the source they subscribed to).
            var proxy = new ListenerProxy(_proxy, listener);

            lock (_syncRoot)
            {
                _listeners.Add(listener, proxy);
            }

            _actualSource.AddListener(proxy, maximumWaitTime, maximumLineCount);
        }
        public PageBufferedLogSource(ITaskScheduler taskScheduler, ILogSource source, TimeSpan maximumWaitTime, IReadOnlyList <IColumnDescriptor> nonCachedColumns, int pageSize = DefaultPageSize, int maxNumPages = DefaultMaxPageCount)
        {
            _syncRoot      = new object();
            _taskScheduler = taskScheduler;
            _source        = source;
            _maxNumPages   = maxNumPages;
            _listeners     = new ProxyLogListenerCollection(source, this);
            _cachedColumns = source.Columns.Except(nonCachedColumns).ToList();
            _buffer        = new PagedLogBuffer(pageSize, maxNumPages, _cachedColumns);
            _fetchQueue    = new ConcurrentQueue <LogSourceSection>();
            _source.AddListener(this, maximumWaitTime, pageSize);

            _fetchBuffer = new LogBufferArray(pageSize, _cachedColumns);
            _fetchTask   = _taskScheduler.StartPeriodic(FetchPagesFromSource, maximumWaitTime);
        }
        public LogSourcePropertyAdorner(ITaskScheduler scheduler, ILogSource source, TimeSpan maximumWaitTime, IReadOnlyList <IReadOnlyPropertyDescriptor> adornedProperties)
            : base(scheduler)
        {
            _source            = source;
            _maximumWaitTime   = maximumWaitTime;
            _adornedProperties = adornedProperties;
            _propertiesBuffer  = new PropertiesBufferList(_adornedProperties);
            _properties        = new ConcurrentPropertiesList(_adornedProperties);
            _pendingSections   = new ConcurrentQueue <LogSourceModification>();
            _requiredColumns   = GetColumnsRequiredFor(_adornedProperties);
            const int bufferSize = 1000;

            _buffer = new LogBufferArray(bufferSize, _requiredColumns);

            _source.AddListener(this, maximumWaitTime, bufferSize);
            StartTask();
        }
        /// <summary>
        ///     Initializes this object.
        /// </summary>
        /// <param name="scheduler"></param>
        /// <param name="maximumWaitTime"></param>
        /// <param name="source"></param>
        /// <param name="logLineFilter"></param>
        /// <param name="logEntryFilter"></param>
        public FilteredLogSource(ITaskScheduler scheduler,
                                 TimeSpan maximumWaitTime,
                                 ILogSource source,
                                 ILogLineFilter logLineFilter,
                                 ILogEntryFilter logEntryFilter)
            : base(scheduler)
        {
            _source = source ?? throw new ArgumentNullException(nameof(source));

            _properties       = new ConcurrentPropertiesList(source.Properties);
            _propertiesBuffer = new PropertiesBufferList();             //< Will be used as temporary storage to hold the properties from the source

            _logLineFilter        = logLineFilter ?? new NoFilter();
            _logEntryFilter       = logEntryFilter ?? new NoFilter();
            _pendingModifications = new ConcurrentQueue <LogSourceModification>();
            _indices         = new List <int>();
            _logEntryIndices = new Dictionary <int, int>();
            _array           = new LogBufferArray(BatchSize, Core.Columns.Minimum);
            _lastLogBuffer   = new LogBufferList(Core.Columns.Minimum);
            _maximumWaitTime = maximumWaitTime;

            _source.AddListener(this, maximumWaitTime, BatchSize);
            StartTask();
        }
Beispiel #12
0
 /// <inheritdoc />
 protected override void StartTask()
 {
     _source.AddListener(this, _maximumWaitTime, _maxEntryCount);
     base.StartTask();
 }