コード例 #1
0
ファイル: RequestHandler.cs プロジェクト: DenisNalivkin/TC
        /// <summary>
        /// The _ReadMeasuringSensorsJson method receives data from json.
        /// </summary>
        /// <param name="path">Specifies the path to the json file.</param>
        public void _ReadMeasuringSensorsJson(string path)
        {
            List <AbstractSensor> databaseLevelSensors = new SensorStorage().ReadMeasuringSensorsJson(path);

            foreach (var sensor in databaseLevelSensors)
            {
                AddSensorInListSensors(businessLevelSensors, sensor);
            }
        }
コード例 #2
0
        private void PurgeOldRecords(SensorStorage sensorStorage)
        {
            var now = DateTime.Now;

            if (now - sensorStorage.LastPurge > new TimeSpan(0, 15, 0))
            {
                var back24 = now - new TimeSpan(24, 0, 0);
                int purged = sensorStorage.RemoveAll(record => record.TimeStamp < back24);
                sensorStorage.LastPurge = now;
            }
        }
コード例 #3
0
        public bool Push(string sensor, IEnumerable <Reading> readings)
        {
            SensorStorage sensorStorage = GetSensorStorageByName(sensor);

            if (null == sensorStorage)
            {
                return(false);
            }
            sensorStorage.AddRange(readings);
            PurgeOldRecords(sensorStorage);
            return(true);
        }
コード例 #4
0
        public IEnumerable <Reading> GetReadings(string sensor, DateTime from, TimeSpan span)
        {
            SensorStorage sensorStorage = GetSensorStorageByName(sensor);

            if (null == sensorStorage)
            {
                return(Enumerable.Empty <Reading>());
            }
            DateTime to = from.Add(span);

            return(
                (to < from)
                                ? (
                    sensorStorage
                    .Where(ss => ss.TimeStamp >= to && ss.TimeStamp <= from)
                    .OrderByDescending(ss => ss.TimeStamp)
                    )
                                : (
                    sensorStorage
                    .Where(ss => ss.TimeStamp >= from && ss.TimeStamp <= to)
                    .OrderBy(ss => ss.TimeStamp)
                    )
                );
        }