private string formatAppMsg(string topic, XMessage msg) { var result = new StringBuilder(); var data = string.Empty; if (msg.MsgData != null) { data = msg.MsgData.ToString(); } result.Append($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")} >>> "); if (!string.IsNullOrWhiteSpace(msg.MsgTopic)) { result.Append($"[{msg.MsgTopic}]@"); } if (!string.IsNullOrWhiteSpace(msg.MsgMethod)) { result.Append($"[{msg.MsgMethod}]"); } if (!string.IsNullOrWhiteSpace(data)) { result.Append($" >>> \r\n{data}"); } result.AppendLine(string.Empty); return(result.ToString()); }
private void receiveeMsg(TopicCallback tc, XMessage msg) { if (!isSubscribed(tc.Topic, msg.MsgTopic)) { return; } if (!isSubscribed(tc.Method, msg.MsgMethod)) { return; } tc.Callback?.Invoke(tc.Topic, msg); }
private void receiveeMsg(XMessage msg) { foreach (var tc in this.topiccallbacks) { try { receiveeMsg(tc, msg); } catch (Exception ex) { } } }
public void Publish(XMessage msg) { try { if (msg == null) { msg = new XMessage(); } msg.MsgMethod = getMsgMethodName(msg.MsgMethod); if (string.IsNullOrWhiteSpace(msg.MsgTopic)) { msg.MsgTopic = msg.MsgMethod; } receiveeMsg(msg); } catch (Exception ex) { } }
private void receiveAppMsg(string topic, XMessage msg) { if (msg == null) { return; } if (this.InvokeRequired) { this.Invoke(new Action(() => { receiveAppMsg(topic, msg); })); return; } var msgdata = formatAppMsg(topic, msg); var sb = new StringBuilder(); sb.Append(this.tbMsg.Text).AppendLine(string.Empty); if (sb.Length > 1000 * 100) { sb.Remove(0, sb.Length - 1000); } sb.Append(msgdata).AppendLine(string.Empty); this.tbMsg.Text = sb.ToString(); this.tbMsg.SelectionStart = this.tbMsg.Text.Length; this.tbMsg.ScrollToCaret(); }