/// <summary> /// Event handler to be executed when send button is clicked. /// /// New outbound message is constructed using the configured chat name and /// chat message from the message input field. Message is send to the other device. /// </summary> private async void sendButton_Click(object sender, EventArgs e) { Message m = new Message() { Name = _dataContext.Settings.Name, Text = messageInput.Text, Direction = Message.DirectionValue.Out }; // If we are transferring an image, load it into the message from the temporary image file if (m_ImageReadyToTransfer) { m.ImageName = string.Format("{0}.jpg", Guid.NewGuid()); // assign a unique image name await m.ConvertImageToByteArrayAsync(m_TempImageName); // load up the temporary image into the message's byte array await m.SaveByteArrayImageToFileSystemAsync(false); // save a local copy of the image, and do not clean up the byte array } // Clean up input values messageInput.Text = ""; messageImage.Source = null; messageImage.Visibility = System.Windows.Visibility.Collapsed; m_ImageReadyToTransfer = false; _dataContext.Messages.Add(m); await _dataContext.Communication.SendMessageAsync(m); scrollToLast(); }
/// <summary> /// Event handler to be executed when a new inbound message has been received. /// /// Message is stored to the DataContext.Messages. /// </summary> /// <param name="m"></param> private void MessageReceived(Message m) { Deployment.Current.Dispatcher.BeginInvoke(async() => { await m.SaveByteArrayImageToFileSystemAsync(); _dataContext.Messages.Add(m); }); }
/// <summary> /// Event handler to be executed when a new inbound message has been received. /// /// Message is stored to the DataContext.Messages. /// </summary> /// <param name="m"></param> private void MessageReceived(Message m) { Deployment.Current.Dispatcher.BeginInvoke(async () => { await m.SaveByteArrayImageToFileSystemAsync(); _dataContext.Messages.Add(m); }); }