Example #1
0
        /// <summary>
        /// Invokes a SendMessag event that contains the event serialzed into a message that can be sent to other apps automatically
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="eventToPublish"></param>
        private void PublishCrossAppEvent <T>(T eventToPublish) where T : ICrossAppEvent
        {
            var request = new EventBusRequest {
                EventClassName      = eventToPublish.GetType().AssemblyQualifiedName,
                SerializedEventData = JsonConvert.SerializeObject(eventToPublish)
            };

            SendMessage?.Invoke(request);
        }
Example #2
0
        /// <summary>
        /// Receive a message via TCP- this is an event raised by another app
        /// </summary>
        /// <param name="eventBusRequest">The event body of the request</param>
        public void ReceiveMessage(EventBusRequest eventBusRequest)
        {
            try {
                var type = Type.GetType(eventBusRequest.EventClassName);
                if (type == null)
                {
                    return;
                }

                if (!_subscriptionList.ContainsKey(type))
                {
                    return;
                }

                var eventToPublish = (type.GetConstructors().FirstOrDefault() == null)
                    ? Activator.CreateInstance(type) as ICrossAppEvent
                    : Activator.CreateInstance(type, GetParameterListFromJsonData(type, eventBusRequest.SerializedEventData)) as ICrossAppEvent;

                InvokeCallbacks(type, _subscriptionList[type], eventToPublish);
            } catch {
                //todo: we need to inject the logger here, but that means also supporting this in the streamdeck plugin
            }
        }