예제 #1
0
        public void TestCreateAnalysis3()
        {
            var storage = new AnalysisStorage(_taskScheduler,
                                              _filesystem,
                                              _dataSourceAnalyserEngine.Object,
                                              _typeFactory);
            var analysisTemplate     = new AnalysisTemplate();
            var analysisViewTemplate = new AnalysisViewTemplate();
            var analysis             = storage.CreateAnalysis(analysisTemplate, analysisViewTemplate);

            analysisViewTemplate.Add(new PageTemplate {
                Title = "A great page"
            });

            var task = storage.SaveAsync(analysis.Id);

            task.Should().NotBeNull();
            task.Wait(TimeSpan.FromSeconds(5)).Should().BeTrue("because the modified template should've been saved");

            var anotherStorage = new AnalysisStorage(_taskScheduler,
                                                     _filesystem,
                                                     _dataSourceAnalyserEngine.Object,
                                                     _typeFactory);

            anotherStorage.AnalysisTemplates.Should().HaveCount(1, "because we've created and saved one template");
            var template = anotherStorage.AnalysisTemplates.First();

            template.Should().NotBeNull();
            template.ViewTemplate.Pages.Should().HaveCount(1, "because we've added one page to that template");
            var pageTemplate = template.ViewTemplate.Pages.First();

            pageTemplate.Should().NotBeNull();
            pageTemplate.Title.Should().Be("A great page");
        }
예제 #2
0
        public void TestRestoreSavedAnalysis()
        {
            AnalysisId id;
            {
                var storage = new AnalysisStorage(_taskScheduler,
                                                  _filesystem,
                                                  _logAnalyserEngine.Object,
                                                  _typeFactory);
                var analysis = storage.CreateAnalysis(new AnalysisTemplate(), new AnalysisViewTemplate());
                id = analysis.Id;

                var file = _filesystem.GetFileInfo(AnalysisStorage.GetFilename(analysis.Id));
                file.Exists.Result.Should().BeTrue("because CreateAnalysis() should've written the analysis to disk");
            }

            {
                var storage = new AnalysisStorage(_taskScheduler,
                                                  _filesystem,
                                                  _logAnalyserEngine.Object,
                                                  _typeFactory);
                storage.Analyses.Should().HaveCount(1);
                storage.AnalysisTemplates.Should().HaveCount(1);

                var analysis = storage.Analyses.First();
                analysis.Should().NotBeNull();
                analysis.Id.Should().Be(id);
                storage.TryGetAnalysisFor(analysis.Id, out var actualAnalysis).Should().BeTrue();
                actualAnalysis.Should().BeSameAs(analysis);

                storage.TryGetTemplateFor(analysis.Id, out var configuration).Should().BeTrue();
                configuration.Should().NotBeNull();
                configuration.Template.Should().NotBeNull();
                configuration.ViewTemplate.Should().NotBeNull();
            }
        }
예제 #3
0
        public void TestCreateAnalysis2()
        {
            var storage = new AnalysisStorage(_taskScheduler,
                                              _filesystem,
                                              _logAnalyserEngine.Object,
                                              _typeFactory);
            var analysis = storage.CreateAnalysis(new AnalysisTemplate(), new AnalysisViewTemplate());

            var id       = analysis.Id;
            var filename = Path.Combine(Constants.AnalysisDirectory, string.Format("{0}.{1}", id, Constants.AnalysisExtension));

            _filesystem.FileExists(filename).Result.Should().BeTrue("because the storage should've created a new file on disk");
        }
예제 #4
0
        public void TestCreateAnalysisFolder()
        {
            string analysisFolderPath = Constants.AnalysisDirectory;

            _filesystem.DirectoryExists(analysisFolderPath).Result.Should().BeFalse();

            var storage = new AnalysisStorage(_taskScheduler,
                                              _filesystem,
                                              _logAnalyserEngine.Object,
                                              _typeFactory);

            _filesystem.DirectoryExists(analysisFolderPath).Result.Should().BeTrue("because the storage should've created the analysis folder");
        }
예제 #5
0
        public void TestRemove2()
        {
            var storage = new AnalysisStorage(_taskScheduler,
                                              _filesystem,
                                              _logAnalyserEngine.Object,
                                              _typeFactory);
            var analysis = storage.CreateAnalysis(new AnalysisTemplate(), new AnalysisViewTemplate());

            ((ActiveAnalysis)analysis).IsDisposed.Should().BeFalse();

            storage.Remove(analysis.Id);
            ((ActiveAnalysis)analysis).IsDisposed.Should().BeTrue("because the storage created the analysis so it should dispose of it as well");
        }
예제 #6
0
        public void TestRemove3()
        {
            var analysis = _storage.CreateAnalysis(new AnalysisTemplate(), new AnalysisViewTemplate());

            ((ActiveAnalysis)analysis).IsDisposed.Should().BeFalse();

            var file = _filesystem.GetFileInfo(AnalysisStorage.GetFilename(analysis.Id));

            file.Exists.Result.Should().BeTrue("because CreateAnalysis() should've written the analysis to disk");

            _storage.Remove(analysis.Id);
            file.Exists.Result.Should().BeFalse("because Remove should've also removed the analysis from disk");
        }
예제 #7
0
        public void Setup()
        {
            _taskScheduler = new ManualTaskScheduler();
            _filesystem    = new InMemoryFilesystem(new ImmediateTaskScheduler());

            var root = Path.GetPathRoot(Constants.AnalysisDirectory);

            _filesystem.AddRoot(root);

            _logAnalyserEngine = new Mock <ILogAnalyserEngine>();
            _storage           = new AnalysisStorage(_taskScheduler,
                                                     _filesystem,
                                                     _logAnalyserEngine.Object);
        }
예제 #8
0
        public void TestCreateAnalysis1()
        {
            var storage = new AnalysisStorage(_taskScheduler,
                                              _filesystem,
                                              _logAnalyserEngine.Object,
                                              _typeFactory);

            storage.Analyses.Should().BeEmpty();

            var analysis = storage.CreateAnalysis(new AnalysisTemplate(), new AnalysisViewTemplate());

            analysis.Should().NotBeNull();
            analysis.Should().BeOfType <ActiveAnalysis>();

            storage.Analyses.Should().BeEquivalentTo(new object[] { analysis });
        }
예제 #9
0
        public void TestRemove3()
        {
            var storage = new AnalysisStorage(_taskScheduler,
                                              _filesystem,
                                              _logAnalyserEngine.Object,
                                              _typeFactory);
            var analysis = storage.CreateAnalysis(new AnalysisTemplate(), new AnalysisViewTemplate());

            ((ActiveAnalysis)analysis).IsDisposed.Should().BeFalse();

            var file = _filesystem.GetFileInfo(AnalysisStorage.GetFilename(analysis.Id));

            file.Exists.Result.Should().BeTrue("because CreateAnalysis() should've written the analysis to disk");

            storage.Remove(analysis.Id);
            file.Exists.Result.Should().BeFalse("because Remove should've also removed the analysis from disk");
        }
예제 #10
0
        public void TestRemove1()
        {
            var storage = new AnalysisStorage(_taskScheduler,
                                              _filesystem,
                                              _logAnalyserEngine.Object,
                                              _typeFactory);

            storage.AnalysisTemplates.Should().BeEmpty();
            var analysis = storage.CreateAnalysis(new AnalysisTemplate(), new AnalysisViewTemplate());

            storage.AnalysisTemplates.Should().HaveCount(1);
            IAnalysis unused;

            storage.TryGetAnalysisFor(analysis.Id, out unused).Should().BeTrue();

            storage.Remove(analysis.Id);
            storage.AnalysisTemplates.Should().BeEmpty("because the only analysis should've been removed");
            storage.TryGetAnalysisFor(analysis.Id, out unused).Should().BeFalse("because the only analysis should've been removed");
        }
예제 #11
0
        private static int StartInternal(SingleApplicationHelper.IMutex mutex, string[] args)
        {
            InstallExceptionHandlers();
            Log.InfoFormat("Starting tailviewer...");
            Log.InfoFormat("Commandline arguments: {0}", string.Join(" ", args));
            LogEnvironment();

            ApplicationSettings settings = ApplicationSettings.Create();

            settings.Restore(out var neededPatching);

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

            var actionCenter = new ActionCenter();

            using (var taskScheduler = new DefaultTaskScheduler())
                using (var serialTaskScheduler = new SerialTaskScheduler())
                {
                    var filesystem = new Filesystem(serialTaskScheduler);
                    using (var pluginArchiveLoader = new PluginArchiveLoader(filesystem, Constants.PluginPath))
                    {
                        var pluginSystem = CreatePluginSystem(pluginArchiveLoader);

                        var fileFormatPlugins = pluginSystem.LoadAllOfType <IFileFormatPlugin>();

                        var logFileFactory = new PluginLogFileFactory(taskScheduler, fileFormatPlugins);
                        using (var dataSources = new DataSources(logFileFactory, taskScheduler, settings.DataSources))
                            using (var updater = new AutoUpdater(actionCenter, settings.AutoUpdate))
                                using (var logAnalyserEngine = new LogAnalyserEngine(taskScheduler, pluginSystem))
                                    using (var dataSourceAnalyserEngine = new DataSourceAnalyserEngine(taskScheduler, logAnalyserEngine, pluginSystem))
                                        using (var analysisStorage = new AnalysisStorage(taskScheduler, filesystem, dataSourceAnalyserEngine, CreateTypeFactory(pluginSystem)))
                                        {
                                            var arguments = ArgumentParser.TryParse(args);
                                            if (arguments.FileToOpen != null)
                                            {
                                                if (File.Exists(arguments.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.AddDataSource(arguments.FileToOpen);
                                                    settings.DataSources.SelectedItem = dataSource.Id;
                                                }
                                                else
                                                {
                                                    Log.ErrorFormat("File '{0}' does not exist, won't open it!", arguments.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);
                                            actionCenter.Add(Build.Current);
                                            actionCenter.Add(Change.Merge(Changelog.MostRecentPatches));
                                            var application  = new App();
                                            var dispatcher   = Dispatcher.CurrentDispatcher;
                                            var uiDispatcher = new UiDispatcher(dispatcher);
                                            dispatcher.UnhandledException         += actionCenter.ReportUnhandledException;
                                            TaskScheduler.UnobservedTaskException += actionCenter.ReportUnhandledException;

                                            var window = new MainWindow(settings)
                                            {
                                                DataContext = new MainWindowViewModel(settings,
                                                                                      dataSources,
                                                                                      quickFilters,
                                                                                      actionCenter,
                                                                                      updater,
                                                                                      taskScheduler,
                                                                                      analysisStorage,
                                                                                      uiDispatcher,
                                                                                      pluginSystem)
                                            };

                                            settings.MainWindow.RestoreTo(window);

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

                                            return(application.Run());
                                        }
                    }
                }
        }