Example #1
0
        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);
            }
        }
Example #2
0
        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);
                }
            }
        }
Example #3
0
 public EventData(DateTime recordingStartTime, JsonApiEvent jsonEvent)
     : this(DateTime.Now, recordingStartTime, jsonEvent)
 {
 }
Example #4
0
 public EventData(DateTime time, DateTime recordingStartTime, JsonApiEvent jsonEvent)
 {
     this.Time = time;
     this.RecordingStartTime = recordingStartTime;
     this.JsonEvent          = jsonEvent;
 }
Example #5
0
 internal MessageReceivedEventArgs(JsonApiEvent @event, string raw, bool hasSubscribers)
 {
     this.HasSubscribers = hasSubscribers;
     this.Event          = @event;
     this.RawData        = raw;
 }