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