Example #1
0
		/// <summary>
		/// Initializes a new instance of the <see cref="Session" /> class.
		/// </summary>
		/// <param name="parameters">Parameters of the session.</param>
		/// <param name="action">Action to process.</param>
		public Session( XParameters parameters, string action )
		{
			_parameters = parameters ?? XParameters.Empty;
			_action = action ?? ViewModel.DefaultAction;

			State = SessionState.Created;
		}
Example #2
0
		/// <summary>
		///     Initializes a new instance of the Breadcrumb class.
		/// </summary>
		/// <param name="type"></param>
		/// <param name="parameters"></param>
		public Breadcrumb( Type type, XParameters parameters )
		{
		    //try
		    //{
		    //    //Contract.Requires<ArgumentNullException>(type != null, "type");
		    //}
		    //catch (Exception ex)
		    //{
		    //    Debug.WriteLine(ex.Message);
		    //}
		    _type = type;
			_parameters = parameters;
		}
	    public abstract void Navigate( string viewName, XParameters parameters, bool openInSubFrame = true);
		public void RestoreStateOrGoToLandingView( string viewName, XParameters parameters )
		{
			//Contract.Requires( viewName != null, "viewName" );
		}
		public bool RollbackSnapshot( object snapshotId, string viewName, XParameters parameters )
		{
			//Contract.Requires<ArgumentNullException>( snapshotId != null );

			return false;
		}
		public void PushBreadcrumb( Type type, XParameters parameters = null )
		{
			_breadcrumbs.Push( new Breadcrumb( type, parameters ) );
		}
Example #7
0
		/// <summary>
		///     Creates the session.
		/// </summary>
		/// <param name="parameters">Parameters of the session.</param>
		/// <param name="action">Action to process.</param>
		/// <returns>
		///     Session.
		/// </returns>
		public Session CreateSession( XParameters parameters, string action )
		{
			Contract.Ensures( Contract.Result<Session>() != null );

			return new Session( parameters, action );
		}
Example #8
0
		/// <summary>
		/// Initializes a new instance of the <see cref="Session"/> class.
		/// </summary>
		/// <param name="parameters">Parameters of the session.</param>
		public Session( XParameters parameters )
			: this( parameters, null )
		{
		}
	    /// <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);
        }
		public static void Serialize( BinaryWriter binaryWriter, XParameters parameters )
		{
			if( binaryWriter == null )
			{
				throw new ArgumentNullException( "binaryWriter" );
			}

			if( parameters == null )
			{
				throw new ArgumentNullException( "parameters" );
			}

			Contract.EndContractBlock();

			using( var writer = new KeyValuePairWriter( binaryWriter ) )
			{
				foreach( var pair in parameters )
				{
					writer.Write( pair );
				}

				writer.WriteEpilogue();
			}
		}
		public static void Serialize( Stream stream, XParameters parameters )
		{
			if( stream == null )
			{
				throw new ArgumentNullException( "stream" );
			}

			if( parameters == null )
			{
				throw new ArgumentNullException( "parameters" );
			}

			Contract.EndContractBlock();

			using( var writer = new KeyValuePairWriter( stream, true ) )
			{
				foreach( var pair in parameters )
				{
					writer.Write( pair );
				}

				writer.WriteEpilogue();
			}
		}
		public static string Serialize( XParameters parameters )
		{
			if( parameters == null )
			{
				throw new ArgumentNullException( "parameters" );
			}

			Contract.Ensures( Contract.Result<string>() != null );

			using( var stream = new MemoryStream() )
			{
				using( var writer = new KeyValuePairWriter( stream ) )
				{
					foreach( var pair in parameters )
					{
						writer.Write( pair );
					}

					writer.WriteEpilogue();
				}

				return Convert.ToBase64String( stream.ToArray() );
			}
		}
		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>
		///     Starts the authentication.
		/// </summary>
		/// <param name="initialViewName">Name of the initial view in the authentication flow.</param>
		/// <param name="parameters">Parameters for the initial view.</param>
		public Task StartAuthentication( string initialViewName, XParameters parameters )
		{
			return StartAuthentication( initialViewName, parameters, null );
		}
	    public void Navigate( string viewName, XParameters parameters, bool openInSubFrame = true)
		{
			//Contract.Requires<ArgumentNullException>( viewName != null, "viewName" );
		}
Example #16
0
		/// <summary>
		///     Adds the parameter value to the current session.
		/// </summary>
		/// <param name="name">Parameter name.</param>
		/// <param name="value">Parameter value.</param>
		/// <returns>Current session.</returns>
		public Session AddParameter( string name, object value )
		{
			//Contract.Requires<ArgumentNullException>( name != null, "name" );
			//Contract.Requires<ArgumentNullException>( value != null, "value" );
			Contract.Ensures( Contract.Result<Session>() != null );

			_parameters = _parameters.WithValue( name, value );

			return this;
		}
	    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;
	    }
		public bool RollbackSnapshot( object snapshotId, string viewName, XParameters parameters )
		{
			var snapshot = snapshotId as NavigationSnapshot;

			if( snapshot == null )
			{
				throw new ArgumentException( "Invalid snapshot.", "snapshotId" );
			}

			// Rewind journal
			var app = (WindowsRTApplication) Application.Current;
			var numberOfEntriesToRemove = 0;
			var sourceViewIsFoundInBackStack = false;

			foreach( var entry in _breadcrumbs )
			{
				if( entry.Equals( snapshot.Breadcrumb ) )
				{
					sourceViewIsFoundInBackStack = true;
					break;
				}

				numberOfEntriesToRemove++;
			}

			if( sourceViewIsFoundInBackStack )
			{
				// TODO: Check whether Navigated event is fired on each GoBack
				while( numberOfEntriesToRemove-- > 0 )
				{
					//var breadcrumb = _breadcrumbs.Peek();
					app.RootFrame.GoBack();

					//ProcessSnapshots( entry.Source );
				}

				if( viewName != null )
				{
					Navigate( viewName, parameters );
				}
				/*
				else
				{
					app.RootFrame.GoBack();
				}
				*/

				return true;
			}

			return false;
		}
		public void RestoreStateOrGoToLandingView( string view, XParameters parameters )
		{
			if( !RestoreBreadcrumbs() )
			{
				Navigate( view, parameters );
			}
		}
		/// <summary>
		///     Initializes a new instance of the <see cref="NavigationCommand" /> class.
		/// </summary>
		/// <param name="navigationService">Instance of navigation service to be used to perform navigation.</param>
		/// <param name="view">Target view.</param>
		/// <param name="canNavigate">Function that determines whether it is possible to navigate to the specified view.</param>
		/// <param name="parameters">Parameters to pass to the target view.</param>
		public NavigationCommand( INavigationService navigationService, string view, Func<bool> canNavigate, XParameters parameters )
			: this( navigationService, view, canNavigate, () => parameters )
		{
			//Contract.Requires<ArgumentNullException>( navigationService != null, "navigationService" );
			//Contract.Requires<ArgumentNullException>( view != null, "view" );
		}
Example #21
0
		/// <summary>
		///     Creates the session.
		/// </summary>
		/// <param name="parameters">Parameters of the session.</param>
		/// <returns>
		///     Session.
		/// </returns>
		public Session CreateSession( XParameters parameters )
		{
			return CreateSession( parameters, null );
		}