Exemplo n.º 1
0
 void SendFriendRequest()
 {
     _handler.SendMessage(new Message(MessageCode.C009, _handler.myID, (int)_friendRequestID, _handler.DisplayName));
     FriendRequestCollection.Add(new FriendRequestViewModel(_handler.myID, (int)_friendRequestID, "_", true));
 }
Exemplo n.º 2
0
        private void MessageHandler(Message tempMessage)
        {
            switch (tempMessage.Code)
            {
            case MessageCode.C002:     // Implement Later
                Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() {
                    _handler.DisplayName = tempMessage.MessageString;
                    RaisePropertyChanged("ScreenDisplayName");
                }));
                break;

            case MessageCode.C003:     // Message from another User
                Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() {
                    _messageCollections.Add(tempMessage, _handler.myID);
                }));
                break;

            case MessageCode.C004:     // Implement Later
                break;

            case MessageCode.C005:     // Message sending fail
                Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() {
                    _messageCollections.RemoveByTimeStamp(tempMessage);
                }));
                break;

            case MessageCode.C006:     // Implement Later
                break;

            case MessageCode.C007:     // Connection Closing / Connection Test Fail
                Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() {
                    Handler.CloseConnection();
                }));
                break;

            case MessageCode.C009:
                Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() {
                    FriendRequestCollection.Add(new FriendRequestViewModel(tempMessage.senderID, _handler.myID,
                                                                           tempMessage.MessageString, false));
                }));
                break;

            case MessageCode.C010:
                Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() {
                    SelectedUser = null;
                    MTObservableCollection <User> allFriends = Handler.ParseC010Message(tempMessage.MessageString);
                    Users.Clear();
                    foreach (User friend in allFriends)
                    {
                        if (friend.IsOnline)
                        {
                            Users.Add(friend);
                        }
                    }
                }));
                break;

            case MessageCode.C011:     // Implement Later
                break;

            case MessageCode.C012:     // Implement Later
                break;

            case MessageCode.C013:     // Implement Later
                break;

            case MessageCode.C016:     // Implement Later
                break;

            case MessageCode.C017:     // Implement Later
                break;

            case MessageCode.C018:     // Friend Request Was Accepted
                Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() {
                    FriendRequestViewModel tempFR = FriendRequestCollection.Single(s => s.IDnumeric == tempMessage.senderID);
                    FriendRequestCollection.Remove(tempFR);
                    RaisePropertyChanged("FriendRequestCollection");
                    Users.Add(new User(tempFR.IDnumeric, tempFR.DisplayName));
                    SelectedFriendRequest = null;
                }));
                break;

            case MessageCode.C020:
                Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() {
                    for (int i = 0; i < FriendRequestCollection.Count; i++)
                    {
                        if (FriendRequestCollection[i].IsSent &&
                            FriendRequestCollection[i].DisplayName == "_" &&
                            FriendRequestCollection[i].IDnumeric == tempMessage.senderID)
                        {
                            FriendRequestCollection[i].DisplayName = tempMessage.MessageString;
                            break;
                        }
                    }
                }));
                break;

            default:
                throw new Exception("Invalid Message Code");
            }
        }