private void btnChatAddOne_Click(object sender, RoutedEventArgs e) { PerMsg pt1 = new PerMsg("test", "ceshi"); PerMsg pt2 = new PerMsg("test", "ceshi"); PerMsg pt3 = new PerMsg("test", "ceshi"); MsgList mt1 = new MsgList(); mt1.Add(pt1); mt1.Add(pt2); mt1.Add(pt3); //model.AllChatWaitReads += 1; //chats.Add(new Chat { SenderId = "8888", sName = "test", ReceiverId = "1111", Content = "测试测试测试测试测试测试", Msgs = mt1 }); chats.Add(new Chat("8888", "test", "1111", "测试测试测试测试测试测试", mt1, 0)); }
private void SendMsg(string msg) { TuLingClient.SendMsg(msg, (result) => { MsgList.Add(CreateMsg("我:", msg)); MsgList.Add(CreateMsg("图灵机器人:", result.SelectToken("text") + "")); Console.WriteLine(result.SelectToken("code")); }); }
public MainWindow() { PerMsg p1 = new PerMsg("wang", "ceshi"); PerMsg p2 = new PerMsg("wang", "ceshi"); PerMsg p3 = new PerMsg("wang", "ceshi"); MsgList m1 = new MsgList(); m1.Add(p1); m1.Add(p2); m1.Add(p3); PerMsg p4 = new PerMsg("ming", "ceshi"); PerMsg p5 = new PerMsg("ming", "ceshi"); PerMsg p6 = new PerMsg("ming", "ceshi"); MsgList m2 = new MsgList(); m2.Add(p4); m2.Add(p5); m2.Add(p6); PerMsg p7 = new PerMsg("gao", "ceshi"); PerMsg p8 = new PerMsg("gao", "ceshi"); PerMsg p9 = new PerMsg("gao", "ceshi"); MsgList m3 = new MsgList(); m3.Add(p7); m3.Add(p8); m3.Add(p9); friends = new FriendList { new Friend { UserId = "1234", UserName = "******", IP = "192.168.1.1", status = Status.Online }, new Friend { UserId = "2345", UserName = "******", IP = "192,168.1.2", status = Status.Online }, new Friend { UserId = "3456", UserName = "******", IP = "192.168.1.3", status = Status.Offline } }; chats = new ChatList { //new Chat{SenderId = "1234", sName="wang", ReceiverId = "1111", Content = "测试测试测试测试测试测试", Msgs = m1, WaitReads = 3}, //new Chat{SenderId = "2345", sName="ming", ReceiverId = "1111", Content = "测试测试测试测试测试", Msgs = m2,WaitReads = 3}, //new Chat{SenderId = "3456", sName="gao", ReceiverId = "1111", Content= "测试测试测试测试", Msgs = m3,WaitReads = 3} new Chat("1234", "wang", "1111", "测试测试测试测试测试测试", m1, 0), new Chat("2345", "ming", "1111", "测试测试测试测试测试", m2, 0), new Chat("3456", "gao", "1111", "测试测试测试测试", m3, 0), }; notices = new NoticeList { new Notice { UserId = "5678" }, new Notice { UserId = "4567" } }; model = new ChatViewModel { AllChatWaitReads = 0, AllFriendWaitReads = 0, AllNoticeWaitReads = 0 }; InitializeComponent(); this.tabMain.DataContext = model; this.gChat.DataContext = chats; this.gFriend.DataContext = friends; this.gNotice.DataContext = notices; this.listChat.AddHandler(UIElement.MouseDownEvent, new MouseButtonEventHandler(listChat_MouseLeftButtonDown), true); this.listChat.AddHandler(UIElement.MouseDownEvent, new MouseButtonEventHandler(listChat_MouseRightButtonDown), true); }
protected void AddUser(SecurityTCP.Client client, UIUser user) { UserList.Add(client, user); BigMsgList.Add(client, new Queue <byte[]>()); MsgList.Add(client, new Queue <Message>()); }
public void AddMsg(PerMsg msg) { Msgs.Add(msg); }
public ClientWindow(TCPHelper helper, List <User> users, List <TalkContract> talks, List <AddFriend> addFriends, string id, string name) { this.UserName = name; model = new ClientViewModel(); friends = new FriendList(); chats = new ChatList(); notices = new NoticeList(); model.AllNoticeWaitReads = 0; model.AllFriendWaitReads = 0; model.AllChatWaitReads = 0; #region 数据到视图模型的转换 foreach (var u in users) { friends.Add(new Friend { UserId = u.UserId, UserName = u.UserName, IP = u.ip, status = u.IsOnline }); } var senders = talks.Select(p => p.SenderId).ToList().Distinct(); foreach (var s in senders) { MsgList m = new MsgList(); var records = talks.Where(p => p.SenderId.Equals(s)).Select(q => q).ToList(); foreach (var r in records) { m.Add(new PerMsg { SenderName = talks.Where(p => p.SenderId.Equals(r.SenderId)).Select(q => q.SenderName).FirstOrDefault(), Msg = r.Content }); } chats.Add(new Chat { SenderId = s, SenderName = talks.Where(p => p.SenderId.Equals(s)).Select(p => p.SenderName).FirstOrDefault(), ReceiverId = talks.Where(x => x.SenderId.Equals(s)).Select(y => y.ReceiverId).FirstOrDefault(), Msgs = m, WaitReadNum = m.Count }); } foreach (var n in addFriends) { notices.Add(new Notice { UserId = n.UserId, UserName = "******", status = Status.Waiting }); } foreach (var c in chats) { model.AllChatWaitReads += c.WaitReadNum; } model.AllNoticeWaitReads = notices.Count(); #endregion this.LocalId = id; InitializeComponent(); this.Closing += ClientWindow_Closing; CC.DataHandle.UpdateFriendHandler += DataHandle_UpdateFriendHandler; CC.DataHandle.SearchHandler += SearchCallBack; CC.DataHandle.AddComfirmHandler += AddComfimCallback; CC.DataHandle.RemoveFriendHandler += DataHandle_RemoveFriendHandler; CC.DataHandle.GetMsgHandler += GetMsgHandler; WindowStartupLocation = WindowStartupLocation.CenterScreen; this.lblID.Content = LocalId; this.helper = helper; //绑定关联数据 this.tabMain.DataContext = model; this.gChat.DataContext = chats; this.gFriend.DataContext = friends; this.gNotice.DataContext = notices; this.listChat.AddHandler(UIElement.MouseDownEvent, new MouseButtonEventHandler(listChat_MouseLeftButtonDown), true); this.listChat.AddHandler(UIElement.MouseDownEvent, new MouseButtonEventHandler(listChat_MouseRightButtonDown), true); this.listNotice.AddHandler(UIElement.MouseDownEvent, new MouseButtonEventHandler(listNotice_MouseLeftButtonDown), true); }