コード例 #1
0
 private void addMessageToFriend(Friend findfriend, ChatMessage message)
 {
     #region
     findfriend._MessageMode = MessageMode.None;
     findfriend._Messages.Add(message);
     TrafficMsg.PostMessage(int.Parse(UserMainWindow._FrmHandle.ToString()), 501, 0, 0);
     #endregion
 }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        public void RegisterListen(IconController iconController)
        {
            #region

            TcpClientEx tcpclient = ChatClient.ConnectServer();

            SendRegisterClientListen sendregister = new SendRegisterClientListen()
            {
                _UserInfor = Logon._User
            };
            SendOnlineMarkup sendonlinemarkup = new SendOnlineMarkup()
            {
                _UserInfor = Logon._User
            };

            byte[] sendregistercommand = sendregister.GetProtocolCommand();
            byte[] sendonlinecommand   = sendonlinemarkup.GetProtocolCommand();
            tcpclient.SendToEndDevice(sendregistercommand);

            //可接收是否发送成功
            while (true)
            {
                tcpclient.Receive();

                switch (tcpclient.GetResolveType())
                {
                case TProtocol.RecvChatContent:
                    RecvChatContent chatcontentcmd = new RecvChatContent();
                    tcpclient.Dispatcher(chatcontentcmd);

                    Friend friend = new Friend()
                    {
                        _User = new EntityTUser()
                        {
                            uid = chatcontentcmd._Content._FromUID.ToString()
                        }
                    };

                    int    timestartindex = chatcontentcmd._Content._Text.Length - 19;
                    string dt             = chatcontentcmd._Content._Text.Substring(timestartindex, 19);

                    ChatMessage message = new ChatMessage()
                    {
                        _Content  = chatcontentcmd._Content._Text.Substring(0, timestartindex),
                        _RecvTime = DateTime.Parse(dt)
                    };

                    Friend findfriend = FriendCollector.FindFriend(friend);
                    if (findfriend != null)
                    {
                        if (findfriend._MessageMode == MessageMode.HasPop)
                        {
                            findfriend._Messages.Add(message);
                            TrafficMsg.PostMessage(int.Parse(findfriend._FrmHandle.ToString()), 500, 0, 0);
                        }
                        else
                        {
                            addMessageToFriend(findfriend, message);
                        }
                    }
                    else
                    {
                        friend._User        = UserMainWindow.GetFriendUser(friend._User.uid);
                        friend._Messages    = new List <ChatMessage>();
                        friend._MessageMode = MessageMode.None;
                        friend._Messages.Add(message);

                        FriendCollector.Add(friend);
                        TrafficMsg.PostMessage(int.Parse(UserMainWindow._FrmHandle.ToString()), 501, 0, 0);
                    }

                    break;

                case TProtocol.RecvOnlineMarkup:
                    tcpclient.SendToEndDevice(sendonlinecommand);
                    break;
                }
            }
            #endregion
        }