Пример #1
0
        public void ImportObservations()
        {
            var fileName = @"D:\Development\Observations.csv";

            using (StreamReader reader = new StreamReader(File.OpenRead(fileName)))
            {
                using (VaderContext ctx = new VaderContext())
                {
                    while (!reader.EndOfStream)
                    {
                        var line = reader.ReadLine();
                        var parts = line.Split(';');

                        var deviceId = int.Parse(parts[1].Replace("\"", string.Empty));
                        var datetime = DateTime.Parse(parts[2].Replace("\"", string.Empty));
                        var temperature = decimal.Parse(parts[3].Replace("\"", string.Empty).Replace(".", ","));

                        var observation = new Observations
                        {
                            DeviceId = deviceId,
                            ObservationTime = datetime,
                            TemperatureInCelsius = temperature
                        };

                        ctx.Observations.Add(observation);
                        ctx.SaveChanges();
                    }
                }
            }
        }
Пример #2
0
 public ClientStructure (Observations observation)
 {
     DeviceId = observation.DeviceId;
     ObservationId = observation.ObservationId;
     ObservationTime = HighChartsDateTimeHelper.GetUnixTime(observation.ObservationTime.ToLocalTime());
     ObservationDateTime = observation.ObservationTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss");
     ObservationTimeString = observation.ObservationTime.ToLocalTime().ToString("HH:mm:ss");
     TemperatureInCelsius = observation.TemperatureInCelsius.Value;
 }
Пример #3
0
        public static void AddTemperatureObservation(int deviceId, decimal temperature)
        {
            using (VaderContext ctx = new VaderContext())
            {
                var observation = new Observations()
                {
                    DeviceId = deviceId,
                    ObservationTime = DateTime.UtcNow,
                    TemperatureInCelsius = temperature
                };

                ctx.Observations.Add(observation);
                ctx.SaveChanges();
            }
        }