Example #1
0
 private async void SendMessage()
 {
     try
     {
         if (SelectedChat == null || string.IsNullOrWhiteSpace(TbMessage.Text)) return;
         var message = new Message
         {
             Author = SessionParams.CurrentUser,
             Text = TbMessage.Text,
             Time = DateTime.Now
         };
         await _netWorker.SendMessage(SelectedChat.AddresseeUser, message);
         SelectedChat.AddMessage(message);
         TbMessage.Clear();
         TbMessage.Focus();
     }
     catch (Exception ex)
     {
         DisplayError(ex);
     }
 }
Example #2
0
 private void AddMessageToChat(Message ms)
 {
     var chat = Chats.FirstOrDefault(ch => Equals(ch.AddresseeUser, ms.Author));
     if (chat == null)
     {
         chat = new Chat() {AddresseeUser = ms.Author};
         Chats.Add(chat);
         chat.AddMessage(ms);
     }
     else chat.AddMessage(ms);
 }
Example #3
0
 private void RefreshUserList(Message ms)
 {
     if (Users.All(us => !Equals(us, ms.Author)))
         Users.Add(ms.Author);
 }
Example #4
0
 /// <summary>
 /// Send message async
 /// </summary>
 /// <param name="addresseeUser"></param>
 /// <param name="message"></param>
 /// <returns></returns>
 public async Task SendMessage(User addresseeUser, Message message)
 {
     var bf = new BinaryFormatter();
     using (var memoryStream = new MemoryStream())
     {
         bf.Serialize(memoryStream, message);
         await _udpClient.SendAsync(memoryStream.ToArray(), Convert.ToInt32(memoryStream.Length),
             new IPEndPoint(addresseeUser.IpAddress, GetIntParamFromConfig("RemotePort")));
     }
 }