예제 #1
0
        public void sendMessage(Message message)
        {
            String id_receiver = message.Receiver.Id;

            if (loggedClients.ContainsKey(id_receiver))    //the receiver is logged in
            {
                IChatObserver receiverClient = loggedClients[id_receiver];
                receiverClient.messageReceived(message);
            }
            else
            {
                throw new ChatException("User " + id_receiver + " not logged in.");
            }
        }
예제 #2
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);
                }
            }
        }