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 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); }
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); }
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); }
public void AddRow(DeviceMessage row) { this.rowList.Add(row); }
public string GetMessageToPublish(DeviceMessage deviceMessage) { return(deviceMessage.ToString()); }