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); } }
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); }
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); } } }
public void RemoveListener(ILogSourceListener listener) { ListenerProxy proxy; lock (_syncRoot) { if (!_listeners.TryGetValue(listener, out proxy)) { return; } } _actualSource.RemoveListener(proxy); }
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); }
/// <inheritdoc /> public void RemoveListener(ILogSourceListener listener) { _buffer.RemoveListener(listener); }
/// <inheritdoc /> public void AddListener(ILogSourceListener listener, TimeSpan maximumWaitTime, int maximumLineCount) { _buffer.AddListener(listener, maximumWaitTime, maximumLineCount); }
/// <inheritdoc /> public void RemoveListener(ILogSourceListener listener) { _listeners.RemoveListener(listener); }
public ListenerProxy(ILogSource source, ILogSourceListener listener) { _source = source; _listener = listener; }