protected override void TimerCallback(object state) { var _state = (State)state; ReadTemperatureCommand command = new ReadTemperatureCommand(); foreach (var device in _state.DeviceQuery.GetAll()) { command.DeviceID = device.ID; _state.CommandBus.Execute(command); // Console.WriteLine($"Node {node.ID} Temp {node.Temperature}"); } }
public void Handle(ReadTemperatureCommand command) { using (var client = new HttpClient()) { try { var device = this.deviceQuery.Get(command.DeviceID); var response = client.GetAsync(device.NodeAddress + "/Temperature").Result; if (response.IsSuccessStatusCode) { device.Temperature = JsonConvert.DeserializeAnonymousType(response.Content.ReadAsStringAsync().Result, new { temperature = 23.45f }).temperature; deviceRepository.UpdateTemperature(device.ID, device.Temperature); temperatureRepository.Add(device.ID, (float)device.Temperature, DateTime.Now); eventServer.SendToAll(EventTypes.TemperatureUpdated, new { Name = device.Name, Temperature = device.Temperature }); } } catch (Exception e) { eventServer.SendToAll(EventTypes.Error, new { message = e.Message }); } } }