internal void setupDefaultSuspendResume(ISuspensionDriver driver)
        {
            driver = driver ?? RxApp.DependencyResolver.GetService <ISuspensionDriver>();

            SuspensionHost.ShouldInvalidateState
            .SelectMany(_ => driver.InvalidateState())
            .LoggedCatch(this, Observable.Return(Unit.Default), "Tried to invalidate app state")
            .Subscribe(_ => this.Log().Info("Invalidated app state"));

            SuspensionHost.ShouldPersistState
            .SelectMany(x => driver.SaveState(ViewModel).Finally(x.Dispose))
            .LoggedCatch(this, Observable.Return(Unit.Default), "Tried to persist app state")
            .Subscribe(_ => this.Log().Info("Persisted application state"));

            SuspensionHost.IsResuming
            .SelectMany(x => driver.LoadState <IApplicationRootState>())
            .LoggedCatch(this,
                         Observable.Defer(() => Observable.Return(RxApp.DependencyResolver.GetService <IApplicationRootState>())),
                         "Failed to restore app state from storage, creating from scratch")
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(x => ViewModel = x);

            SuspensionHost.IsLaunchingNew.Subscribe(_ => {
                ViewModel = RxApp.DependencyResolver.GetService <IApplicationRootState>();
            });
        }
        internal void setupDefaultSuspendResume(ISuspensionDriver driver)
        {
            driver = driver ?? RxApp.GetService<ISuspensionDriver>();

            _viewModelChanged.StartWith(ViewModel).Where(x => x != null).Subscribe(vm => {
                var page = default(IViewFor);
                var frame = RootVisual as PhoneApplicationFrame;

                page = RxApp.GetService<IViewFor>("InitialPage");
                if (frame == null) {
                    frame = new PhoneApplicationFrame() {
                        Content = page,
                    };
                }

                page.ViewModel = vm;
                var pg = page as PhoneApplicationPage;
                if (pg != null) {
                    pg.BackKeyPress += (o, e) => {
                        if (ViewModel.Router.NavigationStack.Count <= 1 ||
                            ViewModel.Router.NavigateBack.CanExecute(null)) {
                            return;
                        }

                        e.Cancel = true;
                        ViewModel.Router.NavigateBack.Execute(null);
                    };
                }

                RootVisual = frame;
            });

            SuspensionHost.ShouldInvalidateState
                .SelectMany(_ => driver.InvalidateState())
                .LoggedCatch(this, Observable.Return(Unit.Default), "Tried to invalidate app state")
                .Subscribe(_ => this.Log().Info("Invalidated app state"));

            SuspensionHost.ShouldPersistState
                .SelectMany(x => driver.SaveState(ViewModel).Finally(x.Dispose))
                .LoggedCatch(this, Observable.Return(Unit.Default), "Tried to persist app state")
                .Subscribe(_ => this.Log().Info("Persisted application state"));

            SuspensionHost.IsResuming
                .SelectMany(x => driver.LoadState<IApplicationRootState>())
                .LoggedCatch(this,
                    Observable.Defer(() => Observable.Return(RxApp.GetService<IApplicationRootState>())),
                    "Failed to restore app state from storage, creating from scratch")
                .ObserveOn(RxApp.DeferredScheduler)
                .Subscribe(x => {
                    ViewModel = x;
                });

            SuspensionHost.IsLaunchingNew.Subscribe(_ => {
                ViewModel = RxApp.GetService<IApplicationRootState>();
            });
        }
        internal void setupDefaultSuspendResume(ISuspensionDriver driver)
        {
            driver = driver ?? RxApp.DependencyResolver.GetService <ISuspensionDriver>();

            _viewModelChanged.Subscribe(vm => {
                var page  = default(IViewFor);
                var frame = Window.Current.Content as Frame;

                if (frame == null)
                {
                    frame = new Frame();
                    Window.Current.Content = frame;
                }

                page = Window.Current.Content as IViewFor;
                if (page == null)
                {
                    page          = RxApp.DependencyResolver.GetService <IViewFor>("InitialPage");
                    frame.Content = (UIElement)page;
                }

                page.ViewModel = vm;
                Window.Current.Activate();
            });

            SuspensionHost.ShouldInvalidateState
            .SelectMany(_ => driver.InvalidateState())
            .LoggedCatch(this, Observable.Return(Unit.Default), "Tried to invalidate app state")
            .Subscribe(_ => this.Log().Info("Invalidated app state"));

            SuspensionHost.ShouldPersistState
            .SelectMany(x => driver.SaveState(ViewModel).Finally(x.Dispose))
            .LoggedCatch(this, Observable.Return(Unit.Default), "Tried to persist app state")
            .Subscribe(_ => this.Log().Info("Persisted application state"));

            SuspensionHost.IsResuming
            .SelectMany(x => driver.LoadState <IApplicationRootState>())
            .LoggedCatch(this,
                         Observable.Defer(() => Observable.Return(RxApp.DependencyResolver.GetService <IApplicationRootState>())),
                         "Failed to restore app state from storage, creating from scratch")
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(x => ViewModel = x);

            SuspensionHost.IsLaunchingNew.Subscribe(_ => {
                ViewModel = RxApp.DependencyResolver.GetService <IApplicationRootState>();
            });
        }
        internal void setupDefaultSuspendResume(ISuspensionDriver driver)
        {
            driver = driver ?? RxApp.GetService<ISuspensionDriver>();

            _viewModelChanged.Subscribe(vm => {
                var page = default(IViewFor);
                var frame = Window.Current.Content as Frame;

                if (frame == null) {
                    page = RxApp.GetService<IViewFor>("InitialPage");

                    frame = new Frame() {
                        Content = page,
                    };

                    Window.Current.Content = frame;
                }

                page.ViewModel = vm;
                Window.Current.Activate();
            });

            SuspensionHost.ShouldInvalidateState
                .SelectMany(_ => driver.InvalidateState())
                .LoggedCatch(this, Observable.Return(Unit.Default), "Tried to invalidate app state")
                .Subscribe(_ => this.Log().Info("Invalidated app state"));

            SuspensionHost.ShouldPersistState
                .SelectMany(x => driver.SaveState(ViewModel).Finally(x.Dispose))
                .LoggedCatch(this, Observable.Return(Unit.Default), "Tried to persist app state")
                .Subscribe(_ => this.Log().Info("Persisted application state"));

            SuspensionHost.IsResuming
                .SelectMany(x => driver.LoadState<IApplicationRootState>())
                .LoggedCatch(this,
                    Observable.Defer(() => Observable.Return(RxApp.GetService<IApplicationRootState>())),
                    "Failed to restore app state from storage, creating from scratch")
                .ObserveOn(RxApp.DeferredScheduler)
                .Subscribe(x => {
                    ViewModel = x;
                });

            SuspensionHost.IsLaunchingNew.Subscribe(_ => {
                ViewModel = RxApp.GetService<IApplicationRootState>();
            });
        }
    private static async Task SuspensionDriverShouldSaveAndLoadState(ISuspensionDriver driver)
    {
        var state = new MainState
        {
            SelectedSupportedType = CloudType.GitHub
        };

        state.Clouds.AddOrUpdate(new CloudState());
        state.Clouds.AddOrUpdate(new CloudState
        {
            AuthState = new AuthState
            {
                DirectAuthState = new DirectAuthState
                {
                    Username = "******",
                    Password = "******"
                }
            }
        });

        await driver.SaveState(state);

        var loaded = await driver.LoadState();

        loaded.Should().BeOfType <MainState>();

        var retyped = (MainState)loaded;

        retyped.SelectedSupportedType.Should().Be(CloudType.GitHub);
        retyped.Clouds.Count.Should().Be(2);
        retyped.CloudStates.Should().NotBeEmpty();
        retyped.CloudStates.Should().Contain(provider =>
                                             provider.AuthState.DirectAuthState.Username == "Joseph Joestar" &&
                                             provider.AuthState.DirectAuthState.Password == "Dio");

        await driver.InvalidateState();

        await Assert.ThrowsAnyAsync <Exception>(async() => await driver.LoadState()).ConfigureAwait(false);

        await driver.SaveState(new MainState());

        await driver.LoadState();
    }
        internal void setupDefaultSuspendResume(ISuspensionDriver driver)
        {
            driver = driver ?? RxApp.GetService <ISuspensionDriver>();

            var window = new UIWindow(UIScreen.MainScreen.Bounds);

            _viewModelChanged.Subscribe(vm => {
                var frame   = RxApp.GetService <UIViewController>("InitialPage");
                var viewFor = frame as IViewFor;
                if (viewFor != null)
                {
                    viewFor.ViewModel = vm;
                }

                window.RootViewController = frame;
                window.MakeKeyAndVisible();
            });

            SuspensionHost.ShouldInvalidateState
            .SelectMany(_ => driver.InvalidateState())
            .LoggedCatch(this, Observable.Return(Unit.Default), "Tried to invalidate app state")
            .Subscribe(_ => this.Log().Info("Invalidated app state"));

            SuspensionHost.ShouldPersistState
            .SelectMany(x => driver.SaveState(ViewModel).Finally(x.Dispose))
            .LoggedCatch(this, Observable.Return(Unit.Default), "Tried to persist app state")
            .Subscribe(_ => this.Log().Info("Persisted application state"));

            SuspensionHost.IsResuming
            .SelectMany(x => driver.LoadState <IApplicationRootState>())
            .LoggedCatch(this,
                         Observable.Defer(() => Observable.Return(RxApp.GetService <IApplicationRootState>())),
                         "Failed to restore app state from storage, creating from scratch")
            .ObserveOn(RxApp.DeferredScheduler)
            .Subscribe(x => ViewModel = x);

            SuspensionHost.IsLaunchingNew.Subscribe(_ => {
                ViewModel = RxApp.GetService <IApplicationRootState>();
            });
        }
 public void SetupDefaultSuspendResume(ISuspensionDriver driver = null)
 {
     var app = (AutoSuspendApplication) Application.Current;
     app.setupDefaultSuspendResume(driver);
 }
        public void SetupDefaultSuspendResume(ISuspensionDriver driver = null)
        {
            var app = (AutoSuspendApplication)Application.Current;

            app.setupDefaultSuspendResume(driver);
        }
Esempio n. 9
0
 public void SetupDefaultSuspendResume(ISuspensionDriver driver = null)
 {
     var app = (AutoSuspendAppDelegate) UIApplication.SharedApplication.Delegate;
     app.setupDefaultSuspendResume(driver);
 }
Esempio n. 10
0
        internal void setupDefaultSuspendResume(ISuspensionDriver driver)
        {
            driver = driver ?? RxApp.DependencyResolver.GetService<ISuspensionDriver>();

            var window = new UIWindow(UIScreen.MainScreen.Bounds);
            _viewModelChanged.Subscribe(vm => {
                var frame = RxApp.DependencyResolver.GetService<UIViewController>("InitialPage");
                var viewFor = frame as IViewFor;
                if (viewFor != null) {
                    viewFor.ViewModel = vm;
                }

                window.RootViewController = frame;
                window.MakeKeyAndVisible();
            });

            SuspensionHost.ShouldInvalidateState
                .SelectMany(_ => driver.InvalidateState())
                .LoggedCatch(this, Observable.Return(Unit.Default), "Tried to invalidate app state")
                .Subscribe(_ => this.Log().Info("Invalidated app state"));

            SuspensionHost.ShouldPersistState
                .SelectMany(x => driver.SaveState(ViewModel).Finally(x.Dispose))
                .LoggedCatch(this, Observable.Return(Unit.Default), "Tried to persist app state")
                .Subscribe(_ => this.Log().Info("Persisted application state"));

            SuspensionHost.IsResuming
                .SelectMany(x => driver.LoadState<IApplicationRootState>())
                .LoggedCatch(this,
                    Observable.Defer(() => Observable.Return(RxApp.DependencyResolver.GetService<IApplicationRootState>())),
                    "Failed to restore app state from storage, creating from scratch")
                .ObserveOn(RxApp.MainThreadScheduler)
                .Subscribe(x => ViewModel = x);

            SuspensionHost.IsLaunchingNew.Subscribe(_ => {
                ViewModel = RxApp.DependencyResolver.GetService<IApplicationRootState>();
            });
        }
Esempio n. 11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="This"></param>
        /// <param name="driver"></param>
        /// <returns></returns>
        public static IDisposable SetupDefaultSuspendResume(this ISuspensionHost This, ISuspensionDriver driver = null)
        {
            var ret = new CompositeDisposable();

            driver = driver ?? Locator.Current.GetService <ISuspensionDriver>();

            ret.Add(This.ShouldInvalidateState
                    .SelectMany(_ => driver.InvalidateState())
                    .LoggedCatch(This, Observables.Unit, "Tried to invalidate app state")
                    .Subscribe(_ => This.Log().Info("Invalidated app state")));

            ret.Add(This.ShouldPersistState
                    .SelectMany(x => driver.SaveState(This.AppState).Finally(x.Dispose))
                    .LoggedCatch(This, Observables.Unit, "Tried to persist app state")
                    .Subscribe(_ => This.Log().Info("Persisted application state")));

            ret.Add(Observable.Merge(This.IsResuming, This.IsLaunchingNew)
                    .SelectMany(x => driver.LoadState())
                    .LoggedCatch(This,
                                 Observable.Defer(() => Observable.Return(This.CreateNewAppState())),
                                 "Failed to restore app state from storage, creating from scratch")
                    .Subscribe(x => This.AppState = x ?? This.CreateNewAppState()));

            return(ret);
        }
Esempio n. 12
0
        public void SetupDefaultSuspendResume(ISuspensionDriver driver = null)
        {
            var app = (AutoSuspendAppDelegate)UIApplication.SharedApplication.Delegate;

            app.setupDefaultSuspendResume(driver);
        }
 public void SetupDefaultSuspendResume(ISuspensionDriver driver = null)
 {
     SetupDefaultSuspendResumeFunc(driver);
 }
        internal void setupDefaultSuspendResume(ISuspensionDriver driver)
        {
            driver = driver ?? RxApp.DependencyResolver.GetService<ISuspensionDriver>();

            SuspensionHost.ShouldInvalidateState
                .SelectMany(_ => driver.InvalidateState())
                .LoggedCatch(this, Observable.Return(Unit.Default), "Tried to invalidate app state")
                .Subscribe(_ => this.Log().Info("Invalidated app state"));

            SuspensionHost.ShouldPersistState
                .SelectMany(x => driver.SaveState(ViewModel).Finally(x.Dispose))
                .LoggedCatch(this, Observable.Return(Unit.Default), "Tried to persist app state")
                .Subscribe(_ => this.Log().Info("Persisted application state"));

            SuspensionHost.IsResuming
                .SelectMany(x => driver.LoadState<IApplicationRootState>())
                .LoggedCatch(this,
                    Observable.Defer(() => Observable.Return(RxApp.DependencyResolver.GetService<IApplicationRootState>())),
                    "Failed to restore app state from storage, creating from scratch")
                .ObserveOn(RxApp.MainThreadScheduler)
                .Subscribe(x => ViewModel = x);

            SuspensionHost.IsLaunchingNew.Subscribe(_ => {
                ViewModel = RxApp.DependencyResolver.GetService<IApplicationRootState>();
            });
        }
Esempio n. 15
0
 public void SetupDefaultSuspendResume(ISuspensionDriver driver = null)
 {
     SetupDefaultSuspendResumeFunc(driver);
 }
 public void SetupDefaultSuspendResume(ISuspensionDriver driver = null)
 {
     inner.SetupDefaultSuspendResume(driver);
 }