Ejemplo n.º 1
0
        public void TestCtor()
        {
            var scheduler = new SerialTaskScheduler(logExceptions: true);

            scheduler.Dispose();
            scheduler.Exceptions.Should().BeEmpty();
        }
Ejemplo n.º 2
0
        public void TestScheduleOneTask()
        {
            var scheduler = new SerialTaskScheduler(logExceptions: true);
            var task      = scheduler.QueueTask(() => 42);

            task.Wait(TimeSpan.FromSeconds(10)).Should().BeTrue();
            task.Result.Should().Be(42);
            scheduler.Dispose();
            scheduler.Exceptions.Should().BeEmpty();
        }
Ejemplo n.º 3
0
        public void TestStarStopThread()
        {
            using (var scheduler = new SerialTaskScheduler(TimeSpan.FromMilliseconds(100), true))
            {
                scheduler.IsExecutingThreadRunning.Should().BeFalse("Because no task has ever been scheduled and thus no additional thread should be waiting for it");
                scheduler.QueueTask(() => { });
                scheduler.IsExecutingThreadRunning.Should().BeTrue("Because a task has just been queued");

                // F*****g AppVeyor is so incredibly slow, no amount of timeout is enough.
                WaitFor(() => scheduler.IsExecutingThreadRunning == false,
                        TimeSpan.FromSeconds(10)).Should().BeTrue("Because for twice the timeout no additional task has been executed and thus the thread should've been ended");

                scheduler.Exceptions.Should().BeEmpty("Because no exceptions should've been thrown in the process");
            }
        }
Ejemplo n.º 4
0
        public void TestScheduleManyTasks()
        {
            var       scheduler = new SerialTaskScheduler(logExceptions: true);
            const int taskCount = 1000;
            var       tasks     = new List <Task <int> >(taskCount);

            for (int i = 0; i < taskCount; ++i)
            {
                var task = scheduler.QueueTask(() => 42);
                tasks.Add(task);
            }
            Task.WaitAll(tasks.Cast <Task>().ToArray(), TimeSpan.FromSeconds(10))
            .Should().BeTrue();
            tasks.All(x => x.Result == 42).Should().BeTrue();
            scheduler.Exceptions.Should().BeEmpty();
        }
Ejemplo n.º 5
0
        public void TestSchedulerHighjacking()
        {
            using (var scheduler = new SerialTaskScheduler(logExceptions: true))
            {
                TaskScheduler actualInnerScheduler = null;
                var           task = scheduler.QueueTask(() =>
                {
                    var task2 = new Task <int>(() =>
                    {
                        actualInnerScheduler = TaskScheduler.Current;
                        return(42);
                    });
                    task2.Start();
                    return(task2.Result);
                });

                task.Wait(TimeSpan.FromSeconds(1)).Should().BeTrue();
                task.Result.Should().Be(42);
                actualInnerScheduler.Should().BeSameAs(TaskScheduler.Default);
            }
        }
Ejemplo n.º 6
0
 public Storage()
 {
     _scheduler = new SerialTaskScheduler();
     OpenAsync();
 }
Ejemplo n.º 7
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());
                            }
                    }
                }
        }
Ejemplo n.º 8
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());
                                        }
                    }
                }
        }