Exemplo n.º 1
0
        public void TestDataSourceDoesntExist2()
        {
            var dataSource = new Mock <ISingleDataSource>();
            var logFile    = new Mock <ILogFile>();

            logFile.Setup(x => x.GetValue(LogFileProperties.EmptyReason)).Returns(ErrorFlags.SourceDoesNotExist);
            logFile.Setup(x => x.GetValue(LogFileProperties.Size)).Returns((Size?)null);
            var filteredLogFile       = new Mock <ILogFile>();
            ILogFileListener listener = null;

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

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

            model.LogEntryCount.Should().Be(0);
            model.NoEntriesExplanation.Should().Be("Can't find \"somefile.log\"");
            model.NoEntriesSubtext.Should().Be("It was last seen at E:\\Tailviewer");

            logFile.Setup(x => x.GetValue(LogFileProperties.EmptyReason)).Returns(ErrorFlags.None);
            logFile.Setup(x => x.GetValue(LogFileProperties.Size)).Returns(Size.Zero);
            listener.OnLogFileModified(logFile.Object, new LogFileSection(0, 0));
            model.Update();

            model.NoEntriesExplanation.Should().Be("The data source is empty");
            model.NoEntriesSubtext.Should().BeNull();
        }
Exemplo n.º 2
0
 public void OnRead(int numberOfLinesRead)
 {
     if (numberOfLinesRead >= 0)
     {
         DateTime now = DateTime.Now;
         if (now - _lastReportedTime >= _maximumTime)
         {
             Flush(numberOfLinesRead, now);
         }
         else if (numberOfLinesRead - _lastNumberOfLines >= _maximumCount)
         {
             Flush(numberOfLinesRead, now);
         }
     }
     else if (_sentAnyData)             //< We want to avoid sending multiple successive reset events
     {
         Reset();
         _listener.OnLogFileModified(_logFile, LogFileSection.Reset);
     }
 }
        public LogFileListenerNotifier(ILogFile logFile, ILogFileListener listener, TimeSpan maximumTime, int maximumCount)
        {
            if (logFile == null) throw new ArgumentNullException("logFile");
            if (listener == null) throw new ArgumentNullException("listener");

            _logFile = logFile;
            _listener = listener;
            _maximumTime = maximumTime;
            _maximumCount = maximumCount;

            Reset();

            _listener.OnLogFileModified(logFile, LogFileSection.Reset);
        }
Exemplo n.º 4
0
        public LogFileListenerNotifier(ILogFile logFile, ILogFileListener listener, TimeSpan maximumTime, int maximumCount)
        {
            if (logFile == null)
            {
                throw new ArgumentNullException(nameof(logFile));
            }
            if (listener == null)
            {
                throw new ArgumentNullException(nameof(listener));
            }

            _logFile      = logFile;
            _listener     = listener;
            _maximumTime  = maximumTime;
            _maximumCount = maximumCount;

            Reset();

            _listener.OnLogFileModified(logFile, LogFileSection.Reset);
        }