Beispiel #1
0
        public void Save(string sensorCode, string dataText, decimal?dataNumeric, DateTime sampleDt)
        {
            //Spremi podatke u bazu prema senzoru, prikupljenoj vrijednosti i vremenu prikupljanja
            try
            {
                var dc = new HMonitorData(HMonitorScheduler.Properties.Settings.Default.HMonitorDataConnection);

                var firstSensor = dc.Sensors.Single(s => s.Code == sensorCode);
                //Console.WriteLine("Save weather - Sensor name: " + firstSensor.Name);

                if (firstSensor != null)
                {
                    var sensorId          = firstSensor.SensorId;
                    var sensorHistoryData = new SensorHistoryData()
                    {
                        SensorId    = sensorId,
                        DataNumeric = dataNumeric,
                        DataText    = dataText,
                        SampledDT   = sampleDt,
                        InsertedDT  = DateTime.Now
                    };
                    dc.Add(sensorHistoryData);
                    dc.SaveChanges();
                }
                else
                {
                    Console.WriteLine(String.Format("You are trying to insert data for unregistered sensor ({0})", sensorCode));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw;
            }
        }
Beispiel #2
0
        public void SaveCurrentWeather(string sensorCode, string dataText, decimal?dataNumeric, DateTime sampleDt)
        {
            //Spremi podatke u bazu prema senzoru, prikupljenoj vrijednosti i vremenu prikupljanja
            try
            {
                #region Deprecated: Snimanje podataka kroz Disposable klasu
                //Console.WriteLine(HMonitorScheduler.Properties.Settings.Default.HMonitorDataConnection);
                //using (var dc = new HMonitorData(HMonitorScheduler.Properties.Settings.Default.HMonitorDataConnection))
                //{
                //    var first = dc.Sensors.First(s => s.Code == sensorCode);
                //    Console.WriteLine("Save weather - Sensor name: " + first.Name);
                //    if (first != null)
                //    {
                //        var sensorId = first.SensorId;
                //        Console.WriteLine("Save weather - Sensor Id:" + Convert.ToString(sensorId));
                //        var sensorHistoryData = new SensorHistoryData()
                //        {
                //            SensorId = sensorId,
                //            DataNumeric = dataNumeric,
                //            DataText = dataText,
                //            SampledDT = sampleDt,
                //            InsertedDT = DateTime.Now
                //        };
                //        dc.Add(sensorHistoryData);
                //        dc.SaveChanges();
                //    }
                //    else
                //    {
                //        //TODO: Obavijestiti da ne postoji sensorCode
                //    }
                //}
                #endregion

                var dc = new HMonitorData(HMonitorScheduler.Properties.Settings.Default.HMonitorDataConnection);

                var firstSensor = dc.Sensors.Single(s => s.Code == sensorCode);
                //Console.WriteLine("Save weather - Sensor name: " + firstSensor.Name);

                if (firstSensor != null)
                {
                    var sensorId          = firstSensor.SensorId;
                    var sensorHistoryData = new SensorHistoryData()
                    {
                        SensorId    = sensorId,
                        DataNumeric = dataNumeric,
                        DataText    = dataText,
                        SampledDT   = sampleDt,
                        InsertedDT  = DateTime.Now
                    };
                    dc.Add(sensorHistoryData);
                    dc.SaveChanges();
                }
                else
                {
                    Console.WriteLine(String.Format("You are trying to insert data for unregistered sensor ({0})", sensorCode));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw;
            }
        }