void DefineMessageType(Message message)
        {
            int i = CommonInfo.RetrieveMessageType(message.messageType);

            message.messageTime = DateTime.Now;
            message.IPAdress    = ((IPEndPoint)listeningClientMessagesSocket.RemoteEndPoint).Address.ToString();
            switch (i)
            {
            case 1:
                ProcessCommonMessage(message);
                break;

            case 2:
                ProcessPrivateMessage(message);
                break;

            case 3:
                ProcessHistoryRequestMessage(message);
                break;

            case 4:
                ProcessJoinToChatMessage(message);
                break;
            }
        }
Example #2
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();
            }
        }