private void GetNewForecast(string stodvaNr)
        {
            Forecast textaInfo = ForecastService.GetForecast(stodvaNr);

            forecastTextBox.Text = textaInfo.Content;

            DateTime parsed;

            if (DateTime.TryParse(textaInfo.Creation, out parsed))
            {
                parsed = DateTime.Parse(textaInfo.Creation);
                DateTime now  = DateTime.Now;
                TimeSpan span = now.Subtract(parsed);
                if (span.Hours > 0)
                {
                    forecastInfoBox.Text = $"Spá skrifuð fyrir {span.Hours} klst";
                }
                else
                {
                    forecastInfoBox.Text = $"Spá skrifuð fyrir {span.Minutes} min";
                }
            }
            else
            {
                forecastInfoBox.Text = $"Reynið aftur síðar";
            }
            var validTo   = textaInfo.Valid_to;
            var validFrom = textaInfo.Valid_from;
        }
示例#2
0
        public void TestFacebookService()
        {
            var forecast      = ForecastService.GetForecast();
            var sunriseSunset = SunriseSunsetService.GetSunriseSunset();
            var report        = ReportBuilder.Build(forecast, sunriseSunset);

            FacebookService.PostText(report);
        }
示例#3
0
        public void GetForecastTest()
        {
            ForecastService forecastService = new ForecastService();
            string          location        = "Stuttgart";
            ForecastModel   forecastModel   = new ForecastModel();

            forecastModel = forecastService.GetForecast(location);
            Assert.NotNull(forecastModel);
        }
示例#4
0
        public static void Run([TimerTrigger("0 0 4 * * *")] TimerInfo myTimer, TraceWriter log)
        {
            log.Info($"Timer trigger function executed at: {DateTime.Now}");

            var forecast      = ForecastService.GetForecast();
            var sunriseSunset = SunriseSunsetService.GetSunriseSunset();
            var report        = ReportBuilder.Build(forecast, sunriseSunset);

            FacebookService.PostText(report);
        }
        public void GetForecastTest()
        {
            // TODO: IRL I would use mocking to bypass the communication to the server on the unit tests, and use integrations tests to validate the end to end, but due to the time limitations I will skip mocking in this code
            var service = new ForecastService();
            var result  = service.GetForecast(LondonId).Result;

            Assert.IsNotNull(result, "result != null");
            Assert.IsNotNull(result.ForecastDay1, "result != null");
            Assert.IsNotNull(result.ForecastDay2, "result.ForecastDay2 != null");
            Assert.IsNotNull(result.ForecastDay3, "result.ForecastDay3 != null");
            Assert.IsNotNull(result.ForecastDay4, "result.ForecastDay4 != null");
            Assert.IsNotNull(result.ForecastDay5, "result.ForecastDay5 != null");
            // Avoiding strong typing every single validation, reflection is a nifty tool to use in cirurgical spots
            Assert.DoesNotThrow(() => ReadAllProperties(result, result.ForecastDay1, result.ForecastDay2, result.ForecastDay3, result.ForecastDay4, result.ForecastDay5));
        }
示例#6
0
 public void TestReportBuilder()
 {
     var result = ReportBuilder.Build(ForecastService.GetForecast(), SunriseSunsetService.GetSunriseSunset());
 }
        /// <summary>
        /// Diese Funktion schreibt alle Wetterdaten in die Properties für die Oberfläche.
        /// Task läuft asynchron
        /// </summary>
        private async void  ShowWeather()
        {
            //CurrentWeather
            CurrentWeatherModel model = new CurrentWeatherModel();

            //Await und LambdaExpression triggert den Service für das jetzige Wetter
            model = await Task.Run(() => currentWeatherService.GetCurrentWeather(Location));

            MainViewModel.city_name = model.name;

            //Modelle werden ausgelesen
            Temperature   = model.main.temp + " C°";
            Description   = "Description: " + model.weather[0].description;
            TempFeelsLike = "Feels Like: " + model.main.feels_like + "C°";
            TempMin       = "Min Temperature: " + model.main.temp_min + "C°";
            TempMax       = "Max Temperature: " + model.main.temp_max + "C°";
            WindSpeed     = "Wind Speed: " + model.wind.speed + "m/s";
            City          = model.name;
            Sunrise       = "sunrise: " + calcuteConverter.UnixTimeStampConverter(model.sys.sunrise);
            Sunset        = "sunset: " + calcuteConverter.UnixTimeStampConverter(model.sys.sunset);
            WeatherIcon   = iconPick.pickIcon(model.weather[0].icon);

            //WeatherForecast
            ForecastModel modelForecast = new ForecastModel();

            //Await und LambdaExpression triggert den Service für den Forecast
            modelForecast = await Task.Run(() => forecastService.GetForecast(Location));

            //Modelle werden ausgelesen
            DateTime thisDay = DateTime.Now;
            string   date    = thisDay.GetDateTimeFormats('D')[0];

            Day1         = "Heute";
            Icon1        = iconPick.pickIcon(modelForecast.list[4].weather[0].icon);
            Description1 = modelForecast.list[4].weather[0].description;
            Degree1      = Convert.ToString(modelForecast.list[4].main.temp_min) + "C°";
            TempMax1     = Convert.ToString(modelForecast.list[4].main.temp_max) + "C°";

            string date2 = thisDay.AddDays(1).GetDateTimeFormats('D')[0];

            Day2         = date2.Split(',')[0];
            Icon2        = iconPick.pickIcon(modelForecast.list[12].weather[0].icon);
            Description2 = modelForecast.list[12].weather[0].description;
            Degree2      = Convert.ToString(modelForecast.list[12].main.temp_min) + "C°";
            TempMax2     = Convert.ToString(modelForecast.list[12].main.temp_max) + "C°";


            string date3 = thisDay.AddDays(2).GetDateTimeFormats('D')[0];

            Day3         = date3.Split(',')[0];
            Icon3        = iconPick.pickIcon(modelForecast.list[20].weather[0].icon);
            Description3 = modelForecast.list[20].weather[0].description;
            Degree3      = Convert.ToString(modelForecast.list[20].main.temp_min) + "C°";
            TempMax3     = Convert.ToString(modelForecast.list[20].main.temp_max) + "C°";


            string date4 = thisDay.AddDays(3).GetDateTimeFormats('D')[0];

            Day4         = date4.Split(',')[0];
            Icon4        = iconPick.pickIcon(modelForecast.list[28].weather[0].icon);
            Description4 = modelForecast.list[28].weather[0].description;
            Degree4      = Convert.ToString(modelForecast.list[28].main.temp_min) + "C°";
            TempMax4     = Convert.ToString(modelForecast.list[28].main.temp_max) + "C°";

            string date5 = thisDay.AddDays(4).GetDateTimeFormats('D')[0];

            Day5         = date5.Split(',')[0];
            Icon5        = iconPick.pickIcon(modelForecast.list[36].weather[0].icon);
            Description5 = modelForecast.list[36].weather[0].description;
            Degree5      = Convert.ToString(modelForecast.list[36].main.temp_min) + "C°";
            TempMax5     = Convert.ToString(modelForecast.list[36].main.temp_max) + "C°";
        }