public void FireTimeOutHandler(CometCoreClient client, CometMessage cm) { if (TimeoutHandler != null) { TimeoutHandler(client, new CometClientEventArgs(cm)); } }
public void FireFailureHandler(CometCoreClient client, CometMessage cm) { if (FailureHandler != null) { FailureHandler(client, new CometClientEventArgs(cm)); } }
// 调用事件处理函数 public void FireSuccessHandler(CometCoreClient client, CometMessage cm) { if (SuccessHandler != null) { SuccessHandler(client, new CometClientEventArgs(cm)); } }
// Winform 客户端订阅到成功消息时候的自身处理函数( 这里还要解决跨线程访问的问题) public void SuccessHandler(object sender, CometClientEventArgs args) { CometMessage mess = args.Message; CometCoreClient client = (CometCoreClient)sender; client.LastMessageId = mess.MessageId; // 解析动态JSon Object对象,dynamic 关键字的用法: 指示编译器不要解析和检查,封装操作信心用于运行时计算 //frm.richTextBox1.Text = mess.Tip + "\t" + ((dynamic)(Newtonsoft.Json.Linq.JObject)mess.Content).from.Value + // "\t" + ((dynamic)(Newtonsoft.Json.Linq.JObject)mess.Content).message.Value; //frm.richTextBox1.Text = mess.Tip + JsonConvert.SerializeObject(mess.Content); Action <string> asyncUiDelegate = delegate(string data) { this.richTextBox1.Text += data + "\n"; }; this.Invoke(asyncUiDelegate, new object[] { JsonConvert.SerializeObject(mess) }); // 这个this 是窗体控件,这里的意义是调用窗体的同步委托来 操作窗体UI }
public CometClientEventArgs(CometMessage message) { this.Message = message; }