/// <summary>
 /// Load the lobby screen with the new session.
 /// </summary>
 void LoadLobbyScreen(NetworkSession networkSession)
 {
     if (networkSession != null)
     {
         LobbyScreen lobbyScreen = new LobbyScreen(networkSession);
         lobbyScreen.ScreenManager = this.ScreenManager;
         ScreenManager.AddScreen(lobbyScreen);
     }
 }
        /// <summary>
        /// Finishes the asynchronous process of joining a game from an invitation,
        /// joining the lobby of a hosted game if the join was successful.
        /// </summary>
        void InvitedSessionJoined(object sender, OperationCompletedEventArgs e)
        {
            NetworkSession networkSession = null;

            try
            {
                networkSession = NetworkSession.EndJoinInvited(e.AsyncResult);
            }
            catch (NetworkSessionJoinException je)
            {
                const string     message    = "Failed joining the session (";
                MessageBoxScreen messageBox = new MessageBoxScreen(message + je.JoinError.ToString() + ").");
                messageBox.Accepted  += FailedMessageBox;
                messageBox.Cancelled += FailedMessageBox;
                ScreenManager.AddScreen(messageBox);

                System.Console.WriteLine("Failed to join session:  " +
                                         je.Message);
            }
            catch (Exception ge)
            {
                const string     message    = "Failed joining the session (";
                MessageBoxScreen messageBox = new MessageBoxScreen(message + ge.Message + ").");
                messageBox.Accepted  += FailedMessageBox;
                messageBox.Cancelled += FailedMessageBox;
                ScreenManager.AddScreen(messageBox);

                System.Console.WriteLine("Failed to join session:  " +
                                         ge.Message);
            }

            // Start the lobby if we got the session!
            // Otherwise the MainMenuScreen will be available.
            if (networkSession != null)
            {
                LobbyScreen lobbyScreen = new LobbyScreen(networkSession);
                lobbyScreen.ScreenManager = ScreenManager;
                ScreenManager.AddScreen(lobbyScreen);
            }
        }
        /// <summary>
        /// Callback to load the lobby screen with the new session.
        /// </summary>
        private void LoadLobbyScreen(object sender, OperationCompletedEventArgs e)
        {
            NetworkSession networkSession = null;

            try
            {
                networkSession = NetworkSession.EndJoin(e.AsyncResult);
            }
            catch (NetworkException ne)
            {
                const string     message    = "Failed joining session.";
                MessageBoxScreen messageBox = new MessageBoxScreen(message);
                messageBox.Accepted  += FailedMessageBox;
                messageBox.Cancelled += FailedMessageBox;
                ScreenManager.AddScreen(messageBox);

                System.Console.WriteLine("Failed joining session:  " + ne.Message);
            }
            catch (GamerPrivilegeException gpe)
            {
                const string message =
                    "You do not have permission to join a session.";
                MessageBoxScreen messageBox = new MessageBoxScreen(message);
                messageBox.Accepted  += FailedMessageBox;
                messageBox.Cancelled += FailedMessageBox;
                ScreenManager.AddScreen(messageBox);

                System.Console.WriteLine(
                    "Insufficient privilege to join session:  " + gpe.Message);
            }
            if (networkSession != null)
            {
                LobbyScreen lobbyScreen = new LobbyScreen(networkSession);
                lobbyScreen.ScreenManager = this.ScreenManager;
                ScreenManager.AddScreen(lobbyScreen);
            }
        }
        /// <summary>
        /// Callback to load the lobby screen with the new session.
        /// </summary>
        private void LoadLobbyScreen(object sender, OperationCompletedEventArgs e)
        {
            NetworkSession networkSession = null;
            try
            {
                networkSession = NetworkSession.EndJoin(e.AsyncResult);
            }
            catch (NetworkException ne)
            {
                const string message = "Failed joining session.";
                MessageBoxScreen messageBox = new MessageBoxScreen(message);
                messageBox.Accepted += FailedMessageBox;
                messageBox.Cancelled += FailedMessageBox;
                ScreenManager.AddScreen(messageBox);

                System.Console.WriteLine("Failed joining session:  " + ne.Message);
            }
            catch (GamerPrivilegeException gpe)
            {
                const string message =
                    "You do not have permission to join a session.";
                MessageBoxScreen messageBox = new MessageBoxScreen(message);
                messageBox.Accepted += FailedMessageBox;
                messageBox.Cancelled += FailedMessageBox;
                ScreenManager.AddScreen(messageBox);

                System.Console.WriteLine(
                    "Insufficient privilege to join session:  " + gpe.Message);
            }
            if (networkSession != null)
            {
                LobbyScreen lobbyScreen = new LobbyScreen(networkSession);
                lobbyScreen.ScreenManager = this.ScreenManager;
                ScreenManager.AddScreen(lobbyScreen);
            }
        }
        /// <summary>
        /// Finishes the asynchronous process of joining a game from an invitation,
        /// joining the lobby of a hosted game if the join was successful.
        /// </summary>
        void InvitedSessionJoined(object sender, OperationCompletedEventArgs e)
        {
            NetworkSession networkSession = null;
            try
            {
                networkSession = NetworkSession.EndJoinInvited(e.AsyncResult);
            }
            catch (NetworkSessionJoinException je)
            {
                const string message = "Failed joining the session (";
                MessageBoxScreen messageBox = new MessageBoxScreen(message + je.JoinError.ToString() + ").");
                messageBox.Accepted += FailedMessageBox;
                messageBox.Cancelled += FailedMessageBox;
                ScreenManager.AddScreen(messageBox);

                System.Console.WriteLine("Failed to join session:  " +
                    je.Message);
            }
            catch (Exception ge)
            {
                const string message = "Failed joining the session (";
                MessageBoxScreen messageBox = new MessageBoxScreen(message + ge.Message + ").");
                messageBox.Accepted += FailedMessageBox;
                messageBox.Cancelled += FailedMessageBox;
                ScreenManager.AddScreen(messageBox);

                System.Console.WriteLine("Failed to join session:  " +
                    ge.Message);
            }

            // Start the lobby if we got the session!
            // Otherwise the MainMenuScreen will be available.
            if (networkSession != null)
            {
                LobbyScreen lobbyScreen = new LobbyScreen(networkSession);
                lobbyScreen.ScreenManager = ScreenManager;
                ScreenManager.AddScreen(lobbyScreen);
            }
        }
 /// <summary>
 /// Load the lobby screen with the new session.
 /// </summary>
 void LoadLobbyScreen(NetworkSession networkSession)
 {
     if (networkSession != null)
     {
         LobbyScreen lobbyScreen = new LobbyScreen(networkSession);
         lobbyScreen.ScreenManager = this.ScreenManager;
         ScreenManager.AddScreen(lobbyScreen);
     }
 }