private void Socket_MessageReceived(string message) { if (DumpToDebug) { Debug.WriteLine(message); } if (IsPlaying) { return; } var ev = JsonApiEvent.Parse(message); if (!ev.Equals(default(JsonApiEvent))) { bool subscribed = Subscribers.ToArray().Any(o => o.Key.IsMatch(ev.URI)); var args = new MessageReceivedEventArgs(ev, message, subscribed); MessageReceived?.Invoke(this, args); if (args.Handled) { return; } HandleEvent(ev); } }
public void HandleEvent(JsonApiEvent @event) { foreach (var item in Subscribers.ToArray().Where(o => o.Key.IsMatch(@event.URI))) { if (item.Value.ModelType == typeof(JsonApiEvent)) { item.Value.Callback.DynamicInvoke(@event); } else { object data; try { data = @event.GetData(item.Value.ModelType); } catch (InvalidCastException) { //TODO Do something? continue; } item.Value.Callback.DynamicInvoke(@event.EventType, data); } } }
public EventData(DateTime recordingStartTime, JsonApiEvent jsonEvent) : this(DateTime.Now, recordingStartTime, jsonEvent) { }
public EventData(DateTime time, DateTime recordingStartTime, JsonApiEvent jsonEvent) { this.Time = time; this.RecordingStartTime = recordingStartTime; this.JsonEvent = jsonEvent; }
internal MessageReceivedEventArgs(JsonApiEvent @event, string raw, bool hasSubscribers) { this.HasSubscribers = hasSubscribers; this.Event = @event; this.RawData = raw; }