Exemple #1
0
 static public void StoreSensor(Sensor sensor, Device device)
 {
     using (var context = new SensorDataContext())
     {
         var _sensorEntity = new SensorEntity();
         _sensorEntity.DeviceName   = device.Name;
         _sensorEntity.LastSyncTime = DateTime.Now;
         _sensorEntity.Value        = sensor.State;
         _sensorEntity.ModuleName   = sensor.Name;
         context.SensorData.Add(_sensorEntity);
         context.SaveChanges();
     }
 }
Exemple #2
0
        static public List <Tuple <DateTime, long> > GetSensorLog(Sensor sensor, Device device, DateTime start, DateTime finish)
        {
            var ret = new List <Tuple <DateTime, long> >();

            using (var context = new SensorDataContext())
            {
                var _res = context.SensorData.Where(d => (d.DeviceName == device.Name && d.ModuleName == sensor.Name &&
                                                          d.LastSyncTime > start && d.LastSyncTime < finish)).ToList <SensorEntity>();
                foreach (var entry in _res)
                {
                    var bufEntry = new Tuple <DateTime, long>(entry.LastSyncTime, entry.Value);
                    ret.Add(bufEntry);
                }
                ret.Sort();
            }
            return(ret);
        }