コード例 #1
0
        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);
        }
コード例 #2
0
        public static JArray SerializeEvents(string deviceId, DeviceMessage deviceMessage, ServiceContext serviceContext, IServiceEventSource serviceEventSource)
        {
            JArray jarrRet = new JArray();

            foreach (DeviceEvent deviceEvent in deviceMessage.Events)
            {
                JObject jsonObj = SerializeEvent(deviceEvent);

                jarrRet.Add(jsonObj);
            }

            return(jarrRet);
        }
コード例 #3
0
        public static DeviceMessage DeserializeEvents(string deviceId, string arrayEventStr, ServiceContext serviceContext, IServiceEventSource serviceEventSource)
        {
            DeviceMessage deviceMessageRet = null;

            try
            {
                JArray jarr = JArray.Parse(arrayEventStr);

                deviceMessageRet = DeserializeEvents(deviceId, jarr, serviceContext, serviceEventSource);
            }
            catch (Exception ex)
            {
                serviceEventSource.ServiceMessage(serviceContext, $"Event Registry - Could not parse device id[{deviceId}] message [{arrayEventStr}] Error Message [{ex.Message}]");
            }

            return(deviceMessageRet);
        }
コード例 #4
0
        public DeviceMessage ManageDeviceEventSeriesContent(DeviceMessage currentSeries, DeviceMessage newSeries, out DeviceMessage completedMessage)
        {
            bool resetCurrent = true;

            if (resetCurrent)
            {
                completedMessage = new DeviceMessage(currentSeries.MessageType, currentSeries.DeviceId, currentSeries.Events);
                currentSeries    = newSeries;
            }
            else
            {
                completedMessage = null;
                currentSeries.AddEvent(newSeries.Events.First());
            }

            return(currentSeries);
        }
コード例 #5
0
 public void AddRow(DeviceMessage row)
 {
     this.rowList.Add(row);
 }
コード例 #6
0
 public string GetMessageToPublish(DeviceMessage deviceMessage)
 {
     return(deviceMessage.ToString());
 }