Exemple #1
0
 public void AddListener(ILogSourceListener listener, TimeSpan maximumWaitTime, int maximumLineCount)
 {
     if (_listeners.Add(listener))
     {
         listener.OnLogFileModified(this, LogSourceModification.Reset());
     }
 }
 /// <summary>
 ///     Removes the given listener from the list of notified listeners.
 /// </summary>
 /// <param name="listener"></param>
 public void RemoveListener(ILogSourceListener listener)
 {
     lock (_listeners)
     {
         _listeners.Remove(listener);
     }
 }
Exemple #3
0
        public void TestDataSourceDoesntExist2()
        {
            var dataSource  = new Mock <IFileDataSource>();
            var logFile     = new Mock <ILogSource>();
            var emptyReason = new SourceDoesNotExist("E:\\Tailviewer\\somefile.log");

            logFile.Setup(x => x.GetProperty(Properties.EmptyReason)).Returns(emptyReason);
            logFile.Setup(x => x.GetProperty(Properties.Size)).Returns((Size?)null);
            var filteredLogFile         = new Mock <ILogSource>();
            ILogSourceListener listener = null;

            filteredLogFile.Setup(x => x.AddListener(It.IsAny <ILogSourceListener>(), It.IsAny <TimeSpan>(), It.IsAny <int>()))
            .Callback((ILogSourceListener l, TimeSpan t, int i) => listener = l);
            dataSource.Setup(x => x.UnfilteredLogSource).Returns(logFile.Object);
            dataSource.Setup(x => x.FullFileName).Returns(@"E:\Tailviewer\somefile.log");
            dataSource.Setup(x => x.FilteredLogSource).Returns(filteredLogFile.Object);
            dataSource.Setup(x => x.Search).Returns(new Mock <ILogSourceSearch>().Object);

            var dataSourceModel = CreateFileViewModel(dataSource.Object);
            var model           = new LogViewerViewModel(dataSourceModel, _actionCenter.Object, _settings.Object, TimeSpan.Zero);

            model.LogEntryCount.Should().Be(0);
            model.NoEntriesExplanation.Should().Be("Data source does not exist");
            model.NoEntriesAction.Should().Be("The data source 'somefile.log' was last seen E:\\Tailviewer");

            logFile.Setup(x => x.GetProperty(Properties.EmptyReason)).Returns((IEmptyReason)null);
            logFile.Setup(x => x.GetProperty(Properties.Size)).Returns(Size.Zero);
            listener.OnLogFileModified(logFile.Object, LogSourceModification.Appended(0, 0));
            model.Update();

            model.NoEntriesExplanation.Should().Be("Data source is empty");
            model.NoEntriesAction.Should().BeNull();
        }
        /// <inheritdoc />
        public void RemoveListener(ILogSourceListener listener)
        {
            if (Log.IsDebugEnabled)
            {
                Log.DebugFormat("RemoveListener({0})", listener);
            }

            _listeners.RemoveListener(listener);
        }
        /// <inheritdoc />
        public void AddListener(ILogSourceListener listener, TimeSpan maximumWaitTime, int maximumLineCount)
        {
            if (Log.IsDebugEnabled)
            {
                Log.DebugFormat("AddListener({0}, {1}, {2})", listener, maximumWaitTime, maximumLineCount);
            }

            _listeners.AddListener(listener, maximumWaitTime, maximumLineCount);
        }
Exemple #6
0
        public LogSourceListenerNotifier(ILogSource logSource, ILogSourceListener listener, TimeSpan maximumTime, int maximumCount)
        {
            _logSource    = logSource ?? throw new ArgumentNullException(nameof(logSource));
            _listener     = listener ?? throw new ArgumentNullException(nameof(listener));
            _maximumTime  = maximumTime;
            _maximumCount = maximumCount;

            Reset();

            _listener.OnLogFileModified(logSource, LogSourceModification.Reset());
        }
 /// <inheritdoc />
 public void RemoveListener(ILogSourceListener listener)
 {
     try
     {
         _logSource.RemoveListener(listener);
     }
     catch (Exception e)
     {
         BlameExceptionOnPlugin(e);
     }
 }
 /// <inheritdoc />
 public void AddListener(ILogSourceListener listener, TimeSpan maximumWaitTime, int maximumLineCount)
 {
     try
     {
         _logSource.AddListener(listener, maximumWaitTime, maximumLineCount);
     }
     catch (Exception e)
     {
         BlameExceptionOnPlugin(e);
     }
 }
 /// <summary>
 ///     Adds the given listener to the list of notified listeners.
 ///     The listener will immediately be notified of the <see cref="CurrentLineIndex" />.
 /// </summary>
 /// <param name="listener"></param>
 /// <param name="maximumWaitTime"></param>
 /// <param name="maximumLineCount"></param>
 public void AddListener(ILogSourceListener listener, TimeSpan maximumWaitTime, int maximumLineCount)
 {
     lock (_listeners)
     {
         if (!_listeners.ContainsKey(listener))
         {
             var notifier = new LogSourceListenerNotifier(_logSource, listener, maximumWaitTime, maximumLineCount);
             _listeners.Add(listener, notifier);
             notifier.OnRead(CurrentLineIndex);
         }
     }
 }
Exemple #10
0
        public void RemoveListener(ILogSourceListener listener)
        {
            ListenerProxy proxy;

            lock (_syncRoot)
            {
                if (!_listeners.TryGetValue(listener, out proxy))
                {
                    return;
                }
            }

            _actualSource.RemoveListener(proxy);
        }
Exemple #11
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);
        }
Exemple #12
0
 /// <inheritdoc />
 public void RemoveListener(ILogSourceListener listener)
 {
     _buffer.RemoveListener(listener);
 }
Exemple #13
0
 /// <inheritdoc />
 public void AddListener(ILogSourceListener listener, TimeSpan maximumWaitTime, int maximumLineCount)
 {
     _buffer.AddListener(listener, maximumWaitTime, maximumLineCount);
 }
Exemple #14
0
 /// <inheritdoc />
 public void RemoveListener(ILogSourceListener listener)
 {
     _listeners.RemoveListener(listener);
 }
Exemple #15
0
 public ListenerProxy(ILogSource source, ILogSourceListener listener)
 {
     _source   = source;
     _listener = listener;
 }