Esempio n. 1
0
 private void notifyFriendsLoggedOut(User user)
 {
     User[] friends = userRepository.getFriends(user);
     foreach (User us in friends)
     {
         if (loggedClients.ContainsKey(us.Id))
         {
             IChatObserver chatClient = loggedClients[us.Id];
             chatClient.friendLoggedOut(user);
         }
     }
 }
Esempio n. 2
0
        private void notifyFriendsLoggedOut(User user)
        {
            IEnumerable <User> friends = userRepository.getFriendsOf(user);

            foreach (User us in friends)
            {
                if (loggedClients.ContainsKey(us.Id))
                {
                    IChatObserver chatClient = loggedClients[us.Id];
                    Task.Run(() => chatClient.friendLoggedOut(user));
                }
            }
        }
Esempio n. 3
0
        private void handleUpdate(UpdateResponse update)
        {
            if (update is FriendLoggedInResponse)
            {
                FriendLoggedInResponse frUpd = (FriendLoggedInResponse)update;
                User friend = DTOUtils.getFromDTO(frUpd.Friend);
                Console.WriteLine("Friend logged in " + friend);
                try
                {
                    client.friendLoggedIn(friend);
                }
                catch (ChatException e)
                {
                    Console.WriteLine(e.StackTrace);
                }
            }
            if (update is FriendLoggedOutResponse)
            {
                FriendLoggedOutResponse frOutRes = (FriendLoggedOutResponse)update;
                User friend = DTOUtils.getFromDTO(frOutRes.Friend);
                Console.WriteLine("Friend logged out " + friend);
                try
                {
                    client.friendLoggedOut(friend);
                }
                catch (ChatException e)
                {
                    Console.WriteLine(e.StackTrace);
                }
            }

            if (update is NewMessageResponse)
            {
                NewMessageResponse msgRes  = (NewMessageResponse)update;
                Message            message = DTOUtils.getFromDTO(msgRes.Message);
                try
                {
                    client.messageReceived(message);
                }
                catch (ChatException e)
                {
                    Console.WriteLine(e.StackTrace);
                }
            }
        }