public void ShowWeather(WeatherSensor sensor)
        {
            string temparatureLine = string.Format("De temperatuur is {0} graden", sensor.Temperature);
            string humidityLine    = string.Format("De vochtigheid is {0}", sensor.Humidity);

            Console.WriteLine(temparatureLine);
            Console.WriteLine(humidityLine);
        }
        public void ShowWeather(WeatherSensor sensor)
        {
            string temparatureLine = string.Format("The temperature is {0} degrees", sensor.Temperature);
            string humdityLine     = string.Format("The humidity is {0}", sensor.Humidity);

            Console.WriteLine(temparatureLine);
            Console.WriteLine(humdityLine);
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            WeatherSensor sensor   = new WeatherSensor();
            IWeatherFan   dutchFan = new WeatherNewsChanelHolland();
            IWeatherFan   ukFan    = new WeatherChannelUK();

            sensor.AddFan(dutchFan);
            sensor.AddFan(ukFan);

            for (int counter = 0; counter < 10; counter++)
            {
                sensor.NewReading();
                Console.WriteLine();
                System.Threading.Thread.Sleep(3000);
            }



            Console.ReadKey();
        }
Exemplo n.º 4
0
        public void LoadWeatherData() //populate db
        {
            if (_context.WeatherSensors.Any())
            {
                return;
            }

            string file    = System.IO.File.ReadAllText(@"C:\IT-Högskolan\Databaser\Entity Framework\Inlämningsuppgift\WeatherDataConsole\EFDataAccessLibrary\Data\tempdata.csv");
            var    datas   = new List <WeatherData>();
            var    sensors = new List <WeatherSensor>();

            var records = file.Split('\n');

            foreach (var record in records)
            {
                var props = record.Split(',');
                if (!sensors.Any(s => s.Location == props[1]))
                {
                    //create sensor...
                    var sensor = new WeatherSensor {
                        Location = props[1]
                    };
                    _context.Add(sensor);
                    _context.SaveChanges();
                    sensors.Add(sensor);
                }

                var ws = sensors.Where(s => s.Location == props[1]).FirstOrDefault();

                var data = new WeatherData
                {
                    Collected_On    = DateTime.Parse(props[0]),
                    Temperature     = float.Parse(props[2], System.Globalization.CultureInfo.InvariantCulture),
                    Humidity        = byte.Parse(props[3]),
                    WeatherSensor   = ws,
                    WeatherSensorId = ws.Id
                };
                datas.Add(data);
            }
            _context.BulkInsert(datas);
        }