public void Init() { this.TitleLabel.Content = this.To; if (SignalRProxy == null) { SignalRProxy = new SignalRProxy(); } SignalRProxy.ConnectAsync(); //注册SignalR客户端方法 if (SignalRProxy.ReceviceFialureMessage == null) { SignalRProxy.ReceviceFialureMessage = (message) => { this.Dispatcher.Invoke(() => { MessageBox.Show(message); }); }; } if (SignalRProxy.ReceviceMessage == null) { SignalRProxy.ReceviceMessage = (username, message) => { this.Dispatcher.Invoke(() => { LeftMessageBoxUControl leftMessageBoxUControl = new LeftMessageBoxUControl(); leftMessageBoxUControl.Init(username, message); this.MessageStackPanel.Children.Add(leftMessageBoxUControl); }); }; } if (SignalRProxy.ReceviceRecord == null) { SignalRProxy.ReceviceRecord = (username, record) => { this.Dispatcher.Invoke(() => { if (username.Equals(To)) { LeftMessageBoxUControl leftMessageBoxUControl = new LeftMessageBoxUControl(); leftMessageBoxUControl.Init(To, record); this.MessageStackPanel.Children.Add(leftMessageBoxUControl); } else { RightMessageBoxUControl rightMessageBoxUControl = new RightMessageBoxUControl(); rightMessageBoxUControl.Init(Self, record); this.MessageStackPanel.Children.Add(rightMessageBoxUControl); } }); }; } }
public void Init(String userName, String group, SignalRProxy signalrProxy) { if (signalrProxy != null) { this.SignalRProxy = signalrProxy; } this.Group = group; this.UserName = userName; if (SignalRProxy.ReceviceNotice == null) { SignalRProxy.ReceviceNotice = (username, notice) => { this.Dispatcher.Invoke(() => { //bool isExistence = false; //foreach (var node in NoticeStackPanel.Children) //{ // if ((node as PLeftMessageBoxUControl).Id == notice.Id) // { // var item = node as PLeftMessageBoxUControl; // item.UpdateListBox(notice.Comments); // isExistence = true; // break; // } //} //if (!isExistence) //{ // if (notice.KeyWord == Expander_Range.Header.ToString()) // { // PLeftMessageBoxUControl pLeftMessage = new PLeftMessageBoxUControl(); // pLeftMessage.Init(notice.Belongs, notice.Comments, notice.DateTime, // notice.From, notice.Id, notice.Message); // pLeftMessage.Comment = (id) => // { // this.CommentId = id; // this.input.ToolTip = "评论"; // this.InputNoticeTBox.Text = userName + ":"; // }; // NoticeStackPanel.Children.Add(pLeftMessage); // } //} SaveMessage(notice, userName); }); }; } SignalRProxy.ConnectAsync(); }
public void Init(String userName, String group, SignalRProxy signalrProxy) { if (signalrProxy != null) { this.SignalRProxy = signalrProxy; } this.Group = group; this.UserName = userName; if (SignalRProxy.ReceviceNotice == null) { SignalRProxy.ReceviceNotice = (username, notice) => { this.Dispatcher.Invoke(() => { bool isExistence = false; foreach (var node in NoticeStackPanel.Children) { if ((node as PLeftMessageBoxUControl).Id == notice.Id) { var item = node as PLeftMessageBoxUControl; item.UpdateListBox(notice.Comments); isExistence = true; break; } } if (!isExistence) { PLeftMessageBoxUControl pLeftMessage = new PLeftMessageBoxUControl(); pLeftMessage.Init(notice.Belongs, notice.Comments, notice.DateTime, notice.From, notice.Id, notice.Message); pLeftMessage.Comment = (id) => { this.CommentId = id; this.input.ToolTip = "评论"; this.InputNoticeTBox.Text = userName + ":"; }; NoticeStackPanel.Children.Add(pLeftMessage); } }); }; } SignalRProxy.ConnectAsync(); }