Ejemplo n.º 1
0
        private void SendButton_OnClick(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(MessageArea.Text) || ActualUsers.SelectedIndex < 0)
            {
                return;
            }
            var text = MessageArea.Text;
            var user = _usersList[ActualUsers.SelectedIndex];

            _messages.Add(new Message
            {
                Date = DateTime.Now,
                FirstConnectionId  = null,
                MessageText        = text,
                SecondConnectionId = user.ConnectionId
            });
            ActualMessages.ItemsSource = null;
            ActualMessages.ItemsSource = _messages;
            MessageArea.Text           = "";
            try
            {
                UpdateCipher(CipherTypeList.SelectedIndex);
                _hubProxy.Invoke("SendMessage", _userConnection.ConnectionId, user.ConnectionId,
                                 _cipher.Encryption(text), CipherTypeList.SelectedIndex).Wait();
            }
            catch
            {
                MessageBox.Show("user is offline");
            }
        }