public void run()
        {
            try
            {
                bool    doRun = true;
                Message message;
                while (doRun)
                {
                    Console.WriteLine("-----WAIT RUN ------- : ");
                    message = getMessage();

                    Console.WriteLine("-----METHODE RUN ------- : " + message.getHead());
                    switch (message.getHead())
                    {
                    case Header.Joined:
                        names.Add(message.getData()[0]);
                        if (chatter != null)
                        {
                            messages.Add(chatter.joinNotification(new TextChatter(message.getData()[0])));
                        }
                        Console.WriteLine(names);
                        break;

                    case Header.Receive:
                        //messages.Add(message);
                        if (chatter != null)
                        {
                            messages.Add(chatter.receiveAMessage(message.getData()[1], new TextChatter(message.getData()[0])));
                        }
                        Console.WriteLine("MESSAGE RECUE" + messages);
                        break;

                    case Header.Left:
                        names.Remove(message.getData()[0]);
                        if (chatter != null)
                        {
                            messages.Add(chatter.quitNotification(new TextChatter(message.getData()[0])));
                        }

                        break;
                    }
                }
                Console.WriteLine("End of while");
            }
            catch (IOException e)
            {
                Console.WriteLine(e);
            }
        }
Esempio n. 2
0
        public void run()
        {
            try
            {
                Message message;
                while ((message = getMessage()) != null)
                {
                    switch (message.Head)
                    {
                    case Message.Header.JOIN_CR:
                    case Message.Header.JOIN_REPLY:
                    case Message.Header.JOIN_TOPIC:
                        aliases.Add(message.getData().First());
                        if (chatter != null)
                        {
                            chatter.joinNotification(new TextChatter(message.getData().First()));
                        }
                        break;

                    case Message.Header.GET:
                        messages.Add(message);
                        if (chatter != null)
                        {
                            chatter.receiveAMessage(message.getData().ElementAt(1), new TextChatter(message.getData().First()));
                        }
                        break;

                    case Message.Header.QUIT_CR:
                        aliases.Remove(message.getData().First());
                        if (chatter != null)
                        {
                            chatter.quitNotification(new TextChatter(message.getData().First()));
                        }
                        break;
                        // todo:post notification?
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }