コード例 #1
0
ファイル: LoginPage.xaml.cs プロジェクト: KHCM/SpheroWin8
        private void UpdateWithServerData(SignalREventArgs e)
        {
            App.Current.AppUser = e.UserUpdate;
            //Upload Games
            App.Current.AllGames = e.CustomGameList;
            App.Current.OppUsers = e.CustomAvailableOpponents;
            App.Current.SignalRHub.SignalRServerNotification -= new SignalRServerHandler(SignalRHub_SignalRServerNotification);


        }
コード例 #2
0
        public async virtual void UserLogin(User tabletChatClient)
        {
            // Fire up SignalR Connection & join chatroom.  
            try
            {
                await gameConnection.Start();

                if (gameConnection.State == Microsoft.AspNet.SignalR.Client.ConnectionState.Connected)
                {
                    await SignalRGameHub.Invoke("Login", tabletChatClient);
                }
            }
            catch (Exception ex)
            {

                // Do some error handling. Could not connect to Sever Error.
                Debug.WriteLine("Error: "+ ex.Message);
            }

            // On 

            // Listen to chat events on SignalR Server & wire them up appropriately.
            SignalRGameHub.On<User, ServerMessage>("addNewUpdate", (user, message) =>
            {
                SignalREventArgs userArgs = new SignalREventArgs();
                userArgs.UserUpdate = user;
                userArgs.CustomServerMessage = message;

                // Raise custom event & let it bubble up.
                SignalRServerNotification(this, userArgs);
            });
            SignalRGameHub.On<string, string>("addNewMessageToPage", (message, word) =>
            {
                SignalREventArgs chatArgs = new SignalREventArgs();
                chatArgs.ChatMessageFromServer = message;
                chatArgs.ChatMessageFromServer = word;
                // Raise custom event & let it bubble up.
                SignalRServerNotification(this, chatArgs);
            });
            SignalRGameHub.On<User, List<Game>, List<User>, ServerMessage>("update", (user, agl, ul, sm) =>
            {
                SignalREventArgs uArgs = new SignalREventArgs();
                uArgs.UserUpdate = user;
                uArgs.CustomGameList = agl;
                uArgs.CustomAvailableOpponents = ul;
                uArgs.CustomServerMessage = sm;
                // Raise custom event & let it bubble up.
                SignalRServerNotification(this, uArgs);
            });
            SignalRGameHub.On<Game, ServerMessage>("gameCreated", (g, sm) =>
            {
                SignalREventArgs gArgs = new SignalREventArgs();
                gArgs.CustomGameObject = g;
                gArgs.CustomServerMessage = sm;
                // Raise custom event & let it bubble up.
                SignalRServerNotification(this, gArgs);
            });
            SignalRGameHub.On<User, Game, ServerMessage>("lobbyMessage", (u, g, sm) =>
            {
                SignalREventArgs gArgs = new SignalREventArgs();
                gArgs.UserUpdate = u;
                gArgs.CustomGameObject = g;
                gArgs.CustomServerMessage = sm;
                // Raise custom event & let it bubble up.
                SignalRServerNotification(this, gArgs);
            });
            SignalRGameHub.On<Game, InGameMessage>("inGameMessage", (g, im) =>
            {
                SignalREventArgs gArgs = new SignalREventArgs();
                gArgs.CustomGameObject = g;
                gArgs.InGameActionMessageEvent = im;
                // Raise custom event & let it bubble up.
                SignalRServerNotification(this, gArgs);
            });
        }
コード例 #3
0
ファイル: LoginPage.xaml.cs プロジェクト: KHCM/SpheroWin8
        protected void SignalRHub_SignalRServerNotification(object sender, SignalREventArgs e)
        {
            Deployment.Current.Dispatcher.BeginInvoke( () => 
            //await CoreWindow.GetForCurrentThread().Dispatcher.RunAsync ( CoreDispatcherPriority.High, () => 
            {
                //Debug.WriteLine("SEND, - SIMPLE CHAT WORKS- "+e.ChatMessageFromServer);
                if (e.CustomServerMessage != null)
                {
                    switch (e.CustomServerMessage.Command)
                    {
                        //Login
                        case 0:
                            //Update Game List
                            if (e.CustomServerMessage.Action == "login")
                            {
                                UpdateWithServerData(e);
                                //LoggedInMessageBox();
                                NavigationService.Navigate(new Uri("/HubPage.xaml", UriKind.Relative));

                            }

                            break;
                        case 1:
                            if (e.CustomServerMessage.Action == "update")
                            {
                                UpdateWithServerData(e);
                                //LoggedInMessageBox();
                                NavigationService.Navigate(new Uri("/HubPage.xaml", UriKind.Relative));


                            }
                            break;
                        default:
                            break;
                    }
                }
            });
        }
コード例 #4
0
 public virtual void OnSignalRServerNotificationReceived(SignalREventArgs e)
 {
     if (SignalRServerNotification != null)
     {
         SignalRServerNotification(this, e);
     }
 }