Exemplo n.º 1
0
        private void buttonSendMessage_Click(object sender, EventArgs e)
        {
            if (richTextBoxMessageContent.Text != "")
            {
                if (client.isClientConnected)
                {
                    string messagecontent = richTextBoxMessageContent.Text;
                    ChatCommonInfo.Message message;

                    if (CurrentDialog != CHATDIALOG)
                    {
                        message = new ChatCommonInfo.Message(CurrentDialog, messagecontent);
                        chatDialogsInfo[message.messageReceiverID].Messages.Add("Я : " + messagecontent);
                    }
                    else
                    {
                        message = new ChatCommonInfo.Message()
                        {
                            messageContent = messagecontent, messageType = ChatCommonInfo.Message.MessageType[1],
                        };
                    }

                    if (httpClient.LoadedToServerFiles.Count != 0)
                    {
                        labelFileManageStatus.Text = "OK";
                        message.areFilesSended     = true;
                        var fileInformationList = new List <FileInformaton>();
                        foreach (KeyValuePair <int, string> keyValuePair in httpClient.LoadedToServerFiles)
                        {
                            fileInformationList.Add(new ChatCommonInfo.FileInformaton()
                            {
                                fileID = keyValuePair.Key, fileName = keyValuePair.Value
                            });
                        }

                        message.sendedFilesList = fileInformationList;
                        httpClient.LoadedToServerFiles.Clear();
                        httpClient.commonSizeOfLoadedFiles = 0;
                        selectedLoadedToServerFileIndex    = -1;
                        UpdateFilesList();
                    }
                    else
                    {
                        message.areFilesSended = false;
                    }

                    client.SendMessage(message);
                    richTextBoxMessageContent.Clear();

                    UpdateView();
                }
            }
            else
            {
                MessageBox.Show("Введите текст сообщения!", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Exemplo n.º 2
0
        private void buttonShowHistory_Click(object sender, EventArgs e)
        {
            comboBoxParticipants.SelectedIndex = 0;
            CurrentDialog                 = CHATDIALOG;
            selectedReceiverIndex         = comboBoxParticipants.SelectedIndex;
            labelCurrentClientDialog.Text = chatDialogsInfo[CHATDIALOG].Name;
            var message = new ChatCommonInfo.Message()
            {
                messageType = ChatCommonInfo.Message.MessageType[3]
            };

            client.SendMessage(message);
            UpdateView();
        }
Exemplo n.º 3
0
        public void ProcessReceivedMessages(ChatCommonInfo.Message message)
        {
            int i = CommonInfo.RetrieveMessageType(message.messageType);

            switch (i)
            {
            case 1:
                if (message.IPAdress == "")
                {
                    chatDialogsInfo[CHATDIALOG].AddMessage(DateTime.Now.ToShortTimeString()
                                                           + " - " + message.messageName + " : " + message.messageContent);
                }
                else
                {
                    chatDialogsInfo[CHATDIALOG].AddMessage(message.messageTime.ToString() + " - " + message.IPAdress
                                                           + " - " + message.messageName + " : " + message.messageContent);
                }

                if (message.areFilesSended)
                {
                    foreach (ChatCommonInfo.FileInformaton fileInformaton in message.sendedFilesList)
                    {
                        chatDialogsInfo[CHATDIALOG].FilesToSave.Add(fileInformaton.fileID, fileInformaton.fileName);
                    }
                }
                break;

            case 2:
                chatDialogsInfo[message.messageSenderID].AddMessage(message.messageTime.ToString() + " : " + message.messageContent);
                labelNewMessage.Text = "Новое сообщение от " + message.messageName;

                if (message.areFilesSended)
                {
                    foreach (ChatCommonInfo.FileInformaton fileInformaton in message.sendedFilesList)
                    {
                        chatDialogsInfo[message.messageSenderID].FilesToSave.Add(fileInformaton.fileID, fileInformaton.fileName);
                    }
                }
                break;

            case 3:
                chatDialogsInfo[CurrentDialog].Messages = message.messageHistory;
                break;

            case 5:
            {
                ProcessFormFilling FormFillingNewClient = delegate
                {
                    clientsInfo.Clear();
                    clientsInfo.Add(new ClientsInfo()
                        {
                            clientID = CHATDIALOG, clientName = "Чат"
                        });
                    foreach (ClientsInfo nameClient in message.clientsInfo)
                    {
                        clientsInfo.Add(nameClient);
                        if (!chatDialogsInfo.ContainsKey(nameClient.clientID))
                        {
                            chatDialogsInfo.Add(nameClient.clientID, new AllDialogsMessages(nameClient.clientName));
                        }
                    }
                };
                if (InvokeRequired)
                {
                    Invoke(FormFillingNewClient);
                }
                else
                {
                    FormFillingNewClient();
                }
            }
            break;

            case 7:
            {
                ProcessFormFilling FormFillingServerResponse = delegate
                {
                    textBoxServerIPAdress.Text    = message.IPAdress;
                    textBoxServerPort.Text        = message.serverPort.ToString();
                    textBoxServerIPAdress.Enabled = false;
                    textBoxServerPort.Enabled     = false;
                };
                if (InvokeRequired)
                {
                    Invoke(FormFillingServerResponse);
                }
                else
                {
                    FormFillingServerResponse();
                }
            }
            break;

            default:
                return;
            }
            if (i != 7)
            {
                UpdateView();
            }
        }