예제 #1
0
        public void Handle(UpdateDeviceCommand command)
        {
            var device = new Device()
            {
                Appliance = command.Appliance, ID = command.ID, Name = command.Name, NodeAddress = command.NodeAddress
            };

            repository.Update(device);
            eventServer.SendToAll(EventTypes.DeviceUpdated, device);
        }
예제 #2
0
 public void Handle(AddScheduleCommand command)
 {
     if (command.Mon || command.Tue || command.Wed || command.Thu || command.Fri || command.Sat || command.Sun)
     {
         Schedule schedule = this.repository.Add(command.Mon, command.Tue, command.Wed, command.Thu, command.Fri,
                                                 command.Sat, command.Sun, command.DeviceID, command.Time, command.Temperature, command.Fan,
                                                 command.Mode);
         eventServer.SendToAll(EventTypes.ScheduleCreated, this.scheduleFactory.Create(schedule));
     }
     else
     {
         //Bad Request
     }
 }
 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 });
         }
     }
 }