/// <summary>
        /// args[0] represent OpenWeatherMapApiClientUri. Ex: https://api.openweathermap.org/data/2.5/
        /// args[1] represent OpenWeatherMapApiClientAppId Ex: 63d35ff6068c3103ccd1227526935675
        /// args[2] represent OpenWeatherDataPersistenceClientFilePath Ex: C://Users/Agallardol/Documents/database.db
        /// </summary>
        /// <param name="args"></param>
        protected override void OnStart(string[] args)
        {
            openWeatherMapBaseAddress = args[0];
            openWeatherMapAppId       = args[1];
            openWeatherDataPersistenceClientFilePath = args[2];

            currentWeatherService            = new CurrentWeatherService(openWeatherMapBaseAddress, openWeatherMapAppId);
            openWeatherDataPersistenceClient = new OpenWeatherDataStoreClient(openWeatherDataPersistenceClientFilePath);

            EventLog.WriteEntry($"Service started\nOpenWeatherMapAddress: {openWeatherMapBaseAddress}\nOpenWeatherMapAppId: {openWeatherMapAppId}", EventLogEntryType.Information);

            GeoCoordinate currentGeoCoordinate = locationService.GetCurrentGeoCoordinate().Result;

            EventLog.WriteEntry($"GeoCoordinate\n Latitude: {currentGeoCoordinate.Latitude}\n Longitude: {currentGeoCoordinate.Longitude}", EventLogEntryType.Information);


            WeatherData weatherData = currentWeatherService.GetCurrentWeather(currentGeoCoordinate.Latitude, currentGeoCoordinate.Longitude).Result;

            EventLog.WriteEntry($"Weather data\n Country: {weatherData.Sys.Country}\n Location: {weatherData.Name}\n Temp: {weatherData.Main.Temp}", EventLogEntryType.Information);

            openWeatherDataPersistenceClient.AddWeatherData(new WeatherDataModel()
            {
                Latitude  = currentGeoCoordinate.Latitude,
                Longitude = currentGeoCoordinate.Longitude,
                Temp      = weatherData.Main.Temp.Value,
                Location  = weatherData.Name,
                Country   = weatherData.Sys.Country
            });
        }
Exemplo n.º 2
0
        public void TestCityNotFoundException()
        {
            CurrentWeatherService currentWeatherService = new CurrentWeatherService();
            string location = "ojfwbwovbwqobi";
            CurrentWeatherModel currentWeatherModel = new CurrentWeatherModel();

            Assert.Throws <ArgumentException>(() => (currentWeatherService.GetCurrentWeather(location)));
        }
Exemplo n.º 3
0
        public void GetCurrentWeatherTest()
        {
            CurrentWeatherService currentWeatherService = new CurrentWeatherService();
            string location = "Stuttgart";
            CurrentWeatherModel currentWeatherModel = new CurrentWeatherModel();

            currentWeatherModel = currentWeatherService.GetCurrentWeather(location);
            Assert.NotNull(currentWeatherModel);
        }
        /// <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°";
        }