Example #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();
                    }
                }
            }
        }
Example #2
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();
            }
        }