Example #1
0
        public void LogTemperatureService(string name, double currentTemperature, double?targetTemperature, DateTime logDate)
        {
            using (var _context = _provider.getContext())
            {
                int RoomID  = _context.Rooms.Where(room => room.Name == name).First().ID;
                var tempLog = new TemperatureLog()
                {
                    CurrentTemp = currentTemperature,
                    LogDate     = logDate,
                    RoomID      = RoomID,
                    TargetTemp  = targetTemperature ?? 0
                };

                _context.Add(tempLog);
                _context.SaveChanges();
                _logger.LogTrace($"Stored into DB: {currentTemperature}° for {name} at {logDate}");
            }
        }
Example #2
0
        private void Received(ProbeTemperatureMessage message)
        {
            try
            {
                using (var dbContext = _provider.getContext())
                {
                    var address = message.ProbeAddress.Replace("/", string.Empty);
                    var room    = dbContext.Rooms.Include(tl => tl.TemperatureSchedules).ThenInclude(t => t.Schedule).ThenInclude(schedule => schedule.Periods).Where(c => c.Captor.Address == address).First();

                    if (room == null)
                    {
                        _logger.LogDebug($"No room found for address '{address}'");
                        return;
                    }

                    if (room.HeatRegulation)
                    {
                        room.ComputeTemperature(new DateTime());
                        _logger.LogInformation($"Computed temperature : {room.TargetTemperature}° /Current Temperature {message.TemperatureValue}° for {room.Name} at {message.MessageDate}");
                    }

                    var tempLog = new TemperatureLog()
                    {
                        CurrentTemp = message.TemperatureValue,
                        LogDate     = message.MessageDate,
                        RoomID      = room.ID,
                        TargetTemp  = room.TargetTemperature ?? 0
                    };

                    dbContext.Add(tempLog);
                    dbContext.SaveChanges();

                    _notificationHub.Clients.All.SendAsync("TemperatureReceived", room.ID, message.TemperatureValue, room.TargetTemperature, message.MessageDate);

                    _logger.LogTrace($"Stored into DB: {message.TemperatureValue}° for {room.Name} at {message.MessageDate}");
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"{ex.ToString()}: {ex.Message}");
            }
        }
Example #3
0
 public DataRead(IDatabaseConnection databaseConnection, IDBContextProvider provider)
 {
     _databaseConnection = databaseConnection;
     _provider           = provider;
     _context            = provider.getContext();
 }