Пример #1
0
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            ClientSocket client = new ClientSocket();
            ModelManager model = new ModelManager(client);
            ChatSystem chat = new ChatSystem("Client");
            Observer observer=new Observer("Observer", chat, model);
            Controller controller = new Controller(model, chat);

            Application.Run(new Login(controller)); //Mistake this call will go into a a loop which first leaves it when closing the GUI. First then it connects to the server
            //with the last 2 method calls.

            client.setObserver(observer);
            client.Loopconnect();
        }
Пример #2
0
        public void execute(string what)
        {
            //this switch case will execute a set of calls depending on the what.
            //MVC stuff
            switch (what)
            {
                case "login":
                    if(modelManager.login(this.username,this.password))
                    {
                        user = this.username;
                        chat = new ChatSystem(user);
                        this.loggedin = true;
                    }
                    else
                    {
                        MessageBox.Show("Login Incorrect, try again", "Login Incorrect");
                    }
                    break;

                case "register":
                    if (modelManager.register(this.username, this.password))
                    {
                        goto case "login";
                    }
                    else
                    {
                        MessageBox.Show("Register failed; Please try again.", "Registration Failed.");
                        //check console output for OLEDB error message
                    }
                    break;
                case "sendMessage":
                    modelManager.sendMessage(user, chat.getMessage());
               break;
                case "logout":
                    modelManager.logout(user);
               break;

            }
        }
Пример #3
0
 public Observer(string name, ChatSystem chat, ModelManager model)
 {
     this.model = model;
     this.ObserverName = name;
     this.chat = chat;
 }
Пример #4
0
 public Controller(ModelManager model, ChatSystem chatSystem)
 {
     this.chat = chatSystem;
     this.modelManager = model;
 }