Example #1
0
        private void buttonSend_Click(object sender, EventArgs e)
        {
            //obj.Message = textMessage.Text;
            //obj.send();
            //// adding to the list Box
            //tBoxreciev.Text = " Me :" + textMessage.Text+"\n";
            ////listMessage.Items.Add(" Me :" + textMessage.Text);
            //textMessage.Text = " ";

            string displayName = Entities.Properties.Settings.Default.DisplayName;

            string textMessage = txtSend.Text;

            //string textMessag = textMessage.Text;
            Entities.TextMessage msg = new Entities.TextMessage()
            {
                Msg  = textMessage,
                User = new User()
                {
                    DisplayName = displayName,
                    Status      = UserStatus.Offline,
                    IPAddress   = textRemotIP.Text,
                }
            };
            obj.send(msg);
            tBoxreciev.Text = " Me :" + textMessage + "\n";
            // textMessage.Text = " ";
        }
Example #2
0
        private void UpdateDisplayPanel(Entities.TextMessage msg)
        {
            if (msg.Type == TextMessageType.TextMessage)
            {
                txtRecieved.Text = msg.Msg;
                ChatBallon ballon = new ChatBallon()
                {
                    ChatText = msg.Msg, ChatBallonDirection = Direction.LeftToRight
                };

                ChatBallon cb = null;
                try
                {
                    cb = (ChatBallon)panel1.Controls[panel1.Controls.Count - 1];
                    ballon.Location = new Point(0, cb.Location.Y + cb.Height);
                    panel1.Controls.Add(ballon);
                }
                catch
                {
                    panel1.Controls.Add(ballon);
                }
            }
            else if (msg.Type == TextMessageType.StatusMessage)
            {
                if (usersList.Count(x => x.IPAddress == msg.User.IPAddress) == 0)
                {
                    usersList.Add(msg.User);
                    StatusIndicator si = new StatusIndicator(msg.User.DisplayName, msg.User.Status, msg.User.IPAddress);
                    flowLayoutPanel1.Controls.Add(si);
                }
                listBox1.DataSource = usersList.Select(u => u.DisplayName).ToList <string>();
            }
        }
Example #3
0
        public void DisplayChat(Entities.TextMessage msg)
        {
            ChatBallon ballon = new UI.ChatBallon();

            ballon.ChatText            = msg.Msg;
            ballon.Time                = DateTime.Now.ToShortTimeString();
            ballon.ChatBallonDirection = msg.User.IPAddress == com.GetMyIPAddress() ? Direction.LeftToRight : Direction.RightToLeft;

            int top = 0;

            foreach (Control c in pnlChatDisplay.Controls)
            {
                top += c.Height + 10;
            }
            if (com.GetMyIPAddress() == msg.User.IPAddress)
            {
                ballon.Location = new Point(0, top);
            }
            else
            {
                ballon.Location = new Point(pnlChatDisplay.Width - ballon.Width, top);
            }

            ballon.Size = new Size(pnlChatDisplay.Width - 20, ballon.Height);
            pnlChatDisplay.Controls.Add(ballon);
        }
Example #4
0
        // private void updateUi(string msg)
        private void updateUi(Entities.TextMessage msg)
        {
            UserStatus statu = msg.User.Status;
            string     Ip    = msg.User.IPAddress;
            string     nam   = msg.User.DisplayName;

            if (msg.User.Status == UserStatus.Available)
            {
                if (msg.Type == TextMessageType.TextMessage)
                {
                    tBoxreciev.AppendText("\n" + nam + " :" + msg.Msg + " Status :" + statu + " IP :" + Ip + "\n");
                }
                else if (msg.Type == TextMessageType.StatusMessage)
                {
                    if (usersList.Count(x => x.IPAddress == msg.User.IPAddress) == 0)
                    {
                        usersList.Add(msg.User);
                        // StatusIndicator si = new StatusIndicator(msg.User.DisplayName, msg.User.Status, msg.User.IPAddress);
                        // flowLayoutPanel1.Controls.Add(si);
                        string     n = msg.User.DisplayName;
                        UserStatus s = msg.User.Status;
                        string     I = msg.User.IPAddress;
                        tBoxreciev.AppendText("Frind Name :" + n + "Status :" + s + "IP :" + I + "\n");
                    }
                    listBox1.DataSource = usersList.Select(u => u.DisplayName).ToList <string>();
                }
            }
            else if (msg.User.Status == UserStatus.Bussy)
            {
                if (msg.Type == TextMessageType.TextMessage)
                {
                    tBoxreciev.AppendText("\n" + nam + " :" + msg.Msg + " Status :" + statu + " IP :" + Ip + "\n");
                }
            }
            else if (msg.User.Status == UserStatus.Offline)
            {
                if (msg.Type == TextMessageType.TextMessage)
                {
                    tBoxreciev.AppendText("\n" + nam + " :" + msg.Msg + " Status :" + statu + " IP :" + Ip + "\n");
                }
            }
            else //if (msg.User.Status == UserStatus.UnAvailable)
            {
                if (msg.Type == TextMessageType.TextMessage)
                {
                    tBoxreciev.AppendText("\n" + nam + " :" + msg.Msg + " Status :" + statu + " IP :" + Ip + "\n");
                }
            }

            //this.Invoke(new EventHandler(delegate
            //{
            //    tBoxreciev.AppendText("Frind :"+msg + "\n");

            //}));
        }
Example #5
0
        private void btnSend_Click(object sender, EventArgs e)
        {
            string textMessage = txtChatText.Text;

            Entities.TextMessage msg = new Entities.TextMessage()
            {
                Type = TextMessageType.TextMessage, Msg = textMessage, User = Me
            };
            chatBallonDirection = Direction.LeftToRight;
            com.Send(msg, new System.Net.IPEndPoint(System.Net.IPAddress.Parse(ClientIPAddress), 8000));
            txtChatText.Focus();
            txtChatText.Text = "";
            UpdateDisplayPanel(msg);
        }
Example #6
0
        private void btnSend_Click(object sender, EventArgs e)
        {
            string displayName = Entities.Properties.Settings.Default.DisplayName;

            string textMessage = txtSend.Text;

            Entities.TextMessage msg = new Entities.TextMessage()
            {
                Msg  = textMessage,
                User = new User()
                {
                    DisplayName = displayName,
                    Status      = UserStatus.Available,
                    IPAddress   = "127.0.0.1"
                }
            };
            com.Send(msg, new System.Net.IPEndPoint(System.Net.IPAddress.Parse("127.0.0.1"), 8000));
        }
Example #7
0
        public static byte[] EncodeMessage(TextMessage msg)
        {
            int displayNameLength = 0, MsgLength = 0, ipAddressLength = 0;

            displayNameLength = msg.User.DisplayName.Length;
            MsgLength         = msg.Msg.Length;
            ipAddressLength   = msg.User.IPAddress.Length;

            byte[] displayName = Encoding.Default.GetBytes(msg.User.DisplayName);
            byte[] textMessage = Encoding.Default.GetBytes(msg.Msg);
            byte[] ipAddress   = Encoding.Default.GetBytes(msg.User.IPAddress);
            byte[] preamble    = Encoding.Default.GetBytes("AA");

            List <byte> frame = new List <byte>();

            foreach (byte pr in preamble)
            {
                frame.Add(pr);
            }

            frame.Add((byte)msg.Type);
            frame.Add((byte)msg.User.Status);
            frame.Add((byte)displayNameLength);
            frame.Add((byte)MsgLength);
            frame.Add((byte)ipAddressLength);

            foreach (byte dN in displayName)
            {
                frame.Add(dN);
            }
            foreach (byte txt in textMessage)
            {
                frame.Add(txt);
            }
            foreach (byte ip in ipAddress)
            {
                frame.Add(ip);
            }
            return(frame.ToArray());
        }
Example #8
0
        private void UpdateDisplayPanel(Entities.TextMessage msg)
        {
            if (msg.Type == TextMessageType.TextMessage)
            {
                //txtRecieved.Text = msg.Msg;
                ChatBallon ballon = new ChatBallon()
                {
                    ChatText = msg.Msg, ChatBallonDirection = Direction.LeftToRight
                };
                int top = 0;
                //ChatBallon cb = null;
                try
                {
                    //cb = (ChatBallon)pnlChatDisplay.Controls[pnlChatDisplay.Controls.Count - 1];

                    foreach (Control c in pnlChatDisplay.Controls)
                    {
                        top += c.Height;
                    }
                    ballon.Location = new Point(0, top);
                    pnlChatDisplay.Controls.Add(ballon);
                }
                catch
                {
                    //pnlChatDisplay.Controls.Add(ballon);
                }
            }
            //else if (msg.Type == MessageType.StatusMessage)
            //{
            //    //if (usersList.Count(x => x.IPAddress == msg.User.IPAddress) == 0)
            //    //{
            //    //    usersList.Add(msg.User);
            //    //    StatusIndicator si = new StatusIndicator(msg.User.DisplayName, msg.User.Status, msg.User.IPAddress);
            //    //    flowLayoutPanel1.Controls.Add(si);
            //    //}
            //    //listBox1.DataSource = usersList.Select(u => u.DisplayName).ToList<string>();

            //}
        }
Example #9
0
        private void UpdateDisplayPanel(Entities.TextMessage msg)
        {
            if (msg.Type == TextMessageType.TextMessage)
            {
                if (msg.User.IPAddress != Me.IPAddress)
                {
                    try
                    {
                        frmChatWindow frm = chatWindows.Where(f => f.SI.IpAddress == msg.User.IPAddress).FirstOrDefault();
                        if (frm == null)
                        {
                            frm              = new frmChatWindow(new StatusIndicator(msg.User.DisplayName, msg.User.Status, msg.User.IPAddress));
                            frm.FormClosing += Frm_FormClosing;
                            Me = new User(Entities.Properties.Settings.Default.DisplayName, (UserStatus)Entities.Properties.Settings.Default.Status, com.GetMyIPAddress());

                            frm.ClientIPAddress = msg.User.IPAddress;
                            frm.Me = Me;

                            if (chatWindows.Count(x => x.SI.IpAddress == msg.User.IPAddress) == 0)
                            {
                                chatWindows.Add(frm);
                            }
                            //frm.DisplayChat(msg);
                            if (Me.Status == UserStatus.Available)
                            {
                                frm.Show();
                            }
                            else //This is for testing purpose
                            {
                                foreach (StatusIndicator s in flContainer.Controls)
                                {
                                    if (msg.User.IPAddress == s.IpAddress)
                                    {
                                        s.NumberOfUnreadMessages++;
                                        break;
                                    }
                                }
                            }
                            frm.Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - (Width + frm.Width), Screen.PrimaryScreen.WorkingArea.Height - frm.Height);
                        }
                        else //This is for testing purpose
                        {
                            foreach (StatusIndicator s in flContainer.Controls)
                            {
                                if (msg.User.IPAddress == s.IpAddress)
                                {
                                    s.NumberOfUnreadMessages++;
                                    break;
                                }
                            }
                        }
                        frm.DisplayChat(msg);
                    }
                    catch
                    {
                    }
                }
            }
            else if (msg.Type == TextMessageType.StatusMessage)
            {
                if (usersList.Count(x => x.IPAddress == msg.User.IPAddress) == 0)
                {
                    usersList.Add(msg.User);
                    StatusIndicator si = new StatusIndicator(msg.User.DisplayName, msg.User.Status, msg.User.IPAddress);
                    si.Click += Si_Click;
                    si.Width  = flContainer.Width - 2;
                    flContainer.Controls.Add(si);
                }
                else
                {
                    int index = usersList.IndexOf(usersList.Where(x => x.IPAddress == msg.User.IPAddress).First());
                    ((StatusIndicator)flContainer.Controls[index]).Status      = msg.User.Status;
                    ((StatusIndicator)flContainer.Controls[index]).DisplayName = msg.User.DisplayName;
                }
            }
        }