public ReactiveApplication()
        {
            this.Log().Info("Starting ReactiveApplication.");
            this.Log().Info("Creating Dependency Resolver.");
            var resolver = this.CreateDependencyResolver();
            this.Log().Info("Initialize Dependency Resolver.");
            resolver.InitializeSplat();
            resolver.InitializeReactiveUI();
            Locator.Current = resolver;

            this.Log().Info("Creating Shell.");
            this.Shell = this.CreateShell();
            #if WINDOWS_PHONE
            this.frameHelper = new PhoneFrameHelper(this.Shell);
            #endif

            this.Log().Info("Creating SuspensionService.");
            #if !WINDOWS_PHONE
            var suspensionService = new SuspensionService(this, launched);
            #else
            this.ApplicationLifetimeObjects.Add(new PhoneApplicationService());
            var suspensionService = new SuspensionService(this, this.frameHelper);
            #endif
            this.SuspensionService = suspensionService;

            this.Log().Info("Register services.");
            this.Configure();
        }
 internal static void Initialize(IPhoneFrameHelper f)
 {
     systemTrayDisposable.Dispose();
     systemTrayDisposable = Observable.FromEventPattern<NavigatedEventHandler, NavigationEventArgs>(h => f.Frame.Navigated += h, h => f.Frame.Navigated -= h)
         .Where(ep => ep.EventArgs.Content != null).Subscribe(ep =>
         {
             PhoneApplicationPage page = ep.EventArgs.Content as PhoneApplicationPage;
             if (page != null && page.GetType() == typeof(BackwardsCompatibilityPage))
             {
                 systemTray.Initialize(page);
             }
             else
             {
                 systemTray.Uninitialize();
             }
         });
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="SuspensionService"/> class.
        /// </summary>
        /// <param name="app">The application.</param>
        /// <param name="frameHelper">The frame helper.</param>
        public SuspensionService(Application app, IPhoneFrameHelper frameHelper)
        {
            this.IsLaunchingNew =
                Observable.FromEventPattern<LaunchingEventArgs>(
                    x => PhoneApplicationService.Current.Launching += x, x => PhoneApplicationService.Current.Launching -= x)
                    .SelectMany(_ => frameHelper.Arguments.FirstOrDefaultAsync());

            this.IsUnpausing =
                Observable.FromEventPattern<ActivatedEventArgs>(
                    x => PhoneApplicationService.Current.Activated += x, x => PhoneApplicationService.Current.Activated -= x)
                    .Where(x => x.EventArgs.IsApplicationInstancePreserved)
                    .SelectMany(_ => frameHelper.Arguments.FirstOrDefaultAsync());

            // NB: "Applications should not perform resource-intensive tasks
            // such as loading from isolated storage or a network resource
            // during the Activated event handler because it increase the time
            // it takes for the application to resume"
            this.IsResuming =
                Observable.FromEventPattern<ActivatedEventArgs>(
                    x => PhoneApplicationService.Current.Activated += x, x => PhoneApplicationService.Current.Activated -= x)
                    .Where(x => !x.EventArgs.IsApplicationInstancePreserved)
                    .SelectMany(_ => frameHelper.Arguments.FirstOrDefaultAsync());

            // NB: No way to tell OS that we need time to suspend, we have to
            // do it in-process
            this.ShouldPersistState = Observable.Merge(
                Observable.FromEventPattern<DeactivatedEventArgs>(
                    x => PhoneApplicationService.Current.Deactivated += x, x => PhoneApplicationService.Current.Deactivated -= x)
                    .Select(_ => Disposable.Empty),
                Observable.FromEventPattern<ClosingEventArgs>(
                    x => PhoneApplicationService.Current.Closing += x, x => PhoneApplicationService.Current.Closing -= x)
                    .Select(_ => Disposable.Empty));

            this.ShouldInvalidateState =
                Observable.FromEventPattern<ApplicationUnhandledExceptionEventArgs>(x => app.UnhandledException += x, x => app.UnhandledException -= x)
                    .Select(_ => Unit.Default);
        }