public SettingsViewModel(ApplicationSettings settings)
        {
            if (settings == null)
                throw new ArgumentNullException("settings");

            _settings = settings;
        }
        public DataSourcesViewModel(ApplicationSettings settings, DataSources dataSources)
        {
            if (settings == null) throw new ArgumentNullException("settings");
            if (dataSources == null) throw new ArgumentNullException("dataSources");

            _settings = settings;
            _observable = new ObservableCollection<IDataSourceViewModel>();
            _allDataSourceViewModels = new List<IDataSourceViewModel>();
            _dataSources = dataSources;
            foreach (IDataSource dataSource in dataSources)
            {
                if (dataSource.ParentId == Guid.Empty)
                {
                    Add(dataSource);
                }
            }

            foreach (IDataSource dataSource in dataSources)
            {
                Guid parentId = dataSource.ParentId;
                if (parentId != Guid.Empty)
                {
                    IDataSourceViewModel parent = _observable.First(x => x.DataSource.Id == parentId);
                    var group = (MergedDataSourceViewModel) parent;
                    IDataSourceViewModel viewModel = CreateViewModel(dataSource);
                    group.AddChild(viewModel);
                }
            }
        }
 public void TestRestore2()
 {
     var settings = new ApplicationSettings(@"Settings\settings_no_file_guid.xml");
     bool neededPatching;
     settings.Restore(out neededPatching);
     settings.DataSources.Count.Should().Be(2);
     settings.DataSources[0].Id.Should().NotBe(Guid.Empty);
     settings.DataSources[1].Id.Should().NotBe(Guid.Empty);
     settings.DataSources[0].Id.Should().NotBe(settings.DataSources[1].Id);
     neededPatching.Should().BeTrue("Because we should now be saving the settings again due to the upgrade");
 }
        public QuickFiltersViewModel(ApplicationSettings settings, QuickFilters quickFilters)
        {
            if (settings == null) throw new ArgumentNullException("settings");
            if (quickFilters == null) throw new ArgumentNullException("quickFilters");

            _settings = settings;
            _quickFilters = quickFilters;
            _addCommand = new DelegateCommand(() => AddQuickFilter());
            _viewModels = new ObservableCollection<QuickFilterViewModel>();
            foreach (QuickFilter filter in quickFilters.Filters)
            {
                CreateAndAddViewModel(filter);
            }
        }
 public void SetUp()
 {
     _settings = new ApplicationSettings("adwad");
     _dispatcher = new ManualDispatcher();
     _scheduler = new ManualTaskScheduler();
     _dataSources = new DataSources(_scheduler, _settings.DataSources);
     _quickFilters = new QuickFilters(_settings.QuickFilters);
     _actionCenter = new ActionCenter();
     _updater = new Mock<IAutoUpdater>();
     _mainWindow = new MainWindowViewModel(_settings,
                                           _dataSources,
                                           _quickFilters,
                                           _actionCenter,
                                           _updater.Object,
                                           _dispatcher);
 }
示例#6
0
        internal MainWindow(ApplicationSettings settings)
        {
            if (settings == null) throw new ArgumentNullException("settings");

            _settings = settings;
            FocusLogFileSearchCommand = new DelegateCommand(FocusLogFileSearch);
            FocusDataSourceSearchCommand = new DelegateCommand(FocusDataSourceSearch);

            InitializeComponent();
            Closing += OnClosing;
            DragEnter += OnDragEnter;
            DragOver += OnDragOver;
            Drop += OnDrop;
            MouseMove += OnMouseMove;

            DragLayer.AdornerLayer = PART_DragDecorator.AdornerLayer;
        }
        public void TestDataSourceId()
        {
            string fname = Path.GetTempFileName();
            var settings = new ApplicationSettings(fname);
            var dataSource = new DataSource("foo");
            dataSource.Id = Guid.NewGuid();
            settings.DataSources.Add(dataSource);
            settings.Save();

            var settings2 = new ApplicationSettings(fname);
            bool neededPatching;
            settings2.Restore(out neededPatching);
            neededPatching.Should().BeFalse();
            settings2.DataSources.Count.Should().Be(1);
            DataSource dataSource2 = settings2.DataSources[0];
            dataSource2.File.Should().Be("foo");
            dataSource2.Id.Should().Be(dataSource.Id);
        }
        public void TestRestore3()
        {
            string fname = Path.GetTempFileName();
            var settings = new ApplicationSettings(fname);
            DateTime timestamp = DateTime.Now;
            settings.DataSources.Add(new DataSource("dawadaw")
                {
                    LastViewed = timestamp
                });

            settings.Save();
            settings = new ApplicationSettings(fname);
            settings.Restore();

            settings.DataSources.Count.Should().Be(1);
            DataSource source = settings.DataSources[0];
            source.Should().NotBeNull();
            source.LastViewed.Should().Be(timestamp);
        }
        public MainWindowViewModel(ApplicationSettings settings,
		                           DataSources dataSources,
		                           QuickFilters quickFilters,
		                           IActionCenter actionCenter,
		                           IAutoUpdater updater,
		                           IDispatcher dispatcher)
        {
            if (dataSources == null) throw new ArgumentNullException("dataSources");
            if (quickFilters == null) throw new ArgumentNullException("quickFilters");
            if (updater == null) throw new ArgumentNullException("updater");
            if (dispatcher == null) throw new ArgumentNullException("dispatcher");

            _dataSourcesViewModel = new DataSourcesViewModel(settings, dataSources);
            _dataSourcesViewModel.PropertyChanged += DataSourcesViewModelOnPropertyChanged;
            _quickFilters = new QuickFiltersViewModel(settings, quickFilters);
            _quickFilters.OnFiltersChanged += OnQuickFiltersChanged;
            _settings = new SettingsViewModel(settings);
            _actionCenter = new ActionCenterViewModel(dispatcher, actionCenter);

            _timer = new DispatcherTimer
                {
                    Interval = TimeSpan.FromMilliseconds(100)
                };
            _timer.Tick += TimerOnTick;
            _timer.Start();

            _autoUpdater = new AutoUpdateViewModel(updater, settings.AutoUpdate, dispatcher);

            _dispatcher = dispatcher;
            WindowTitle = Constants.MainWindowTitle;

            _selectNextDataSourceCommand = new DelegateCommand(SelectNextDataSource);
            _selectPreviousDataSourceCommand = new DelegateCommand(SelectPreviousDataSource);
            _addDataSourceCommand = new DelegateCommand(AddDataSource);

            ChangeDataSource(CurrentDataSource);
        }
        public void TestCtor1()
        {
            _settings = new ApplicationSettings("foobar");
            var group = new DataSource {Id = Guid.NewGuid()};
            var source1 = new DataSource("foo") {Id = Guid.NewGuid(), ParentId = group.Id};
            var source2 = new DataSource("bar") {Id = Guid.NewGuid(), ParentId = group.Id};
            var source3 = new DataSource("clondyke") {Id = Guid.NewGuid()};
            _settings.DataSources.Add(group);
            _settings.DataSources.Add(source1);
            _settings.DataSources.Add(source2);
            _settings.DataSources.Add(source3);
            _dataSources = new DataSources(_scheduler, _settings.DataSources);
            _model = new DataSourcesViewModel(_settings, _dataSources);
            _model.Observable.Count.Should().Be(2);
            IDataSourceViewModel viewModel = _model.Observable[0];
            viewModel.Should().NotBeNull();
            viewModel.Should().BeOfType<MergedDataSourceViewModel>();
            viewModel.DataSource.Id.Should().Be(group.Id);
            var merged = (MergedDataSourceViewModel) viewModel;
            merged.Observable.Count().Should().Be(2);
            merged.Observable.ElementAt(0).DataSource.Id.Should().Be(source1.Id);
            merged.Observable.ElementAt(1).DataSource.Id.Should().Be(source2.Id);

            viewModel = _model.Observable[1];
            viewModel.Should().NotBeNull();
            viewModel.Should().BeOfType<SingleDataSourceViewModel>();
            viewModel.DataSource.Id.Should().Be(source3.Id);
        }
 public void SetUp()
 {
     _settings = new ApplicationSettings("dawddwa");
     _dataSources = new DataSources(_scheduler, _settings.DataSources);
     _model = new DataSourcesViewModel(_settings, _dataSources);
 }
        public void TestRemove1()
        {
            _settings = new ApplicationSettings("foobar");
            var source = new DataSource("foo") {Id = Guid.NewGuid()};
            _settings.DataSources.Add(source);
            _dataSources = new DataSources(_scheduler, _settings.DataSources);
            _model = new DataSourcesViewModel(_settings, _dataSources);
            IDataSourceViewModel viewModel = _model.Observable[0];
            viewModel.RemoveCommand.Execute(null);

            _model.Observable.Should().BeEmpty();
            _dataSources.Should().BeEmpty();
            _settings.DataSources.Should().BeEmpty();
        }
 public void SetUp()
 {
     _settings = new ApplicationSettings("foo");
     _model = new SettingsViewModel(_settings);
 }
        public void TestRemove2()
        {
            _settings = new ApplicationSettings("foobar");
            var group = new DataSource {Id = Guid.NewGuid()};
            var source1 = new DataSource("foo") {Id = Guid.NewGuid(), ParentId = group.Id};
            var source2 = new DataSource("bar") {Id = Guid.NewGuid(), ParentId = group.Id};
            var source3 = new DataSource("clondyke") {Id = Guid.NewGuid(), ParentId = group.Id};
            _settings.DataSources.Add(source1);
            _settings.DataSources.Add(source2);
            _settings.DataSources.Add(source3);
            _settings.DataSources.Add(group);
            _dataSources = new DataSources(_scheduler, _settings.DataSources);
            _model = new DataSourcesViewModel(_settings, _dataSources);
            var merged = (MergedDataSourceViewModel) _model.Observable[0];
            IDataSourceViewModel viewModel1 = merged.Observable.ElementAt(0);
            IDataSourceViewModel viewModel2 = merged.Observable.ElementAt(1);
            IDataSourceViewModel viewModel3 = merged.Observable.ElementAt(2);
            viewModel1.RemoveCommand.Execute(null);

            merged.ChildCount.Should().Be(2);
            merged.Observable.Should().NotContain(viewModel1);
            _model.Observable.Should().Equal(new object[] {merged});
            _dataSources.Should().Equal(new object[] {viewModel2.DataSource, viewModel3.DataSource, merged.DataSource});
            _settings.DataSources.Should().Equal(new object[] {source2, source3, group});
        }
示例#15
0
        private static int StartApplication(SingleApplicationHelper.IMutex mutex, string fileToOpen, Stopwatch stopwatch)
        {
            ApplicationSettings settings = ApplicationSettings.Create();

            settings.Restore(out var neededPatching);
            settings.AllowSave = false;             //< We will allow saving once the app is fully booted

            if (neededPatching)
            {
                // TODO: Save settings right again to complete the upgrade
                //       (maybe we should preserve an old version)
            }

            var bookmarks = Bookmarks.Create();

            bookmarks.Restore();

            var services = new ServiceContainer();

            services.RegisterInstance <ILogFileSettings>(settings.LogFile);

            var actionCenter = new ActionCenter();

            using (var taskScheduler = new DefaultTaskScheduler())
                using (var serialTaskScheduler = new SerialTaskScheduler())
                {
                    services.RegisterInstance <ITaskScheduler>(taskScheduler);
                    services.RegisterInstance <ISerialTaskScheduler>(serialTaskScheduler);
                    var navigationService = new NavigationService();
                    services.RegisterInstance <INavigationService>(navigationService);

                    var filesystem = new Filesystem(taskScheduler);
                    services.RegisterInstance <IFilesystem>(filesystem);

                    using (var pluginArchiveLoader = new PluginArchiveLoader(filesystem, Constants.PluginPath, Constants.DownloadedPluginsPath))
                    {
                        var pluginUpdater = new PluginUpdater(pluginArchiveLoader);
                        services.RegisterInstance <IPluginUpdater>(pluginUpdater);

                        var pluginSystem = CreatePluginSystem(pluginArchiveLoader);
                        services.RegisterInstance <IPluginLoader>(pluginSystem);

                        var logFileFormatRegistry = new LogFileFormatRegistry(pluginSystem, settings.CustomFormats);
                        services.RegisterInstance <ILogFileFormatRepository>(logFileFormatRegistry);
                        services.RegisterInstance <ILogFileFormatRegistry>(logFileFormatRegistry);

                        var logFileFormatMatcher = new LogFileFormatMatcher(services);
                        services.RegisterInstance <ILogFileFormatMatcher>(logFileFormatMatcher);

                        var textLogFileParserPlugin = new LogEntryParserFactory(services);
                        services.RegisterInstance <ILogEntryParserPlugin>(textLogFileParserPlugin);

                        var propertyPresenter = new PropertyPresenterRegistry(pluginSystem);
                        services.RegisterInstance <IPropertyPresenterPlugin>(propertyPresenter);

                        var fileLogSourceFactory = new StreamingTextLogSourceFactory(filesystem, taskScheduler);
                        services.RegisterInstance <IRawFileLogSourceFactory>(fileLogSourceFactory);

                        var parsingLogSourceFactory = new ParsingLogSourceFactory(services);
                        services.RegisterInstance <ILogSourceParserPlugin>(parsingLogSourceFactory);

                        var customDataSourcePlugins = pluginSystem.LoadAllOfTypeWithDescription <ICustomDataSourcePlugin>();
                        var logFileFactory          = new PluginLogSourceFactory(services, customDataSourcePlugins);
                        using (var dataSources = new DataSources(logFileFactory, taskScheduler, filesystem, settings.DataSources, bookmarks))
                            using (var updater = new AutoUpdater(actionCenter, settings.AutoUpdate))
                            {
                                if (fileToOpen != null)
                                {
                                    if (File.Exists(fileToOpen))
                                    {
                                        // Not only do we want to add this file to the list of data sources,
                                        // but we also want to select it so the user can view it immediately, regardless
                                        // of what was selected previously.
                                        var dataSource = dataSources.AddFile(fileToOpen);
                                        settings.DataSources.SelectedItem = dataSource.Id;
                                    }
                                    else
                                    {
                                        Log.ErrorFormat("File '{0}' does not exist, won't open it!", fileToOpen);
                                    }
                                }

                                if (settings.AutoUpdate.CheckForUpdates)
                                {
                                    // Our initial check for updates is not due to a user action
                                    // and therefore we don't need to show a notification when the
                                    // application is up-to-date.
                                    updater.CheckForUpdates(addNotificationWhenUpToDate: false);
                                }

                                var quickFilters = new QuickFilters(settings.QuickFilters);
                                var highlighters = new HighlighterCollection();
                                services.RegisterInstance <IHighlighters>(highlighters);

                                actionCenter.Add(Build.Current);
                                actionCenter.Add(Change.Merge(Changelog.MostRecentPatches));
                                var application  = new App();
                                var dispatcher   = Dispatcher.CurrentDispatcher;
                                var uiDispatcher = new UiDispatcher(dispatcher);
                                services.RegisterInstance <IDispatcher>(uiDispatcher);

                                dispatcher.UnhandledException         += actionCenter.ReportUnhandledException;
                                TaskScheduler.UnobservedTaskException += actionCenter.ReportUnhandledException;

                                var windowViewModel = new MainWindowViewModel(services,
                                                                              settings,
                                                                              dataSources,
                                                                              quickFilters,
                                                                              actionCenter,
                                                                              updater);
                                navigationService.MainWindow = windowViewModel;

                                var window = new MainWindow(settings, windowViewModel);

                                settings.MainWindow.ClipToBounds(Desktop.Current);
                                settings.MainWindow.RestoreTo(window);
                                settings.AllowSave = true;

                                stopwatch.Stop();
                                Log.InfoFormat("Tailviewer started (took {0}ms), showing window...", stopwatch.ElapsedMilliseconds);

                                window.Show();
                                mutex?.SetListener(window);

                                return(application.Run());
                            }
                    }
                }
        }
        public void TestCtor2()
        {
            _settings = new ApplicationSettings("foobar");
            var group = new DataSource {Id = Guid.NewGuid()};
            var source = new DataSource("foo") {Id = Guid.NewGuid(), ParentId = Guid.NewGuid()};
            _settings.DataSources.Add(group);
            _settings.DataSources.Add(source);
            _dataSources = new DataSources(_scheduler, _settings.DataSources);
            new Action(() => _model = new DataSourcesViewModel(_settings, _dataSources)).ShouldNotThrow();
            _model.Observable.Count.Should().Be(2);
            IDataSourceViewModel viewModel = _model.Observable[0];
            viewModel.Should().NotBeNull();
            viewModel.Should().BeOfType<MergedDataSourceViewModel>();
            viewModel.DataSource.Id.Should().Be(group.Id);
            var merged = (MergedDataSourceViewModel) viewModel;
            merged.Observable.Should().BeEmpty();

            viewModel = _model.Observable[1];
            viewModel.Should().NotBeNull();
            viewModel.Should().BeOfType<SingleDataSourceViewModel>();
        }
        public void TestStoreRestore()
        {
            const string fileName = "applicationsettingstest.xml";
            var settings = new ApplicationSettings(fileName);
            settings.MainWindow.Left = 1;
            settings.MainWindow.Top = 2;
            settings.MainWindow.Width = 3;
            settings.MainWindow.Height = 4;
            settings.MainWindow.State = WindowState.Maximized;
            settings.DataSources.Add(new DataSource(@"SharpRemote.Host.1600.log")
                {
                    Id = Guid.NewGuid(),
                    FollowTail = true,
                    SearchTerm = "foobar",
                    LevelFilter = LevelFlags.Debug,
                    VisibleLogLine = new LogLineIndex(1),
                    ShowLineNumbers = false,
                    ActivatedQuickFilters =
                        {
                            Guid.NewGuid(),
                            Guid.NewGuid(),
                            Guid.NewGuid(),
                        }
                });
            settings.DataSources.Add(new DataSource(@"SharpRemote.Host.1700.log")
            {
                Id = Guid.NewGuid(),
                FollowTail = false,
                ShowLineNumbers = true,
            });
            List<Guid> guids = settings.DataSources[0].ActivatedQuickFilters.ToList();
            settings.QuickFilters.Add(new QuickFilter
                {
                    Value = "foobar",
                    IgnoreCase = true,
                    MatchType = QuickFilterMatchType.RegexpFilter,
                    IsInverted = true,
                });
            settings.QuickFilters.Add(new QuickFilter
            {
                Value = "clondykebar",
                IgnoreCase = false,
                MatchType = QuickFilterMatchType.WildcardFilter,
                IsInverted = false,
            });
            Guid filterId1 = settings.QuickFilters[0].Id;
            Guid filterId2 = settings.QuickFilters[1].Id;
            settings.DataSources.SelectedItem = settings.DataSources[0].Id;
            settings.Save().Should().BeTrue();

            settings = new ApplicationSettings(fileName);
            settings.Restore();
            settings.MainWindow.Left.Should().Be(1);
            settings.MainWindow.Top.Should().Be(2);
            settings.MainWindow.Width.Should().Be(3);
            settings.MainWindow.Height.Should().Be(4);
            settings.MainWindow.State.Should().Be(WindowState.Maximized);
            settings.DataSources.Count.Should().Be(2);
            settings.DataSources[0].File.Should().Be(@"SharpRemote.Host.1600.log");
            settings.DataSources[0].FollowTail.Should().BeTrue();
            settings.DataSources[0].ShowLineNumbers.Should().BeFalse();
            settings.DataSources[0].SearchTerm.Should().Be("foobar");
            settings.DataSources[0].LevelFilter.Should().Be(LevelFlags.Debug);
            settings.DataSources[0].VisibleLogLine.Should().Be(new LogLineIndex(1));
            settings.DataSources[0].ActivatedQuickFilters.Should().Equal(guids);
            settings.DataSources[1].File.Should().Be(@"SharpRemote.Host.1700.log");
            settings.DataSources[1].FollowTail.Should().BeFalse();
            settings.DataSources[1].ShowLineNumbers.Should().BeTrue();
            settings.DataSources.SelectedItem.Should().NotBe(Guid.Empty);
            settings.DataSources.SelectedItem.Should().Be(settings.DataSources[0].Id);

            settings.QuickFilters.Count.Should().Be(2);
            settings.QuickFilters[0].Id.Should().Be(filterId1);
            settings.QuickFilters[0].Value.Should().Be("foobar");
            settings.QuickFilters[0].IgnoreCase.Should().BeTrue();
            settings.QuickFilters[0].MatchType.Should().Be(QuickFilterMatchType.RegexpFilter);
            settings.QuickFilters[0].IsInverted.Should().BeTrue();

            settings.QuickFilters[1].Id.Should().Be(filterId2);
            settings.QuickFilters[1].Value.Should().Be("clondykebar");
            settings.QuickFilters[1].IgnoreCase.Should().BeFalse();
            settings.QuickFilters[1].MatchType.Should().Be(QuickFilterMatchType.WildcardFilter);
            settings.QuickFilters[1].IsInverted.Should().BeFalse();
        }
        public void TestStore1()
        {
            string path = Path.GetTempPath();
            const string folderName = "ApplicationSettingsTest";
            const string fileName = "settings.xml";
            string fileFolder = Path.Combine(path, folderName);
            string filePath = Path.Combine(fileFolder, fileName);

            if (File.Exists(filePath))
                File.Delete(filePath);

            if (Directory.Exists(fileFolder))
                Directory.Delete(fileFolder);

            var settings = new ApplicationSettings(filePath);
            settings.QuickFilters.Add(new QuickFilter());
            settings.Save().Should().BeTrue();

            File.Exists(filePath);
            var settings2 = new ApplicationSettings(filePath);
            settings2.Restore();
            settings2.QuickFilters.Count.Should().Be(1);
        }
        public void TestRestore4()
        {
            string fname = Path.GetTempFileName();
            var settings = new ApplicationSettings(fname);
            settings.DataSources.Add(new DataSource("dawadaw")
            {
                VisibleLogLine = 42,
                HorizontalOffset = 142.42
            });

            settings.Save();
            settings = new ApplicationSettings(fname);
            settings.Restore();

            settings.DataSources.Count.Should().Be(1);
            DataSource source = settings.DataSources[0];
            source.Should().NotBeNull();
            source.VisibleLogLine.Should().Be(42);
            source.HorizontalOffset.Should().Be(142.42);
        }