Exemple #1
0
 public bool ValidatePayload(EventPayload payload)
 {
     if (payload == null)
     {
         return(true);
     }
     return(CheckContentAs(payload.ContentType, payload.GetContent()));
 }
Exemple #2
0
        public void TriggerEvent(EventKey eventKey, EventPayload payload)
        {
            if (EventPayloadLibrary != null)
            {
                if (eventKey == EventKey.None)
                {
                    throw new ArgumentException("Cannot trigger a null event!");
                }

                if (!EventPayloadLibrary.ValidatePayload(payload))
                {
                    throw new ArgumentException("Invalid payload!");
                }
            }

            FlushListeners();
            TofuEvent evnt = GetEvent(eventKey);

            if (!_eventListeners.ContainsKey(evnt) || _eventListeners[evnt].Count == 0)
            {
                return;
            }
            _events.Get(evnt.Key).HasBeenCalled();

            List <IListener> listeners = new List <IListener>(_eventListeners[evnt]);

            foreach (IListener listener in listeners)
            {
                listener.ReceiveEvent(evnt, payload);
            }

            if (EventLogger != null)
            {
                if (payload == null)
                {
                    EventLogger.LogEvent(Time.time, eventKey, "NULL");
                }
                else
                {
                    EventLogger.LogEvent(Time.time, eventKey, payload.ContentType);
                }
            }
        }