public Task<bool> HandleNavigation( NavigationContext context )
		{
			//Contract.Requires<ArgumentNullException>( context != null );

			return null;
		}
예제 #2
0
	    /// <summary>
        ///     Navigates to the specified view with parameters.
        /// </summary>
        /// <param name="viewName">Name of the view.</param>
        /// <param name="parameters">The parameters.</param>
        /// <exception cref="System.ArgumentNullException">viewName</exception>
        /// <exception cref="System.ArgumentException">viewName</exception>
        public async void Navigate( string viewName, XParameters parameters, bool openInSubFrame = false)
		{
			var context = new NavigationContext { ViewName = viewName, Parameters = parameters };

			foreach( var handler in _navigationHandlers )
			{
				if( await handler.HandleNavigation( context ) )
				{
					break;
				}
			}

			if( context.Cancel )
			{
				return;
			}

			ViewDescriptor descriptor;

			if( !_views.TryGetValue( context.ViewName, out descriptor ) )
			{
				throw new ArgumentException( String.Format( "View with name '{0}' is not registered.", context.ViewName ), "viewName" );
			}
		    if (openInSubFrame)
		    {
		       var subFrame = ((WindowsRTApplication) Application.Current).RootSubFrame;
                subFrame.Navigate(descriptor.Type, context.Parameters);
                ((UIElement)subFrame.Parent).Visibility = Visibility.Visible;
		        //FlyoutBase.ShowAttachedFlyout(((WindowsRTApplication)Application.Current).RootFrame);
		    }
		    else
		    {
                ((WindowsRTApplication)Application.Current).RootFrame.Navigate(descriptor.Type, context.Parameters);
            }
		    
            //if (openInSubFrame) ((WindowsRTApplication)Application.Current).RootSubFrame.Navigate(descriptor.Type, context.Parameters);
            //else ((WindowsRTApplication)Application.Current).RootFrame.Navigate(descriptor.Type, context.Parameters);
        }
예제 #3
0
	    public Frame NavigateWithFrame(string viewName, XParameters parameters)
	    {
	        var context = new NavigationContext {ViewName = viewName, Parameters = parameters};

	        if (context.Cancel)
	        {
	            return null;
	        }

	        ViewDescriptor descriptor;

	        if (!_views.TryGetValue(context.ViewName, out descriptor))
	        {
	            throw new ArgumentException(String.Format("View with name '{0}' is not registered.", context.ViewName),
	                "viewName");
	        }

	        Frame subFrame = ((WindowsRTApplication) Application.Current).RootSubFrame;
	        subFrame.Navigate(descriptor.Type, context.Parameters);
	        ((UIElement) subFrame.Parent).Visibility = Visibility.Visible;
	        return subFrame;
	    }
		private void CancelAuthenticationAndRollbackHistory()
		{
			if( _snapshotId != null )
			{
				var snapshotId = _snapshotId;

				_snapshotId = null;
				_targetContext = null;

				_navigationService.RollbackSnapshot( snapshotId );
			}
		}
		private async Task StartAuthentication( string initialViewName, XParameters parameters, Action performWhenAuthenticated )
		{
			if( _authenticationServiceContext != null )
			{
				var authenticated = await _authenticationServiceContext.IsAuthenticated();

				if( !authenticated )
				{
					Action<object> guard = NavigationGuard;

					if( performWhenAuthenticated != null )
					{
						guard = async o =>
						{
							NavigationGuard( o );

							if( await _authenticationServiceContext.IsAuthenticated() )
							{
								performWhenAuthenticated();
							}
						};
					}

					_targetContext = null;
					_snapshotId = _navigationService.CreateSnapshot( guard );

					if( string.IsNullOrEmpty( initialViewName ) )
					{
						initialViewName = _authenticationServiceContext.AuthenticationViewName;
						parameters = _authenticationServiceContext.AuthenticationViewParameters;
					}

					_navigationService.Navigate( initialViewName, parameters );
				}
				else
				{
					if( performWhenAuthenticated != null )
					{
						performWhenAuthenticated();
					}
				}
			}
		}
		/// <summary>
		///     Completes the authentication.
		/// </summary>
		public void CompleteAuthentication()
		{
			if( _snapshotId != null )
			{
				var snapshotId = _snapshotId;
				var targetContext = _targetContext;

				_snapshotId = null;
				_targetContext = null;

				if( targetContext != null )
				{
					_navigationService.RollbackSnapshot( snapshotId, targetContext.ViewName, targetContext.Parameters );
				}
				else
				{
					_navigationService.RollbackSnapshot( snapshotId );
				}
			}
		}
		public async Task<bool> HandleNavigation( NavigationContext context )
		{
			ViewDescriptor descriptor;
			var result = false;

			if( _authenticationServiceContext == null || !_views.TryGetValue( context.ViewName, out descriptor ) )
			{
				return false;
			}

			if( AuthenticationInProgress )
			{
				if( !descriptor.PartOfAuthentication )
				{
					context.Cancel = true;
					CancelAuthenticationAndRollbackHistory();

					result = true;
				}
			}
			else
			{
				if( descriptor.RequiresAuthentication )
				{
					var authenticated = await _authenticationServiceContext.IsAuthenticated();

					if( !authenticated )
					{
						_targetContext = new NavigationContext { ViewName = context.ViewName, Parameters = context.Parameters };
						_snapshotId = _navigationService.CreateSnapshot( NavigationGuard );

						context.ViewName = _authenticationServiceContext.AuthenticationViewName;
						context.Parameters = _authenticationServiceContext.AuthenticationViewParameters;

						result = true;
					}
				}
			}

			return result;
		}
		private void NavigationGuard( object tag )
		{
			_snapshotId = null;
			_targetContext = null;
		}