コード例 #1
0
ファイル: Register.cs プロジェクト: SinJunior/ChatsApp
        private void sendRegister(string fullname, string username, string password, string email)
        {
            ChatHeaderObject header = new ChatHeaderObject()
            {
                Header      = Header.Register,
                SessionFrom = this.user
            };
            ChatPayloadObject payload = new ChatPayloadObject()
            {
                Fullname = fullname,
                Username = username,
                Password = password,
                Email    = email
            };
            ChatDataObject chatData = new ChatDataObject()
            {
                Header  = header,
                Payload = payload
            };

            try
            {
                this.chatClient.sendDataObject(chatData);
            }
            catch (Exception)
            {
                lblWarning.Text = "Kết nối tới máy chủ thất bại!";
                isConnect       = false;
            }
        }
コード例 #2
0
ファイル: Register.cs プロジェクト: SinJunior/ChatsApp
        private void linkRegister_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (isConnect)
            {
                ChatHeaderObject header = new ChatHeaderObject()
                {
                    Header      = Header.Quit,
                    SessionFrom = this.user
                };
                ChatPayloadObject payload = new ChatPayloadObject()
                {
                };
                ChatDataObject chatData = new ChatDataObject()
                {
                    Header  = header,
                    Payload = payload
                };
                this.chatClient.sendDataObject(chatData);
            }
            Login login = new Login(this._frmLogin, this.user);

            login.Location = this.Location;
            login.Width    = this.Width;
            login.Height   = this.Height;
            login.Anchor   = this.Anchor;
            panel1.Controls.Clear();
            panel1.Controls.Add(login);
        }
コード例 #3
0
 private void sendRefresh()
 {
     while (this.chatClient != null)
     {
         try
         {
             ChatHeaderObject header = new ChatHeaderObject()
             {
                 Header      = Header.Refresh,
                 SessionFrom = this.username
             };
             ChatPayloadObject payload = new ChatPayloadObject()
             {
             };
             ChatDataObject chatData = new ChatDataObject()
             {
                 Header  = header,
                 Payload = payload
             };
             this.chatClient.sendDataObject(chatData);
         }
         catch (Exception e)
         {
             Console.WriteLine(e.Message);
         }
         System.Threading.Thread.Sleep(5000);
     }
 }
コード例 #4
0
 private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (this.chatClient != null)
     {
         try
         {
             ChatHeaderObject header = new ChatHeaderObject()
             {
                 Header      = Header.Quit,
                 SessionFrom = this.username
             };
             ChatPayloadObject payload = new ChatPayloadObject()
             {
             };
             ChatDataObject chatData = new ChatDataObject()
             {
                 Header  = header,
                 Payload = payload
             };
             this.chatClient.sendDataObject(chatData);
         }
         catch (Exception ex)
         {
             Console.WriteLine(ex.Message);
         }
     }
 }
コード例 #5
0
        private void sendLoadMessage()
        {
            while (this.chatClient != null)
            {
                if (box != null && box.roomName != "" && loadBox)
                {
                    try
                    {
                        ChatHeaderObject header = new ChatHeaderObject()
                        {
                            SessionFrom = this.username,
                            Header      = Header.LoadMessage,
                            SessionTo   = box.roomName
                        };
                        ChatPayloadObject payload = new ChatPayloadObject()
                        {
                        };
                        ChatDataObject chatData = new ChatDataObject()
                        {
                            Header  = header,
                            Payload = payload
                        };
                        this.chatClient.sendDataObject(chatData);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                    loadBox = false;
                }

                System.Threading.Thread.Sleep(500);
            }
        }
コード例 #6
0
ファイル: chatbox.cs プロジェクト: SinJunior/ChatsApp
        private void getRoomName()
        {
            ChatHeaderObject header = new ChatHeaderObject()
            {
                SessionFrom = this.username,
                Header      = Header.GetRoomName
            };

            ChatPayloadObject payload = new ChatPayloadObject()
            {
                Username = username,
                Fullname = this.fullname,
                Data     = this.toUser
            };
            ChatDataObject chatData = new ChatDataObject()
            {
                Header  = header,
                Payload = payload
            };

            try
            {
                this.chatClient.sendDataObject(chatData);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
コード例 #7
0
        private void checkLogin(string username, string password)
        {
            ChatHeaderObject header = new ChatHeaderObject()
            {
                SessionFrom = this.user,
                Header      = Header.Login
            };

            ChatPayloadObject payload = new ChatPayloadObject()
            {
                Username = username,
                Password = password
            };
            ChatDataObject chatData = new ChatDataObject()
            {
                Header  = header,
                Payload = payload
            };

            try
            {
                this.chatClient.sendDataObject(chatData);
            }
            catch (Exception)
            {
                lblWarning.Text = "Kết nối tới máy chủ thất bại!";
                isConnect       = false;
            }
        }
コード例 #8
0
ファイル: chatbox.cs プロジェクト: SinJunior/ChatsApp
 private void button2_Click(object sender, EventArgs e)
 {
     if (type == ChatObject.ChatTypeMess.Message)
     {
         string mess = txtMessage.Text;
         if (mess != "" && mess != null)
         {
             sendMessage(this.fullname, mess, DateTime.Now.ToShortTimeString());
             ChatHeaderObject header = new ChatHeaderObject()
             {
                 Header      = Header.Message,
                 SessionFrom = this.username,
                 SessionTo   = this.roomName,
                 ChatType    = type
             };
             ChatPayloadObject payload = new ChatPayloadObject()
             {
                 MessageType = this.messageType,
                 Data        = mess,
                 Time        = DateTime.Now,
                 Fullname    = this.fullname
             };
             ChatDataObject chatData = new ChatDataObject()
             {
                 Header  = header,
                 Payload = payload
             };
             this.chatClient.sendDataObject(chatData);
             txtMessage.Text = "";
         }
     }
     else if (type == ChatObject.ChatTypeMess.File)
     {
         MessageBox.Show("Chức năng đang phát triển!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
         //try
         //{
         //    byte[] dataFile = File.ReadAllBytes(txtMessage.Text.Trim());
         //    string dataTranfer = Convert.ToBase64String(dataFile);
         //    string filePath = txtMessage.Text.Trim();
         //    string[] temp = filePath.Split('\\');
         //    string filename = temp[temp.Length - 1];
         //    sendFile(this.fullname, filename, DateTime.Now.ToShortTimeString());
         //    ChatHeaderObject header = new ChatHeaderObject()
         //    {
         //        Header = Header.Upload,
         //        SessionFrom = this.username,
         //        SessionTo = this.roomName,
         //        ChatType = type
         //    };
         //    ChatPayloadObject payload = new ChatPayloadObject()
         //    {
         //        MessageType = this.messageType,
         //        Data = dataTranfer,
         //        Time = DateTime.Now,
         //        Filename = filename
         //    };
         //    ChatDataObject chatData = new ChatDataObject()
         //    {
         //        Header = header,
         //        Payload = payload
         //    };
         //    this.chatClient.sendDataObject(chatData);
         //    txtMessage.Text = "";
         //}
         //catch (Exception)
         //{
         //    MessageBox.Show("Đường dẫn file sai", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         //}
     }
 }
コード例 #9
0
ファイル: frmCreateRoom.cs プロジェクト: SinJunior/ChatsApp
        private void btnCreateRoom_Click(object sender, EventArgs e)
        {
            string roomName = txtRoomName.Text;

            if (!"".Equals(roomName))
            {
                List <string> users = new List <string>();
                foreach (string user in lbUsers.CheckedItems)
                {
                    users.Add(user);
                }
                if (users.Count > 0)
                {
                    string           usersString = convertUserListToString(users);
                    ChatHeaderObject header      = new ChatHeaderObject()
                    {
                        SessionFrom = this.username,
                        Header      = Header.CreateRoom
                    };
                    ChatPayloadObject payload = new ChatPayloadObject()
                    {
                        ChatroomName = roomName,
                        Data         = usersString
                    };
                    ChatDataObject chatData = new ChatDataObject()
                    {
                        Header  = header,
                        Payload = payload
                    };
                    this.chatClient.sendDataObject(chatData);
                    if (chatClient != null)
                    {
                        try
                        {
                            Object o = this.chatClient.recvDataObject();
                            if (o != null)
                            {
                                ChatDataObject chatDataRecv = (ChatDataObject)o;

                                if (chatDataRecv.Header.Header == Header.CreateRoom)
                                {
                                    if (chatDataRecv.Payload.StatusCode == StatusCode.CheckTrue)
                                    {
                                        lblWarning.Text = "Tạo phòng thành công!";
                                    }
                                    else
                                    {
                                        lblWarning.Text = "Tên phòng trùng/ chưa chọn thành viên!";
                                    }
                                }
                            }
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
                else
                {
                    lblWarning.Text = "Chưa chọn thành viên!";
                }
            }
            else
            {
                lblWarning.Text = "Chưa nhập tên phòng!";
            }
        }