예제 #1
0
        private IDataSource AddDataSource(DataSource settings)
        {
            lock (_syncRoot)
            {
                IDataSource dataSource;
                if (!string.IsNullOrEmpty(settings.LogFileFolderPath))
                {
                    dataSource = new FolderDataSource(_taskScheduler, _logFileFactory, _filesystem, settings);
                }
                else if (!string.IsNullOrEmpty(settings.File))
                {
                    dataSource = new SingleDataSource(_logFileFactory, _taskScheduler, settings, _maximumWaitTime);
                }
                else
                {
                    if (settings.DisplayName == null)
                    {
                        settings.DisplayName = "Merged Data Source";
                    }

                    dataSource = new MergedDataSource(_taskScheduler, settings, _maximumWaitTime);
                }

                _dataSources.Add(dataSource);
                _dataSourceIds.Add(dataSource.Id);
                _bookmarks.AddDataSource(dataSource);
                return(dataSource);
            }
        }
예제 #2
0
 public void TestAdd1()
 {
     var settings = new DataSource("foo") {Id = Guid.NewGuid()};
     var dataSource = new SingleDataSource(_scheduler, settings);
     _merged.Add(dataSource);
     settings.ParentId.Should()
             .Be(_settings.Id, "Because the parent-child relationship should've been declared via ParentId");
 }
예제 #3
0
 public void TestAdd2()
 {
     var settings = new DataSource("foo") {Id = Guid.NewGuid()};
     var dataSource = new SingleDataSource(_scheduler, settings);
     _merged.Add(dataSource);
     _merged.UnfilteredLogFile.Should().NotBeNull();
     _merged.UnfilteredLogFile.Should().BeOfType<MergedLogFile>();
     ((MergedLogFile) _merged.UnfilteredLogFile).Sources.Should().Equal(new object[] {dataSource.UnfilteredLogFile});
 }
예제 #4
0
 public void TestCtor()
 {
     using (var source = new SingleDataSource(_scheduler, new DataSource(@"E:\somelogfile.txt") { Id = Guid.NewGuid() }))
     {
         source.FullFileName.Should().Be(@"E:\somelogfile.txt");
         source.LevelFilter.Should().Be(LevelFlags.All);
         source.SearchTerm.Should().BeNull();
         source.FollowTail.Should().BeFalse();
     }
 }
        public void TestCtor2()
        {
            using (var source = new SingleDataSource(_scheduler, new DataSource { Id = Guid.NewGuid(), File = @"C:\temp\foo.txt", SearchTerm = "foobar" }, new Mock<ILogFile>().Object, TimeSpan.Zero))
            {
                source.SearchTerm.Should().Be("foobar");

                var model = new SingleDataSourceViewModel(source);
                model.FileName.Should().Be("foo.txt");
                model.SearchTerm.Should().Be("foobar");
            }
        }
 public void SetUp()
 {
     _quickFilter = new QuickFilter(new Tailviewer.Settings.QuickFilter());
     _dataSource = new SingleDataSource(_scheduler, _dataSourceSettings = new DataSource("nothing") {Id = Guid.NewGuid()});
     _model = new QuickFilterViewModel(_quickFilter, x => { })
         {
             CurrentDataSource = _dataSource
         };
     _changes = new List<string>();
     _model.PropertyChanged += (sender, args) => _changes.Add(args.PropertyName);
 }
예제 #7
0
        public void TestChangeFilter1()
        {
            ILogFile logFile1 = _merged.UnfilteredLogFile;
            _merged.SearchTerm = "foo";
            var settings1 = new DataSource("foo") {Id = Guid.NewGuid()};
            var dataSource1 = new SingleDataSource(_scheduler, settings1);
            _merged.Add(dataSource1);
            ILogFile logFile2 = _merged.UnfilteredLogFile;

            logFile2.Should().NotBeSameAs(logFile1);
            ((AbstractLogFile) logFile1).IsDisposed.Should().BeTrue();
        }
 public void TestRemoveCommand1()
 {
     using (
         var source =
             new SingleDataSource(_scheduler, new DataSource(@"E:\Code\SharpTail\SharpTail.Test\TestData\20Mb.test") { Id = Guid.NewGuid() }))
     {
         var model = new SingleDataSourceViewModel(source);
         model.RemoveCommand.Should().NotBeNull();
         model.RemoveCommand.CanExecute(null).Should().BeTrue();
         new Action(() => model.RemoveCommand.Execute(null)).ShouldNotThrow();
     }
 }
 public void TestRemoveCommand2()
 {
     using (
         var source =
             new SingleDataSource(_scheduler, new DataSource(@"E:\Code\SharpTail\SharpTail.Test\TestData\20Mb.test") { Id = Guid.NewGuid() }))
     {
         var model = new SingleDataSourceViewModel(source);
         var calls = new List<IDataSourceViewModel>();
         model.Remove += calls.Add;
         new Action(() => model.RemoveCommand.Execute(null)).ShouldNotThrow();
         calls.Should().Equal(new object[] {model});
     }
 }
 public void TestCtor1()
 {
     var settings = new DataSource(@"E:\Code\SharpTail\SharpTail.Test\TestData\20Mb.test")
         {
             Id = Guid.NewGuid()
         };
     using (var source = new SingleDataSource(_scheduler, settings))
     {
         var model = new SingleDataSourceViewModel(source);
         model.FullName.Should().Be(@"E:\Code\SharpTail\SharpTail.Test\TestData\20Mb.test");
         model.Id.Should().Be(settings.Id);
     }
 }
예제 #11
0
        public void TestDispose()
        {
            LogFileProxy permanentLogFile;
            LogFileSearchProxy permanentSearch;

            SingleDataSource source;
            using (source = new SingleDataSource(_scheduler, new DataSource(@"E:\somelogfile.txt") {Id = Guid.NewGuid()}))
            {
                permanentLogFile = (LogFileProxy) source.FilteredLogFile;
                permanentSearch = (LogFileSearchProxy) source.Search;

                permanentLogFile.IsDisposed.Should().BeFalse();
                permanentSearch.IsDisposed.Should().BeFalse();
            }
            source.IsDisposed.Should().BeTrue();
            permanentLogFile.IsDisposed.Should().BeTrue();
            permanentSearch.IsDisposed.Should().BeTrue();
        }
        public void TestSearch1()
        {
            var settings = new DataSource(LogFileTest.File2Mb) { Id = Guid.NewGuid() };
            using (var logFile = new LogFile(_taskScheduler, LogFileTest.File2Mb))
            using (var dataSource = new SingleDataSource(_taskScheduler, settings, logFile, TimeSpan.Zero))
            {
                var model = new SingleDataSourceViewModel(dataSource);

                logFile.Property(x => x.EndOfSourceReached).ShouldEventually().BeTrue();

                model.Update();
                model.TotalCount.Should().Be(16114);

                model.SearchTerm = "RPC #12";
                var search = dataSource.Search;
                search.Property(x => x.Count).ShouldEventually().Be(334);

                model.Update();
                model.SearchResultCount.Should().Be(334);
                model.CurrentSearchResultIndex.Should().Be(0);
            }
        }
        public void TestSearch1()
        {
            using (var dataSource = new SingleDataSource(_scheduler, new DataSource(LogFileTest.File20Mb) { Id = Guid.NewGuid() }))
            {
                var dataSourceModel = new SingleDataSourceViewModel(dataSource);
                var model = new LogViewerViewModel(dataSourceModel, _dispatcher, TimeSpan.Zero);

                dataSourceModel.SearchTerm = "i";
                dataSource.FilteredLogFile.Property(x => x.EndOfSourceReached).ShouldEventually().BeTrue(TimeSpan.FromSeconds(20));
                // We have waited for that filter operation to finish, HOWEVER, did not invoke the dispatcher.
                // This causes all modifications from that operation to stay in the view-model's queue

                dataSourceModel.SearchTerm = "in";
                dataSourceModel.SearchTerm = "inf";
                dataSourceModel.SearchTerm = "info";

                // Now we wait for the very last filter operation to complete
                dataSource.FilteredLogFile.Property(x => x.EndOfSourceReached).ShouldEventually().BeTrue(TimeSpan.FromSeconds(20));
                // And then dispatch ALL events at ONCE.
                // We expect the view model to completely ignore the old changes!
                _dispatcher.InvokeAll();

                /*model.LogEntryCount.Should().Be(5);
                model.LogEntries.Select(x => x.Message)
                     .Should().Equal(new[]
                         {
                             "2015-10-07 19:50:58,982 [8092, 1] INFO  SharpRemote.Hosting.OutOfProcessSiloServer (null) - Silo Server starting, args (1): \"14056\", without custom type resolver"
                             ,
                             "2015-10-07 19:50:59,081 [8092, 1] INFO  SharpRemote.SocketRemotingEndPointServer (null) - EndPoint '<Unnamed>' listening on 0.0.0.0:49152"
                             ,
                             "2015-10-07 19:50:59,171 [8092, 6] INFO  SharpRemote.AbstractIPSocketRemotingEndPoint (null) - <Unnamed>: Connected to 127.0.0.1:10348"
                             ,
                             "2015-10-07 19:51:42,481 [8092, EndPoint '<Unnamed>' Socket Reading] INFO  SharpRemote.AbstractSocketRemotingEndPoint (null) - Disconnecting socket '<Unnamed>' from 127.0.0.1:10348: ReadFailure"
                             ,
                             "2015-10-07 19:51:42,483 [8092, 6] INFO  SharpRemote.Hosting.OutOfProcessSiloServer (null) - Parent process terminated unexpectedly (exit code: -1), shutting down..."
                         });*/
            }
        }
예제 #14
0
        public void TestLevelCount1()
        {
            using (var dataSource = new SingleDataSource(_scheduler, new DataSource(@"TestData\LevelCounts.txt") { Id = Guid.NewGuid() }))
            {
                dataSource.UnfilteredLogFile.Property(x => x.EndOfSourceReached).ShouldEventually().BeTrue();

                dataSource.TotalCount.Should().Be(21);
                dataSource.DebugCount.Should().Be(1);
                dataSource.InfoCount.Should().Be(2);
                dataSource.WarningCount.Should().Be(3);
                dataSource.ErrorCount.Should().Be(4);
                dataSource.FatalCount.Should().Be(5);
                dataSource.NoLevelCount.Should().Be(0);
            }
        }
예제 #15
0
 public void TestSearch1()
 {
     using (var dataSource = new SingleDataSource(_scheduler, CreateDataSource(), _logFile.Object, TimeSpan.Zero))
     {
         _entries.Add(new LogLine(0, 0, "Hello foobar world!", LevelFlags.None));
         _listeners.OnRead(1);
         dataSource.SearchTerm = "foobar";
         //dataSource.Search.Wait(TimeSpan.FromSeconds(5)).Should().BeTrue();
         dataSource.Search.Property(x => x.Count).ShouldEventually().Be(1, TimeSpan.FromSeconds(5));
         var matches = dataSource.Search.Matches.ToList();
         matches.Should().Equal(new[] {new LogMatch(0, new LogLineMatch(6, 6))});
     }
 }
예제 #16
0
        public void TestLevelPrecedence()
        {
            using (var dataSource = new SingleDataSource(_scheduler, new DataSource(@"TestData\DifferentLevels.txt") { Id = Guid.NewGuid() }))
            {
                dataSource.UnfilteredLogFile.Property(x => x.EndOfSourceReached).ShouldEventually().BeTrue();
                dataSource.UnfilteredLogFile.Count.Should().Be(6);
                LogLine[] lines = dataSource.UnfilteredLogFile.GetSection(new LogFileSection(0, 6));
                lines[0].Message.Should().Be("DEBUG ERROR WARN FATAL INFO");
                lines[0].Level.Should().Be(LevelFlags.Debug, "Because DEBUG is the first level to appear in the line");

                lines[1].Message.Should().Be("INFO DEBUG ERROR WARN FATAL");
                lines[1].Level.Should().Be(LevelFlags.Info, "Because INFO is the first level to appear in the line");

                lines[2].Message.Should().Be("WARN ERROR FATAL INFO DEBUG");
                lines[2].Level.Should().Be(LevelFlags.Warning, "Because WARN is the first level to appear in the line");

                lines[3].Message.Should().Be("ERROR INFO DEBUG FATAL WARN");
                lines[3].Level.Should().Be(LevelFlags.Error, "Because ERROR is the first level to appear in the line");

                lines[4].Message.Should().Be("FATAL ERROR INFO WARN DEBUG");
                lines[4].Level.Should().Be(LevelFlags.Fatal, "Because FATAL is the first level to appear in the line");

                lines[5].Message.Should().Be("fatal error info warn debug");
                lines[5].Level.Should()
                        .Be(LevelFlags.Fatal,
                            "Because this line belongs to the previous log entry and thus is marked as fatal as well");
                lines[5].LogEntryIndex.Should().Be(lines[4].LogEntryIndex);

                dataSource.DebugCount.Should().Be(1);
                dataSource.InfoCount.Should().Be(1);
                dataSource.WarningCount.Should().Be(1);
                dataSource.ErrorCount.Should().Be(1);
                dataSource.FatalCount.Should().Be(1);
                dataSource.NoLevelCount.Should().Be(0);
            }
        }
예제 #17
0
        private IReadOnlyList <IDataSource> SynchronizeDataSources(IReadOnlyList <IFileInfo> files)
        {
            var newFiles    = new List <IFileInfo>();
            var oldFiles    = new List <IFileInfo>();
            var dataSources = new List <IDataSource>();

            try
            {
                lock (_syncRoot)
                {
                    foreach (var file in _dataSources.Keys)
                    {
                        if (!files.Contains(file))
                        {
                            oldFiles.Add(file);
                        }
                    }

                    foreach (var file in oldFiles)
                    {
                        _dataSources.TryGetValue(file, out var dataSource);
                        _dataSources.Remove(file);
                        dataSource?.Dispose();
                    }

                    foreach (var file in files)
                    {
                        if (!_dataSources.TryGetValue(file, out var dataSource))
                        {
                            // We'll print a nice warning to the user if this happens
                            if (_dataSources.Count >= LogLineSourceId.MaxSources)
                            {
                                break;
                            }

                            var settings = new DataSource(file.FullPath)
                            {
                                Id = DataSourceId.CreateNew()
                            };
                            dataSource = new SingleDataSource(_logFileFactory,
                                                              _taskScheduler,
                                                              settings);
                            _dataSources.Add(file, dataSource);
                            newFiles.Add(file);
                        }

                        dataSources.Add(dataSource);
                    }
                }
            }
            catch (Exception)
            {
                foreach (var dataSource in dataSources)
                {
                    dataSource.Dispose();
                }
                throw;
            }

            if (Log.IsDebugEnabled)
            {
                Log.DebugFormat("Adding #{0} files ({1}), removing #{2} files ({3})",
                                newFiles.Count,
                                string.Join(", ", newFiles.Select(x => x.FullPath)),
                                oldFiles.Count,
                                string.Join(", ", oldFiles.Select(x => x.FullPath)));
            }

            return(dataSources);
        }
예제 #18
0
        public void TestRemove2()
        {
            var settings1 = new DataSource("foo") {Id = Guid.NewGuid()};
            var dataSource1 = new SingleDataSource(_scheduler, settings1);
            _merged.Add(dataSource1);

            var settings2 = new DataSource("bar") {Id = Guid.NewGuid()};
            var dataSource2 = new SingleDataSource(_scheduler, settings2);
            _merged.Add(dataSource2);

            _merged.Remove(dataSource2);
            _merged.UnfilteredLogFile.Should().NotBeNull();
            _merged.UnfilteredLogFile.Should().BeOfType<MergedLogFile>();
            ((MergedLogFile) _merged.UnfilteredLogFile).Sources.Should().Equal(new object[] {dataSource1.UnfilteredLogFile});
        }
예제 #19
0
 public void TestRemove1()
 {
     var settings = new DataSource("foo") {Id = Guid.NewGuid()};
     var dataSource = new SingleDataSource(_scheduler, settings);
     _merged.Add(dataSource);
     _merged.Remove(dataSource);
     dataSource.Settings.ParentId.Should().Be(Guid.Empty);
 }
 public void TestSetQuickFilterChain1()
 {
     var settings = new DataSource(@"E:\Code\SharpTail\SharpTail.Test\TestData\20Mb.test")
         {
             Id = Guid.NewGuid()
         };
     using (var dataSource = new SingleDataSource(_scheduler, settings))
     {
         var model = new SingleDataSourceViewModel(dataSource);
         var chain = new[] {new SubstringFilter("foobar", true)};
         model.QuickFilterChain = chain;
         model.QuickFilterChain.Should().BeSameAs(chain);
         dataSource.QuickFilterChain.Should().BeSameAs(chain);
     }
 }