示例#1
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);
        }
示例#2
0
        private void SaveFile(Entities.FileMessage msg)
        {
            SaveFileDialog dlg = new SaveFileDialog();

            if (msg.FileMessageType == FileMessageType.Responese)
            {
                if (msg.FileStatus == FileStatus.NotStarted)
                {
                    if (dlg.ShowDialog() == DialogResult.OK)
                    {
                        FileNameToSave = dlg.FileName + ".pdf";
                        FileManager mgr = new FileManager(FileNameToSave, msg);
                        mgr.Save();

                        //msg.Index++;
                        msg.IpAddress       = com.GetMyIPAddress();
                        msg.FileStatus      = FileStatus.Started;
                        msg.FileMessageType = FileMessageType.Request;
                        msg.IPLength        = msg.IpAddress.Length;
                        com.Send(msg, new System.Net.IPEndPoint(IPAddress.Parse(msg.IpAddress), 8000));
                    }
                }
                else
                {
                    FileManager mgr = new FileManager(FileNameToSave, msg);
                    mgr.Save();

                    msg.Index++;
                    msg.IpAddress       = com.GetMyIPAddress();
                    msg.FileMessageType = FileMessageType.Request;
                    msg.IPLength        = msg.IpAddress.Length;
                    if (msg.FileStatus == FileStatus.Started)
                    {
                        com.Send(msg, new System.Net.IPEndPoint(IPAddress.Parse(msg.IpAddress), 8000));
                    }
                }
            }
            else if (msg.FileMessageType == FileMessageType.Request)
            {
                FileManager mgr = new FileManager(msg);
                //byte[] data = mgr.GetBytes(msg.Index);
                //msg.Data = new byte[data.Length];
                //Array.Copy(data, 0, msg.Data, 0, data.Length);
                //msg.IpAddress = com.GetMyIPAddress();
                //msg.IPLength = msg.IpAddress.Length;

                FileMessage fileMessage = mgr.GetMessage();
                fileMessage.FileMessageType = FileMessageType.Responese;
                fileMessage.IpAddress       = com.GetMyIPAddress();
                fileMessage.DataLength      = fileMessage.Data.Length;
                fileMessage.IPLength        = fileMessage.IpAddress.Length;
                fileMessage.FileName        = msg.FileName;
                fileMessage.FileNameLength  = msg.FileNameLength;
                fileMessage.FileStatus      = msg.FileStatus;
                fileMessage.Index           = msg.Index;
                fileMessage.Preamble        = msg.Preamble;
                com.Send(fileMessage, new System.Net.IPEndPoint(IPAddress.Parse(msg.IpAddress), 8000));
            }
        }
示例#3
0
 public frmChatWindow()
 {
     InitializeComponent();
     com = new UDPComm();
     Me  = new Entities.User(Entities.Properties.Settings.Default.DisplayName, (UserStatus)Entities.Properties.Settings.Default.Status, com.GetMyIPAddress());
     com.TextMessageRecieved += Com_MessageRecieved;
     com.Start();
 }
示例#4
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;
                }
            }
        }
示例#5
0
 public frmMain()
 {
     InitializeComponent();
     frmState             = FormState.Maximize;
     com                  = new UDPComm();
     com.MessageRecieved += Com_MessageRecieved;
     Me = new User(Entities.Properties.Settings.Default.DisplayName, (UserStatus)Entities.Properties.Settings.Default.Status, com.GetMyIPAddress());
     com.Start();
 }