Esempio n. 1
0
        private async Task <RouterState> GetRouterState(IObjectStateStore stateStore)
        {
            ObjectState existingState = null;

            try
            {
                existingState = await stateStore.LoadStateAsync();
            }
            catch (Exception e)
            {
                this.Log().WarnException("Could not load state from state store.", e);
                await InvalidateStateAsync(stateStore);
            }
            RouterState routerState = null;

            try
            {
                routerState = (RouterState)existingState?.State;
            }
            catch (InvalidCastException e)
            {
                this.Log().WarnException($"Could not cast loaded state to {nameof(RouterState)}. Was a breaking change made to the app's stored data model?", e);
                await InvalidateStateAsync(stateStore);
            }
            return(routerState);
        }
Esempio n. 2
0
        public virtual async Task StartAsync()
        {
            RegisterDependencies();
            StateStore = GetService <IObjectStateStore>();
            var routerParams = GetService <RouterConfig>();

            Router = GetService <IRouter>();

            SetupSubscriptions(Router);

            var routerState = await GetRouterState(StateStore);

            await ResumeRouterAsync(Router, routerParams, routerState, StateStore);

            await Router.ShowDefaultViewModelAsync();

            started = true;
        }
Esempio n. 3
0
        private static async Task SaveRouterStateAsync(IRouter router, IObjectStateStore stateStore)
        {
            var state = await ActivationHelpers.GetObjectStateAsync(router);

            await stateStore.SaveStateAsync(state);
        }
Esempio n. 4
0
 private static async Task InvalidateStateAsync(IObjectStateStore stateStore)
 {
     await stateStore.SaveStateAsync(null);
 }
Esempio n. 5
0
        private async Task ResumeRouterAsync(IRouter router, RouterConfig routerConfig, RouterState routerState, IObjectStateStore stateStore)
        {
            await ActivationHelpers.InitObjectAsync(router, routerConfig);

            try
            {
                if (routerState != null)
                {
                    await ActivationHelpers.ResumeObjectStateAsync(router, routerState);
                }
            }
            catch (Exception e)
            {
                this.Log().WarnException("Could not resume the router state.", e);
                await InvalidateStateAsync(stateStore);
            }
        }