public Task ProcessEventsAsync(PartitionContext context, IEnumerable <EventData> messages) { var messagesFromDevice = new List <Device2CloudMessage>(); foreach (var eventData in messages) { var data = Encoding.ASCII.GetString(eventData.Body.Array, eventData.Body.Offset, eventData.Body.Count); Device2CloudMessage devMessage = JsonConvert.DeserializeObject <Device2CloudMessage>(data); messagesFromDevice.Add(devMessage); } var lastMessage = messagesFromDevice.LastOrDefault(x => x.CheckIsMessageValid(TimeSpan.FromMinutes(3))); MessageFromDevice.Invoke(lastMessage ?? new Device2CloudMessage("", DeviceState.NotSet, new MediaPlayerState(String.Empty, 0))); return(context.CheckpointAsync()); }
public IUIVisibilityStrategy CreateStrategy(Device2CloudMessage message) { switch (message.DeviceState) { case DeviceState.DeviceReady: return(new DeviceReadyStrategy()); case DeviceState.Paused: return(new DevicePausedStrategy()); case DeviceState.Playing: return(new DevicePlayingStrategy()); case DeviceState.NotSet: case DeviceState.TurnedOff: return(new DeviceTurnedoffStrategy()); default: throw new NotImplementedException($"Strategy not implemented: {message.DeviceState.ToString()}"); } }