Пример #1
0
 private void btGetHistory_Click(object sender, EventArgs e)
 {
     lbParticipants.SelectedIndex = 0;
     LANnode.Message message = new LANnode.Message(new List <string>(), clientsList[selectedIndex].Key);
     client.SendMessage(message);
     UpdateView();
 }
Пример #2
0
 private void btSendMessage_Click(object sender, EventArgs e)
 {
     if (selectedIndex != -1)
     {
         LANnode.Message message;
         if (CurrentDialogId == CommonChatDialogId)
         {
             message = new LANnode.Message(tbMessageContent.Text);
         }
         else
         {
             message = new LANnode.Message(clientsList[selectedIndex].Key, tbMessageContent.Text);
             chatDialogsInfo[message.ReceiverID].Messages.Add("Me: " + message.Content + "  " + DateTime.Now);
         }
         if (cbIsConnected.Checked)
         {
             client.SendMessage(message);
             UpdateView();
         }
     }
 }
Пример #3
0
        public void ShowReceivedMessages(LANnode.Message message)
        {
            switch (message.messageType)
            {
            case MessageType.Common:
                chatDialogsInfo[CommonChatDialogId].AddMessage(message.Name + ": "
                                                               + message.Content + "  " + message.Time + "  " + message.IPAdress);
                break;

            case MessageType.Private:
                chatDialogsInfo[message.SenderID].AddMessage(message.Content + "  " +
                                                             message.Time + "  " + message.IPAdress);
                break;

            case MessageType.ClientsList:
            {
                Action action = delegate
                {
                    clientsList.Clear();
                    clientsList.Add(new Endpoints()
                        {
                            Key = CommonChatDialogId, Name = "Common chat"
                        });
                    foreach (Endpoints nameClient in message.clientsNames)
                    {
                        clientsList.Add(nameClient);
                        if (!chatDialogsInfo.ContainsKey(nameClient.Key))
                        {
                            chatDialogsInfo.Add(nameClient.Key, new DialogInformation(nameClient.Name));
                        }
                    }
                };
                if (InvokeRequired)
                {
                    Invoke(action);
                }
                else
                {
                    action();
                }
            }
            break;

            case MessageType.SearchResponse:
            {
                Action action = delegate
                {
                    tbIPAdress.Text = message.IPAdress;
                    IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse(message.IPAdress), message.Port);
                    cbIsConnected.Checked = client.ConnectToServer(endPoint, tbName.Text);
                };
                if (InvokeRequired)
                {
                    Invoke(action);
                }
                else
                {
                    action();
                }
            }
            break;

            case MessageType.History:
                chatDialogsInfo[message.ReceiverID].Messages = message.messageHistory;
                break;
            }
            UpdateView();
        }