public List<ChatMessage> GetNewMessages(ChatUser user) { List<ChatMessage> myNewMessages = incomingMessages[user.UserName]; incomingMessages[user.UserName]=new List<ChatMessage>(); if (myNewMessages.Count > 0) return myNewMessages; else return null; }
//ChatUser object aanmaken voor nieuwe gebruiker public ChatUser AddNewChatUser(ChatUser user) { var exists = from ChatUser e in this.ConnectedUsers where e.UserName == user.UserName select e; if (exists.Count() == 0) { this.ConnectedUsers.Add(user); incomingMessages.Add(user.UserName, new List<ChatMessage>() { new ChatMessage(){User=new ChatUser{UserName="******"},Message=user+" is het kanaal binnengekomen",Date=DateTime.Now} }); Console.WriteLine("New user connected: " + user); return user; } else return null; }
/** * Inloggen */ private void loginToolStripMenuItem_Click(object sender, EventArgs e) { try { lblStatus.Text = "Verbinden..."; /** * Loginform openen */ LoginForm loginDialog = new LoginForm(); loginDialog.ShowDialog(this); if (!String.IsNullOrEmpty(loginDialog.UserName)) { //Verbinding maken remoteFactory = new ChannelFactory<IChatService>("ChatConfig"); remoteProxy = remoteFactory.CreateChannel(); clientUser = remoteProxy.ClientConnect(loginDialog.UserName); if (clientUser != null) { usersTimer.Enabled = true; messagesTimer.Enabled = true; loginToolStripMenuItem.Enabled = false; btnSend.Enabled = true; txtMessage.Enabled = true; isConnected = true; lblStatus.Text = "Verbonden als: " + clientUser.UserName; } } else lblStatus.Text = "Verbinding verbroken"; } catch (Exception ex) { MessageBox.Show("Er is een fout opgetreden\nClient kan geen verbinding maken\n:"+ex.Message, "FATAL ERROR",MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void RemoveUser(ChatUser user) { this.ConnectedUsers.RemoveAll(u=>u.UserName==user.UserName); }
//Gebruiker van de server verwijderen public void RemoveUser(ChatUser user) { mainEngine.RemoveUser(user); }
//Berichten ophalen van de server public List<ChatMessage> GetNewMessages(ChatUser user) { return mainEngine.GetNewMessages(user); }