Пример #1
0
        /// <summary>
        /// reads readings from sensor
        /// </summary>
        /// <param name="number"></param>
        /// <returns></returns>
        public bool ReadSensorData(int number)
        {
            var O =
                JsonStringToObject<SensorRead>.Convert(
                    HttpGetAction.Get($"http://userportal.iha.dk/~jrt/i4dab/E14/HandIn4/dataGDL/data/{number}.json"));

            using (var context = new Handin4DatabaseContext())
            {
                foreach (var a in O.reading.Where(a => context.AppartmentcharacteristicSet.Any(t => t.appartmentId == a.appartmentId) &&
                                                       context.SensorcharacteristicSet.Any(t => t.SensorID == a.SensorID)))
                {
                    context.ReadingSet.Add(a);
                }
                context.SaveChanges();
            }

            return true;
        }
Пример #2
0
        /// <summary>
        /// reads all sensor and appartment info and saves them in db
        /// </summary>
        public void ReadData()
        {
            var O =
                JsonStringToObject<SensorNApartmentRead>.Convert(
                    HttpGetAction.Get("http://userportal.iha.dk/~jrt/i4dab/E14/HandIn4/GFKSC002_original.txt"));

            using (var context = new Handin4DatabaseContext())
            {
                foreach (var a in O.appartmentCharacteristic)
                {
                    context.AppartmentcharacteristicSet.Add(a);
                }
                foreach (var s in O.sensorCharacteristic)
                {
                    context.SensorcharacteristicSet.Add(s);
                }
                context.SaveChanges();
            }
        }