public static Message ParseMessage(string message) { Message returnMessage; try { JObject o = JObject.Parse(message); var type = (string)o["Type"]; if (type.Equals("Control")) { returnMessage = new ControlMessage(o); } else if (type.Equals("Start")) { returnMessage = new StartMessage(o); } else if (type.Equals("Stop")) { returnMessage = new StopMessage(o); } else if (type.Equals("Blink")) { returnMessage = new BlinkMessage(o); } else { returnMessage = new Message(null); } } catch (Exception e) { returnMessage = new Message(null); } return returnMessage; }
public async Task ControlLightsAsync(ControlMessage controlMsg) { foreach (var consumer in Consumers) { if (consumer.Value != null) { await SetValuesAsync(consumer.Value, controlMsg.LampValue); } } _lastValues = controlMsg.LampValue; }