public static DeviceMessage DeserializeEvents(string deviceId, JArray events, ServiceContext serviceContext, IServiceEventSource serviceEventSource)
        {
            DeviceMessage messageRet = null;
            bool          firstEvent = true;

            foreach (JObject evt in events)
            {
                String eventType = GetEventTypeFromEvent(evt);

                if (eventType.Equals(Names.EVENT_TYPE_DEFAULT))
                {
                    serviceEventSource.ServiceMessage(serviceContext, $"Event Registry - Could not find event configuration for event type [{eventType}] - Will parse the event as Default Type");
                }

                EventConfiguration eventConfiguration = EventRegistry.GetEventConfiguration(eventType);

                DeviceEvent deviceEvent = DeserializeEvent(eventConfiguration, evt);

                if (firstEvent)
                {
                    messageRet = new DeviceMessage(eventConfiguration.MessageType, deviceId, deviceEvent);
                    firstEvent = false;
                }
                else
                {
                    messageRet.AddEvent(deviceEvent);
                }
            }

            return(messageRet);
        }
        public static EventConfiguration GetEventConfiguration(string eventType)
        {
            EventConfiguration eventConfigurationRet = defaultEventConfiguration;

            if (IsEventTypeAlreadyRegistered(eventType))
            {
                eventTypesBag.TryGetValue(eventType, out eventConfigurationRet);
            }

            return(eventConfigurationRet);
        }
        private static DeviceEvent DeserializeEvent(EventConfiguration eventConfiguration, JObject jsonObj)
        {
            DeviceEvent deviceEventRet = (DeviceEvent)jsonObj.ToObject(eventConfiguration.EventObectType);

            if (deviceEventRet == null)
            {
                deviceEventRet = new DeviceEventDefault(eventConfiguration.EventType, jsonObj);
            }

            return(deviceEventRet);
        }
        public static bool RegisterEventType(string eventType, EventConfiguration eventConfiguration)
        {
            bool bRet = false;

            if (!IsEventTypeAlreadyRegistered(eventType))
            {
                eventTypesBag.TryAdd(eventType, eventConfiguration);
                bRet = true;
            }

            return(bRet);
        }
        public static List <string> GetEventTypeListForMessageType(string messageType)
        {
            List <string> listRet = new List <string>();

            foreach (var item in eventTypesBag)
            {
                EventConfiguration eventConfiguration = item.Value;

                if (eventConfiguration.Equals(messageType))
                {
                    listRet.Add(item.Key);
                }
            }

            return(listRet);
        }