Beispiel #1
0
        protected override void OnStartup(StartupEventArgs args)
        {
            using (Duration.Measure(Logger, "OnStartup - " + GetType().Name))
            {
                Logger.Info("Starting");

                // ReSharper disable once RedundantToStringCallForValueType
                var dispatcherMessage =
                    $"Dispatcher managed thread identifier = {Thread.CurrentThread.ManagedThreadId.ToString()}";

                Logger.Info(dispatcherMessage);
                Debug.WriteLine(dispatcherMessage);

                Logger.Info($"WPF rendering capability (tier) = {(RenderCapability.Tier / 0x10000).ToString()}");
                RenderCapability.TierChanged += (s, a) =>
                                                Logger.Info($"WPF rendering capability (tier) = {(RenderCapability.Tier / 0x10000).ToString()}");

                base.OnStartup(args);

                BootStrapper.Start();

                var schedulerService = BootStrapper.Resolve <ISchedulerService>();
                var messageService   = BootStrapper.Resolve <IMessageService>();
                var gestureService   = BootStrapper.Resolve <IGestureService>();

                ObservableExtensions.GestureService = gestureService;

                // Load the application settings asynchronously
                LoadSettingsAsync(schedulerService)
                .Wait();

                var window = new MainWindow(messageService, schedulerService);

                // The window has to be created before the root visual - all to do with the idling service initialising correctly...
                window.DataContext = BootStrapper.RootVisual;

                window.Closed += HandleClosed;
                Current.Exit  += HandleExit;

                // Let's go...
                window.Show();


                if (Logger.IsInfoEnabled)
                {
                    // Monitoring heartbeat only when info level is enabled...
                    ObserveHeartbeat(schedulerService)
                    .DisposeWith(_disposable);
                }

#if DEBUG
                ObserveUiFreeze()
                .DisposeWith(_disposable);
#endif
                ObserveCultureChanges()
                .DisposeWith(_disposable);

                Logger.Info("Started");
            }
        }
Beispiel #2
0
        private static void HandleException(Exception exception)
        {
            Logger.Error(exception);

            BootStrapper.Resolve <ISchedulerService>()
            .Dispatcher
            .Schedule(exception, (scheduler, state) =>
            {
                var messageService = BootStrapper.Resolve <IMessageService>();

                var parameters = new Parameter[]
                {
                    new NamedParameter("exception", state)
                };

                var viewModel = BootStrapper.Resolve <IExceptionViewModel>(parameters);

                Observable.Return(viewModel)
                .SelectMany(x => x.Closed, (x, y) => x)
                .Take(1)
                .Subscribe(x => x.Dispose());

                messageService.Post(Constants.UI.ExceptionTitle, viewModel);

                return(Disposable.Empty);
            });
        }
Beispiel #3
0
        private static IObservable <Unit> LoadSettingsAsync(ISchedulerService schedulerService)
        {
            return(Observable.Create <Unit>(x =>
            {
                BootStrapper.Resolve <ISettingsService>();

                x.OnNext(Unit.Default);
                x.OnCompleted();

                return Disposable.Empty;
            })
                   .SubscribeOn(schedulerService.TaskPool));
        }
Beispiel #4
0
        private static IDisposable ObserveHeartbeat(ISchedulerService schedulerService)
        {
            var diagnosticsService = BootStrapper.Resolve <IDiagnosticsService>();

            return(BootStrapper.Resolve <IHeartbeatService>()
                   .Listen
                   .SelectMany(x => diagnosticsService.Memory.Take(1), (x, y) => y)
                   .SelectMany(x => diagnosticsService.Cpu.Take(1), (x, y) => new Tuple <Memory, int>(x, y))
                   .Select(x => $"Heartbeat (Memory={x.Item1.WorkingSetPrivateAsString()}, CPU={x.Item2.ToString()}%)")
                   .ObserveOn(schedulerService.Dispatcher)
                   .Subscribe(x =>
            {
                Debug.WriteLine(x);
                Logger.Info(x);
            }));
        }