Example #1
0
        protected async virtual Task ProcessResponseImplAsync(NavigationResponse response)
        {
            Guard.ArgumentNotNull(response, "response");

            // we won't handle it the response, if it is not the active request!
            if (!response.Request.Equals(ActiveNavigationRequest))
            {
                return;
            }

            // we check if the navigation was successful or not
            if (response.Status != ResponseStatus.Success)
            {
                // if cancelled then return to normal state, else we inform the error
                if (response.Status == ResponseStatus.Cancelled)
                {
                    TransitionToNavigationState(Controls.NavigationState.Navigated);
                    return;
                }
                ShowFailedNavigationState(response.Request, response.Status, response.Error);
                return;
            }

            // we save our supporters and use them - note_ we need to save this to access later
            CurrentNavigationLifecycleSupporter     = NavigationService.GetSupporter <ISupportNavigationLifecycle>(response.Content);
            CurrentNavigationViewLifecycleSupporter = NavigationService.GetSupporter <ISupportNavigationViewLifecycle>(response.Content);
            CurrentNavigationStateSupporter         = NavigationService.GetSupporter <ISupportNavigationState>(response.Content);
            CurrentNavigationViewStateSupporter     = NavigationService.GetSupporter <ISupportNavigationViewState>(response.Content);

            // we save the url and the content
            CurrentNavigationRequest = response.Request;
            SetValue(ContentProperty, response.Content);

            // if the content support navigation, we pass in the request/response merged parameters
            if (this.CurrentNavigationLifecycleSupporter != null)
            {
                CurrentNavigationLifecycleSupporter.Initialize(response.ResponseParameters);
                await CurrentNavigationLifecycleSupporter.InitializeAsync(response.ResponseParameters);

                Title = CurrentNavigationLifecycleSupporter.Title ??
                        nRoute.Navigation.Navigation.GetTitle(response.Content as DependencyObject);
            }
            else
            {
                Title = nRoute.Navigation.Navigation.GetTitle(response.Content as DependencyObject);
            }

            TransitionToNavigationState(Controls.NavigationState.Navigated);

            // and once we have set the transition state, then we call the view's initialize
            if (CurrentNavigationViewLifecycleSupporter != null)
            {
                CurrentNavigationViewLifecycleSupporter.Initialize(response);
            }
        }
        protected async override Task ProcessResponseImplAsync(NavigationResponse response)
        {
            Guard.ArgumentNotNull(response, "response");

            // we won't handle it the response, if it is not the active request!
            if (!response.Request.Equals(base.ActiveNavigationRequest))
            {
                return;
            }

            // we check if the navigation was successful or not
            if (response.Status != ResponseStatus.Success)
            {
                // we raise navigation failed and return - note for cancelled it returns to navigated state
                var _failedEventArgs = new NavigationFailedEventArgs(this, response.Request, response.Status, response.Error);
                OnNavigatingFailed(_failedEventArgs);
                return;
            }

            // we save our supporters and use them - note_ we need to save this to access later
            CurrentNavigationLifecycleSupporter     = NavigationService.GetSupporter <ISupportNavigationLifecycle>(response.Content);
            CurrentNavigationViewLifecycleSupporter = NavigationService.GetSupporter <ISupportNavigationViewLifecycle>(response.Content);
            CurrentNavigationStateSupporter         = NavigationService.GetSupporter <ISupportNavigationState>(response.Content);
            CurrentNavigationViewStateSupporter     = NavigationService.GetSupporter <ISupportNavigationViewState>(response.Content);

            // we save the url and the content
            CurrentNavigationRequest = response.Request;
            SetValue(ContentProperty, response.Content);

            // if the content support navigation, we pass in the request/response merged parameters
            if (this.CurrentNavigationLifecycleSupporter != null)
            {
                CurrentNavigationLifecycleSupporter.Initialize(response.ResponseParameters);
                await CurrentNavigationLifecycleSupporter.InitializeAsync(response.ResponseParameters);

                Title = CurrentNavigationLifecycleSupporter.Title ??
                        nRoute.Navigation.Navigation.GetTitle(response.Content as DependencyObject);
            }
            else
            {
                Title = nRoute.Navigation.Navigation.GetTitle(response.Content as DependencyObject);
            }


            // we raise completed
            OnNavigationCompleted(new NavigatedEventArgs(this, response.Request));

            // and once we have set the transition state, then we call the view's initialize
            if (CurrentNavigationViewLifecycleSupporter != null)
            {
                CurrentNavigationViewLifecycleSupporter.Initialize(response);
            }
        }
Example #3
0
        protected async override Task ProcessResponseImplAsync(NavigationResponse response)
        {
            Guard.ArgumentNotNull(response, "response");

            // we won't handle it the response, if it is not the active request!
            if (!response.Request.Equals(base.ActiveNavigationRequest))
            {
                return;
            }

            // we check if the navigation was not successful we let the base class handle it
            if (response.Status != ResponseStatus.Success)
            {
                await base.ProcessResponseImplAsync(response);

                return;
            }

            // note_ we don't send this request to the base class, hereon
            // we add to the journal the current page info
            if (base.CurrentNavigationRequest != null)
            {
                if (_states.ContainsKey(base.CurrentNavigationRequest.RequestUrl))
                {
                    _states[base.CurrentNavigationRequest.RequestUrl] = GetCurrentPageContentState();
                }
                else
                {
                    _states.Add(base.CurrentNavigationRequest.RequestUrl, GetCurrentPageContentState());
                    base.NotifyPropertyChanged(() => CanPurgeJournal);
                }
            }

            // we save our supporters and use them - note_ we need to save this to access later
            CurrentNavigationLifecycleSupporter     = NavigationService.GetSupporter <ISupportNavigationLifecycle>(response.Content);
            CurrentNavigationViewLifecycleSupporter = NavigationService.GetSupporter <ISupportNavigationViewLifecycle>(response.Content);
            CurrentNavigationStateSupporter         = NavigationService.GetSupporter <ISupportNavigationState>(response.Content);
            CurrentNavigationViewStateSupporter     = NavigationService.GetSupporter <ISupportNavigationViewState>(response.Content);

            // we save the url and the content
            CurrentNavigationRequest = response.Request;
            SetValue(ContentProperty, response.Content);

            // if the content support navigation, we pass in the request/response merged parameters
            if (this.CurrentNavigationLifecycleSupporter != null)
            {
                CurrentNavigationLifecycleSupporter.Initialize(response.ResponseParameters);
                await CurrentNavigationLifecycleSupporter.InitializeAsync(response.ResponseParameters);

                Title = CurrentNavigationLifecycleSupporter.Title ??
                        nRoute.Navigation.Navigation.GetTitle(response.Content as DependencyObject);
            }
            else
            {
                Title = nRoute.Navigation.Navigation.GetTitle(response.Content as DependencyObject);
            }

            // we get the page state manager and restore the state
            if (CurrentNavigationStateSupporter != null)
            {
                // restore state, if we have a state
                if (_states.ContainsKey(response.Request.RequestUrl))
                {
                    CurrentNavigationStateSupporter.RestoreState(_states[response.Request.RequestUrl].State);  // note_ with stored state
                }
            }

            // if the content supports view state, and we are navigating back/forward
            if (CurrentNavigationViewStateSupporter != null)
            {
                if (_states.ContainsKey(response.Request.RequestUrl))
                {
                    CurrentNavigationViewStateSupporter.RestoreState(_states[response.Request.RequestUrl].VisualState);  // note_ with stored state
                }
            }


            // and raise the event navigation completed
            OnNavigationCompleted(new NavigatedEventArgs(this, response.Request));

            // and once we have set the transition state, then we call the view's initialize
            if (CurrentNavigationViewLifecycleSupporter != null)
            {
                CurrentNavigationViewLifecycleSupporter.Initialize(response);
            }
        }
Example #4
0
        protected override async Task ProcessResponseImplAsync(NavigationResponse response)
        {
            Guard.ArgumentNotNull(response, "response");

            // we won't handle it the response, if it is not the active request!
            if (!response.Request.Equals(base.ActiveNavigationRequest))
            {
                return;
            }

            // we check if the navigation was successful or not
            if (response.Status != ResponseStatus.Success)
            {
                // we raise navigation failed and return
                await base.ProcessResponseImplAsync(response);

                return;
            }

            // note_ we don't send this request to the base class, hereon

            // we get the current page info, as in the current page before being navigated
            var _currentPageInfo = GetCurrentPageContentState();
            var _nextPageInfo    = default(PageContentState);

            // else as per the navigation mode we change the stacks
            switch (response.Request.NavigationMode)
            {
            // we treat new and unknown alike
            case NavigateMode.New:
            case NavigateMode.Unknown:

                // we check if we were to record
                if (_currentPageInfo != null)
                {
                    _backStack.Push(_currentPageInfo);
                }

                // we also clear the forward stack
                _forwardStack.Clear();

                // and we say history changed
                RaiseHistoryChanged();
                break;

            case NavigateMode.Back:
                if (CanNavigateBack)
                {
                    // we push the current item into the forward stack
                    _forwardStack.Push(_currentPageInfo);

                    // we remove one item
                    _nextPageInfo = _backStack.Pop();

                    // and we say history changed
                    RaiseHistoryChanged();
                }

                break;

            case NavigateMode.Forward:

                // we push the current item into the back stack
                _backStack.Push(_currentPageInfo);

                // and we remove one item
                _nextPageInfo = _forwardStack.Pop();

                // and we say history changed and return
                RaiseHistoryChanged();
                break;

            case NavigateMode.Refresh:

                // we don't need to do anything here, as the history remains the same
                _nextPageInfo = _currentPageInfo;
                break;
            }

            // we save our supporters and use them - note_ we need to save this to access later
            CurrentNavigationLifecycleSupporter     = NavigationService.GetSupporter <ISupportNavigationLifecycle>(response.Content);
            CurrentNavigationViewLifecycleSupporter = NavigationService.GetSupporter <ISupportNavigationViewLifecycle>(response.Content);
            CurrentNavigationStateSupporter         = NavigationService.GetSupporter <ISupportNavigationState>(response.Content);
            CurrentNavigationViewStateSupporter     = NavigationService.GetSupporter <ISupportNavigationViewState>(response.Content);

            // we save the url and the content
            CurrentNavigationRequest = response.Request;
            SetValue(ContentProperty, response.Content);

            // if the content support navigation, we pass in the request/response merged parameters
            if (this.CurrentNavigationLifecycleSupporter != null)
            {
                CurrentNavigationLifecycleSupporter.Initialize(response.ResponseParameters);
                await CurrentNavigationLifecycleSupporter.InitializeAsync(response.ResponseParameters);

                Title = CurrentNavigationLifecycleSupporter?.Title ??
                        nRoute.Navigation.Navigation.GetTitle(response.Content as DependencyObject);
            }
            else
            {
                Title = nRoute.Navigation.Navigation.GetTitle(response.Content as DependencyObject);
            }

            // if the content supports state, and we are navigating back/forward
            if (CurrentNavigationStateSupporter != null)
            {
                // if we are navigating back  or forward, and we are to - also we treat the unknown state to be like a New navigation
                if (response.Request.NavigationMode != NavigateMode.New) // && response.Request.NavigationMode != NavigateMode.Unknown)
                {
                    CurrentNavigationStateSupporter.RestoreState(_nextPageInfo != null ? _nextPageInfo.State : null);
                }
            }

            // if the content supports view state, and we are navigating back/forward
            if (CurrentNavigationViewStateSupporter != null)
            {
                // if we are navigating back  or forward, and we are to - also we treat the unknown state to be like a New navigation
                if (response.Request.NavigationMode != NavigateMode.New)
                {
                    CurrentNavigationViewStateSupporter.RestoreState(_nextPageInfo != null ? _nextPageInfo.VisualState : null);
                }
            }

            // and raise the event navigation completed
            OnNavigationCompleted(new NavigatedEventArgs(this, response.Request));

            // and once we have set the transition state, then we call the view's initialize
            if (CurrentNavigationViewLifecycleSupporter != null)
            {
                CurrentNavigationViewLifecycleSupporter.Initialize(response);
            }
        }
Example #5
0
        protected async override Task ProcessResponseImplAsync(NavigationResponse response)
        {
            Guard.ArgumentNotNull(response, "response");

            // we won't handle it the response, if it is not the active request!
            if (!response.Request.Equals(base.ActiveNavigationRequest))
            {
                return;
            }

            // we check if the navigation was successful or not
            if (response.Status != ResponseStatus.Success)
            {
                // we raise navigation failed and return
                await base.ProcessResponseImplAsync(response);

                return;
            }

            // note_ we don't send this request to the base class, hereon

            // we get the current page info
            var _currentPageStatelessInfo = GetCurrentPageStatelessContentState();

            // else as per the navigation mode we change the stacks
            switch (response.Request.NavigationMode)
            {
            // we treat new and unknown alike
            case NavigateMode.New:
            case NavigateMode.Unknown:

                // we check if we were to record
                if (_currentPageStatelessInfo != null)
                {
                    _backStack.Push(_currentPageStatelessInfo);
                }

                // we also clear the forward stack
                _forwardStack.Clear();

                // and we say history changed
                RaiseHistoryChanged();
                break;

            case NavigateMode.Back:

                // we push the current item into the forward stack
                _forwardStack.Push(_currentPageStatelessInfo);

                // we remove one item
                _backStack.Pop();

                // and we say history changed
                RaiseHistoryChanged();
                break;

            case NavigateMode.Forward:

                // we push the current item into the back stack
                _backStack.Push(_currentPageStatelessInfo);

                // and we remove one item
                _forwardStack.Pop();

                // and we say history changed and return
                RaiseHistoryChanged();
                break;

            case NavigateMode.Refresh:

                // we don't need to do anything here, as the history remains the same
                break;
            }

            // we add to the journal the current page info - note we don't save the state when refreshing
            if (base.CurrentNavigationRequest != null && !_isRestoring)
            {
                if (_states.ContainsKey(base.CurrentNavigationRequest.RequestUrl))
                {
                    _states[base.CurrentNavigationRequest.RequestUrl] = GetCurrentPageContentState();
                }
                else
                {
                    _states.Add(base.CurrentNavigationRequest.RequestUrl, GetCurrentPageContentState());
                    base.NotifyPropertyChanged(() => CanPurgeJournal);
                }
            }

            // we save our supporters and use them - note_ we need to save this to access later
            CurrentNavigationLifecycleSupporter     = NavigationService.GetSupporter <ISupportNavigationLifecycle>(response.Content);
            CurrentNavigationViewLifecycleSupporter = NavigationService.GetSupporter <ISupportNavigationViewLifecycle>(response.Content);
            CurrentNavigationStateSupporter         = NavigationService.GetSupporter <ISupportNavigationState>(response.Content);
            CurrentNavigationViewStateSupporter     = NavigationService.GetSupporter <ISupportNavigationViewState>(response.Content);

            // we save the url and the content
            CurrentNavigationRequest = response.Request;
            SetValue(ContentProperty, response.Content);

            // if the content support navigation, we pass in the request/response merged parameters
            if (this.CurrentNavigationLifecycleSupporter != null)
            {
                CurrentNavigationLifecycleSupporter.Initialize(response.ResponseParameters);
                await CurrentNavigationLifecycleSupporter.InitializeAsync(response.ResponseParameters);

                Title = CurrentNavigationLifecycleSupporter.Title ??
                        nRoute.Navigation.Navigation.GetTitle(response.Content as DependencyObject);
            }
            else
            {
                Title = nRoute.Navigation.Navigation.GetTitle(response.Content as DependencyObject);
            }

            // if the content supports state, and we are navigating back/forward
            if (CurrentNavigationStateSupporter != null)
            {
                // restore state, if we have a state
                if (_states.ContainsKey(response.Request.RequestUrl))
                {
                    CurrentNavigationStateSupporter.RestoreState(_states[response.Request.RequestUrl].State);  // note_ with stored state
                }
            }

            // if the content supports view state, and we are navigating back/forward
            if (CurrentNavigationViewStateSupporter != null)
            {
                if (_states.ContainsKey(response.Request.RequestUrl))
                {
                    CurrentNavigationViewStateSupporter.RestoreState(_states[response.Request.RequestUrl].VisualState);  // note_ with stored state
                }
            }


            // and raise the event navigation completed
            OnNavigationCompleted(new NavigatedEventArgs(this, response.Request));

            // and once we have set the transition state, then we call the view's initialize
            if (CurrentNavigationViewLifecycleSupporter != null)
            {
                CurrentNavigationViewLifecycleSupporter.Initialize(response);
            }
        }