Beispiel #1
0
        private void Frm_FormClosing(object sender, FormClosingEventArgs e)
        {
            frmChatWindow frm   = (frmChatWindow)sender;
            int           index = chatWindows.IndexOf(chatWindows.Where(x => x.SI.IpAddress == frm.SI.IpAddress).First());

            chatWindows.RemoveAt(index);
        }
Beispiel #2
0
        private void Si_Click(object sender, EventArgs e)
        {
            StatusIndicator si  = (StatusIndicator)sender;
            frmChatWindow   frm = new frmChatWindow(si);

            frm.FormClosing += Frm_FormClosing;
            Me = new User(Entities.Properties.Settings.Default.DisplayName, (UserStatus)Entities.Properties.Settings.Default.Status, com.GetMyIPAddress());

            frm.ClientIPAddress = si.IpAddress;
            frm.Me = Me;

            if (chatWindows.Count(x => x.SI.IpAddress == si.IpAddress) == 0)
            {
                chatWindows.Add(frm);
            }
            frm.Show();
            frm.Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - (Width + frm.Width), Screen.PrimaryScreen.WorkingArea.Height - frm.Height);
        }
Beispiel #3
0
        private void UpdateDisplayPanel(Entities.Message msg)
        {
            if (msg.Type == MessageType.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 == 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);
                    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;
                }
            }
        }