private void OnForward() { try { if (SelectedContact != null) { if (!GlobalBase.IsMenuEnabled && GlobalBase.SelectedContact.UniqueName == SelectedContact.UniqueName) { return; } BaseMessage mes = null; if (SelectedContact is UserUiInfo) { var userUiInfo = SelectedContact as UserUiInfo; mes = new UserMessage() { Text = _message.Text, DateOfSending = _message.DateOfSending, SenderId = GlobalBase.CurrentUser.Id, ReceiverId = userUiInfo.UserId }; } else if (SelectedContact is ChatGroupUiInfo) { var groupUiInfo = SelectedContact as ChatGroupUiInfo; mes = new GroupMessage() { Text = _message.Text, DateOfSending = _message.DateOfSending, SenderId = GlobalBase.CurrentUser.Id, ChatGroupId = groupUiInfo.ChatGroupId }; } UserServiceClient.SendMessageAsync(mes).ContinueWith((task) => { if (GlobalBase.SelectedContact.UniqueName == SelectedContact.UniqueName) { GlobalBase.AddMessageOnUi(mes); } }); } _view.CloseWindow(); } catch (Exception) { } }
private void ExecuteOnSendMessage() { try { if (SelectedContact != null && (!string.IsNullOrWhiteSpace(MessageText) || FilesPath != null)) { BaseMessage messageTemplate = null; if (SelectedContact is UserUiInfo) { messageTemplate = new UserMessage(); } else if (SelectedContact is ChatGroupUiInfo) { messageTemplate = new GroupMessage(); } messageTemplate.DateOfSending = DateTime.Now; messageTemplate.SenderId = GlobalBase.CurrentUser.Id; messageTemplate.Sender = GlobalBase.CurrentUser; if (SelectedContact is UserUiInfo) { (messageTemplate as UserMessage).ReceiverId = (SelectedContact as UserUiInfo).UserId; } else if (SelectedContact is ChatGroupUiInfo) { (messageTemplate as GroupMessage).ChatGroupId = (SelectedContact as ChatGroupUiInfo).ChatGroupId; } if (MessageText != null && MessageText != string.Empty) { messageTemplate.Text = Encoding.UTF8.GetBytes(MessageText); UserServiceClient.SendMessageAsync(messageTemplate).ContinueWith(task => GlobalBase.AddMessageOnUi(UserServiceClient.GetLastMessage())); } if (FilesPath != null) { foreach (var file in FilesPath) { var chatFile = new FileService.ChatFile() { Source = CompressionHelper.CompressFile(GlobalBase.FileToByte(file)), Name = GlobalBase.GetShortName(file) }; messageTemplate.Text = Encoding.UTF8.GetBytes(chatFile.Name); messageTemplate.ChatFileId = GlobalBase.FileServiceClient.UploadFile(chatFile); UserServiceClient.SendMessageAsync(messageTemplate).ContinueWith(task => GlobalBase.AddMessageOnUi(UserServiceClient.GetLastMessage())); } } FilesPath = null; FileAmount = 0; MessageText = string.Empty; Debug.WriteLine("Send Message"); } } catch (Exception) { } }