Example #1
0
 //向TCP服务器发送信息,由它转发信息
 private void _sendBtn_Click(object sender, RoutedEventArgs e)
 {
     //_currentSelectUser
     if (_currentSelectUser.State != offLine)
     {
         string text = "s" + _localUser.UserId.ToString() + "|" + _currentSelectUser.UserId.ToString()
                       + "|" + _sendMseeageTb.Text;
         Byte[] sendData = new Byte[text.Length];
         sendData = Encoding.Default.GetBytes(text);
         tcp_stream.BeginWrite(sendData, 0, sendData.Length, new AsyncCallback(
                                   ar =>
         {
             tcp_stream.EndWrite(ar);
             //MessageBox.Show("Send Ok!");
         }
                                   ), (object)string.Empty);
         //add to ChatContentCollection, but it is belong to me which I chat with.
         ChatContent m = new ChatContent()
         {
             ImgSource = @"Resource/me.png",
             Content   = _sendMseeageTb.Text,
             IsSelf    = true
         };
         var vm = from b in chatContentCollectionList
                  where (b.ID == _currentSelectUser.UserId)
                  select b;
         vm.ElementAt(0).ChatContentCollection.Add(m);
         _sendLb.ScrollIntoView(m);
         _sendMseeageTb.Text = string.Empty;
     }
 }
Example #2
0
        //异步更新UDP数据所包含的内容
        private void updateRecvMsg(string temp)
        {
            string[] msg    = temp.Split('|');//0:userid 1:msg
            int      userid = int.Parse(msg[0]);


            //add to ChatContentCollection, but it is belong to people which he send to me.
            ChatContent f = new ChatContent()
            {
                ImgSource = @"Resource/someone.png",
                Content   = msg[1],
                IsSelf    = false
            };
            var vf = from b in chatContentCollectionList
                     where (b.ID == userid)
                     select b;

            vf.ElementAt(0).ChatContentCollection.Add(f);
            _sendLb.ScrollIntoView(f);
            //notify you to read message.
            var notifyUser = from b in remoteUserCollection
                             where (b.UserId == userid)
                             select b;

            notifyUser.ElementAt(0).NotifyColor = notifyColor;
        }