Esempio n. 1
0
        private void HandleMessage(MessageEntity ReceiveMsg)//处理Message类信息
        {
            //查找好友列表中IP,如果存在,则头像闪烁并记录消息
            var FriendList = from item in Program.FriendList where item.IPAdress == ReceiveMsg.MyInformation.IPAdress select item;

            if (FriendList == null || FriendList.Count() <= 0)
            {
                Program.FriendList.Add(ReceiveMsg.MyInformation);
            }
            AccessMethod AccMethod = new AccessMethod();
            var          Frm       = AccMethod.findForm(ReceiveMsg.Adress);

            if (Frm != null)
            {
                //消息加入对话窗体控件显示窗体
                TalkWinFrm frm = (TalkWinFrm)Frm;
                frm.FreshChatMessage(ReceiveMsg);
            }
            else
            {
                TalkWinFrm NewFrm = new TalkWinFrm(ReceiveMsg);
                NewFrm.Show();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 消息处理方法
        /// </summary>
        /// <param name="ByteArray">收到的消息体</param>
        private void HandleReceiveByte(byte[] ByteArray)//消息处理
        {
            var ReceiveMessage = (MessageEntity)null;

            try
            {
                ReceiveMessage = (MessageEntity)IMLibrary.Serializers.ByteToObj(ByteArray);
                if (string.IsNullOrEmpty(ReceiveMessage.Flag))
                {
                    return;
                }
                if (string.IsNullOrEmpty(ReceiveMessage.Adress))
                {
                    return;
                }
            }
            catch (Exception ex)
            {
            }
            switch (ReceiveMessage.Flag)
            {
            case "Login":
                //如果有此IP则忽略,否则增加好友列表并给此IP发送消息
                var FriendList = from item in Program.FriendList where item.IPAdress == ReceiveMessage.Adress select item;
                if (FriendList.Count() < 1)
                {
                    Program.FriendList.Add(ReceiveMessage.MyInformation);
                    HandleMethod.UdpBrodcastSend("Login", "", new IPEndPoint(IPAddress.Parse(ReceiveMessage.Adress), 8002));
                    this.treeList1.DataSource = null;
                    this.treeList1.DataSource = Program.FriendList;
                    this.treeList1.Refresh();
                }
                break;

            case "Out":
                //如果有此IP则删除好友,否则忽略
                FriendList = from item in Program.FriendList where item.IPAdress == ReceiveMessage.Adress select item;
                if (FriendList.Count() > 0)
                {
                    foreach (var item in Program.FriendList)
                    {
                        if (item.IPAdress == ReceiveMessage.Adress)
                        {
                            Program.FriendList.Remove(item);
                            this.treeList1.DataSource = null;
                            this.treeList1.DataSource = Program.FriendList;
                            this.treeList1.Refresh();
                            break;
                        }
                    }
                }
                break;

            case "Message":
                //查找好友列表中IP,如果存在,则头像闪烁并记录消息
                FriendList = from item in Program.FriendList where item.IPAdress == ReceiveMessage.Adress select item;
                if (FriendList.Count() > 0)
                {
                    AccessMethod AccMethod = new AccessMethod();
                    var          Frm       = AccMethod.findForm(ReceiveMessage.Adress);
                    if (Frm != null)
                    {
                        //消息加入对话窗体控件显示窗体
                        TalkWinFrm frm = (TalkWinFrm)Frm;
                        frm.FreshChatMessage(ReceiveMessage);
                    }
                    else
                    {
                        TalkWinFrm NewFrm = new TalkWinFrm(ReceiveMessage);
                        //NewFrm.Name = ReceiveMessage.CumputerName;
                        //NewFrm.Tag = ReceiveMessage.Adress;
                        ////消息加入对话窗体控件展示
                        //NewFrm.Text = "和" + ReceiveMessage.MyInformation.TrueName + "聊天中...";
                        NewFrm.Show();
                    }
                }
                else
                {
                    Program.FriendList.Add(ReceiveMessage.MyInformation);
                }
                break;

            default:
                break;
            }
        }