private void button2_Click(object sender, EventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); dialog.Multiselect = false; if (dialog.ShowDialog().Equals(DialogResult.OK)) { try { string filename = dialog.FileName; byte[] file = File.ReadAllBytes(filename); var ans = MessageBox.Show("Add the file " + Path.GetFileName(filename) + " to be sent", "Confirm", MessageBoxButtons.YesNo); if (ans == DialogResult.Yes) { Task t = Task.Factory.StartNew(() => { Message message = new Message(ClientApp.GetLoggedUser(), "Sent file " + Path.GetFileName(filename), _chatName); message.AddFile(file, Path.GetFileName(filename)); _chat.WriteMessage(message); }); } } catch (Exception error) { MessageBox.Show("Unable to upload the file", "Error", MessageBoxButtons.OK); Console.WriteLine(error.Message); } } }
private void InviteWindow_FormClosed(object sender, FormClosedEventArgs e) { BeginInvoke((MethodInvoker) delegate() { _iFriend.RejectChat(ClientApp.GetLoggedUser(), _chatName, _id); this.Close(); }); }
private string CreateID(List <ActiveUser> users) { string name = ClientApp.GetLoggedUser().Username; foreach (var u in users) { name += u.Username; } return(String.Concat(name.OrderBy(c => c))); }
private void MainWindow_Load(object sender, EventArgs e) { foreach (ActiveUser user in _onlineUsers) { if (user.Equals(ClientApp.GetLoggedUser())) { continue; } ListViewItem lvItem = new ListViewItem(user.Username); listView1.Items.Add(lvItem); lvItem.ImageIndex = 0; } }
private void sendButton_Click(object sender, EventArgs e) { char[] charsToTrim = { ' ' }; string test = inputMessage.Text.Trim(charsToTrim); if (!test.Equals("")) { Message m = new Message(ClientApp.GetLoggedUser(), inputMessage.Text, _chatName); _messages.Add(m); Thread t = new Thread(() => { _chat.WriteMessage(m); }); t.Start(); inputMessage.Text = ""; } }
private void AcceptInvationButton_Click(object sender, System.EventArgs e) { string chatName; if (_chatName != _user.Username) { chatName = _chatName; } else { chatName = ClientApp.GetLoggedUser().Username; } Task.Factory.StartNew(() => { _iFriend.AcceptChat(ClientApp.GetLoggedUser(), chatName, _chat, _id); }); ClientApp.GetMainWindow().StartChatBox(_user, _chatName, _chat, _id); this.Close(); }
void InsertMessage(Message m) { string dateTime = m.MessageDate.ToString("g", CultureInfo.CreateSpecificCulture("fr-FR")); if (m.GetFiles().Count > 0) { for (int i = 0; i < m.GetFiles().Count; i++) { ListViewItem s = new ListViewItem(); s.Text = m.GetFilesName()[i]; files.Add(m.GetFiles()[i]); filesShared.Items.Add(s); } } string message = ""; if (m.MessageSent == null) { return; } if (m.Sender.Username == ClientApp.GetLoggedUser().Username) { chatMessages.SelectionAlignment = HorizontalAlignment.Right; message += m.Sender.Username + " (Me)"; } else { chatMessages.SelectionAlignment = HorizontalAlignment.Left; message += m.Sender.Username; } message += " - " + dateTime + Environment.NewLine + m.MessageSent + Environment.NewLine + Environment.NewLine; chatMessages.SelectionFont = new Font(chatMessages.Font, FontStyle.Regular); chatMessages.AppendText(message); }
private void RejectInvitationButton_Click(object sender, System.EventArgs e) { _iFriend.RejectChat(ClientApp.GetLoggedUser(), _chatName, _id); this.Close(); }
private void CreateChat_Click(object sender, EventArgs e) { List <ActiveUser> users = new List <ActiveUser>(); var selectedUsers = listView1.SelectedItems; bool groupChat = selectedUsers.Count > 1; for (var index = 0; index < selectedUsers.Count; index++) { foreach (var contact in _onlineUsers) { if (contact.Username.Equals(selectedUsers[index].Text)) { users.Add(contact); break; } } } string id = CreateID(users); bool exists = ClientApp.GetInstance().GetPendingChats().Contains(id) || ClientApp.GetInstance().GetChats().ContainsKey(id); if (users.Count == 1 && !exists) { IClientRem friend = (IClientRem)RemotingServices.Connect(typeof(IClientRem), users[0].Address); ClientApp.GetInstance().GetPendingChats().Add(id); RemoteChat chat = new RemoteChat(); Task.Factory.StartNew(() => { try { friend.Invite(new ControlMessage(ClientApp.GetLoggedUser(), Client.ClientApp.GetLoggedUser().Username, chat, id)); } catch (Exception e) { Console.WriteLine("Invitation Failed"); Console.WriteLine(e); } Console.WriteLine("success"); }); } else if (users.Count > 1 && !exists) { Form1 chatNameForm = new Form1(); chatNameForm.ShowDialog(); RemoteChat chat = new RemoteChat(); foreach (var user in users) { IClientRem friend = (IClientRem)RemotingServices.Connect(typeof(IClientRem), user.Address); Task.Factory.StartNew(() => { Console.WriteLine(@"Invitation sent to " + user.Username + " to join " + chatNameForm.GetText); try { friend.Invite(new ControlMessage(ClientApp.GetLoggedUser(), chatNameForm.GetText, chat, id)); } catch (Exception e) { Console.WriteLine("Invitation Failed"); Console.WriteLine(e); } Console.WriteLine("success"); }); } } else if (users.Count < 1) { MessageBox.Show("Please select a user of a group of users", "No user was selected", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Chat already created or Invites sent", "Already Created", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void LogoutSession() { UnsubscribeServerNotifications(); ClientApp.GetServer().LogoutUser(ClientApp.GetLoggedUser()); }