private Task Ack(string receive) { return(Task.Run(() => { // ack消息 43 _absolutePath packetid ["result","result"...] string message = receive.Substring((((int)Protocol.Message).ToString() + ((int)Protocol.Pong).ToString() + _AbsolutePath).Length); Regex regex = new Regex($@"^(\d+)\[({{[\s\S]*}})\]$"); if (regex.IsMatch(message)) { var groups = regex.Match(message).Groups; int packetId = int.Parse(groups[1].Value); object[] results = JsonConvert.DeserializeObject <object[]> ($"[{groups[2].Value}]"); string result = JsonConvert.SerializeObject(results[0]); if (result.StartsWith("\"")) { result = JsonConvert.DeserializeObject <string> (result); } _EventTarget.Emit(packetId, result); _EventTarget.Off(packetId); } }, _TokenSource.Token)); }
public void Off(string eventName, GeneralEventHandler callback) { _EventTarget.Off(eventName, callback); }