Esempio n. 1
0
 private void UpdateUserList(ICollection <string> users)
 {
     if (chatTextBox.InvokeRequired)
     {
         var d = new UpdateUserListDelegate(UpdateUserList);
         userListComboBox.Invoke(d, new object[] { users });
     }
     else
     {
         userListComboBox.Items.Clear();
         userListComboBox.Items.AddRange(users.Select(x => (object)x).ToArray());
     }
 }
Esempio n. 2
0
 public CModel(UpdateUserListDelegate upd_delegate, GetMessageDocumentEnd get_msg_doc_delegate,
               IncomingMessage incoming_message_delegate, SaveIncomingFile incoming_file_delegate,
               LoginRequestResultProcessor log_req_res, SynchronizationContext cntx)
 {
     m_is_logged_in = false;
     m_messages     = new Dictionary <string, CMessage>();
     m_new_messages = new List <string>();
     m_login_probe  = false;
     m_update_user_list_delegate = upd_delegate;
     m_get_message_document_end  = get_msg_doc_delegate;
     m_incoming_message          = incoming_message_delegate;
     m_incoming_file             = incoming_file_delegate;
     m_login_req_res             = log_req_res;
     m_event_queue = new ConcurrentQueue <CQueueMessage>();
     m_context     = cntx;
 }
Esempio n. 3
0
        private void ConnectButton_Click(object sender, EventArgs e)
        {
            int.TryParse(portTextBox.Text, out var port);
            IPAddress.TryParse(ipAddressTextBox.Text, out var ip);

            if (port == default || ip == null || string.IsNullOrEmpty(nicknameBox.Text))
            {
                var incorrectFields =
                    $"{(port == default ? "port, " : string.Empty)}" +
                    $"{(ip == null ? "ip address, " : string.Empty)}" +
                    $"{(string.IsNullOrEmpty(nicknameBox.Text) ? "nickname" : string.Empty)}";

                MessageBox.Show($"Some fields are incorrect: {incorrectFields.TrimEnd(new []{' ', ','})}");
            }
            else
            {
                var fillChatDelegate       = new FillChatDelegate(AppendText);
                var updateUserListDelegate = new UpdateUserListDelegate(UpdateUserList);

                try
                {
                    _backgroundWorker.Connect(
                        ip.ToString(),
                        port,
                        nicknameBox.Text,
                        fillChatDelegate,
                        updateUserListDelegate);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    return;
                }

                connectButton.Enabled    = false;
                nicknameBox.Enabled      = false;
                portTextBox.Enabled      = false;
                ipAddressTextBox.Enabled = false;
            }
        }
Esempio n. 4
0
        ///<exception cref="SocketException"></exception>
        public void Connect(
            string hostname,
            int port,
            string nickname,
            FillChatDelegate fillChatDelegate,
            UpdateUserListDelegate updateUserListDelegate)
        {
            if (!_isConnected)
            {
                _nickname               = nickname;
                _fillChatDelegate       = fillChatDelegate;
                _updateUserListDelegate = updateUserListDelegate;

                _client      = new TcpClient(hostname, port);
                _stream      = _client.GetStream();
                _isConnected = true;

                SendMessage(new NetworkProtocol.Event(NetworkProtocol.EventType.Connect, _nickname));

                Task.Run(StartReceiveMessages);
            }
        }