void initViewModels() { /// TemperatureViewModel setup var tvm = new TemperatureViewModel(); /// TODO 09 : Indiquer qu'il n'y a aucune clé si le Settings apiKey est vide. /// S'il y a une valeur, instancié OpenWeatherService avec la clé if (Properties.Settings.Default.apiKey == "") { MessageBox.Show("There is currently no api key."); } else { ows = new OpenWeatherService(Properties.Settings.Default.apiKey); } tvm.SetTemperatureService(ows); ViewModels.Add(tvm); /// TODO 01 : ConfigurationViewModel Add Configuration ViewModel var configvm = new ConfigurationViewModel(); ViewModels.Add(configvm); CurrentViewModel = ViewModels[0]; }
void initViewModels() { /// TemperatureViewModel setup var tvm = new TemperatureViewModel(); /// TODO 09 : Indiquer qu'il n'y a aucune clé si le Settings apiKey est vide. /// S'il y a une valeur, instancié OpenWeatherService avec la clé string apiKey = Properties.Settings.Default.apiKey; if (apiKey == null || apiKey == string.Empty) { tvm.RawText = "There is no api key, you should add one in the settings page."; } else { ows = new OpenWeatherService(apiKey); tvm.SetTemperatureService(ows); } ViewModels.Add(tvm); /// TODO 01 : ConfigurationViewModel Add Configuration ViewModel var cvm = new ConfigurationViewModel(); ViewModels.Add(cvm); CurrentViewModel = ViewModels[0]; }
void initViewModels() { /// TemperatureViewModel setup var tvm = new TemperatureViewModel(); ConfigurationViewModel configViewModel = new ConfigurationViewModel(); /// TODO 09 : Indiquer qu'il n'y a aucune clé si le Settings apiKey est vide. Fait /// S'il y a une valeur, instancié OpenWeatherService avec la clé Fait if (String.IsNullOrEmpty(Settings.Default.apiKey)) { MessageBox.Show("La clé API est obligatoire pour obtenir la météo"); } else { ows = new OpenWeatherService(Settings.Default.apiKey); } tvm.SetTemperatureService(ows); ViewModels.Add(tvm); ViewModels.Add(configViewModel); CurrentViewModel = ViewModels[0]; /// TODO 01 : ConfigurationViewModel Add Configuration ViewModel Fait CurrentViewModel = ViewModels[0]; }
void initViewModels() { /// TemperatureViewModel setup var tvm = new TemperatureViewModel(); var cvm = new ConfigurationViewModel(); if (Properties.Settings.Default.apiKey == null) { tvm.RawText = "You need an apiKey"; } else { ows = new OpenWeatherService(Properties.Settings.Default.apiKey); } /// TODO 09 : Indiquer qu'il n'y a aucune clé si le Settings apiKey est vide. /// S'il y a une valeur, instancié OpenWeatherService avec la clé tvm.SetTemperatureService(ows); ViewModels.Add(tvm); /// TODO 01 : ConfigurationViewModel Add Configuration ViewModel ViewModels.Add(cvm); CurrentViewModel = ViewModels[0]; }
void initViewModels() { /// TemperatureViewModel setup var tvm = new TemperatureViewModel(); /// TODO 09 : Indiquer qu'il n'y a aucune clé si le Settings apiKey est vide. /// S'il y a une valeur, instancié OpenWeatherService avec la clé if (Settings.Default.apiKey == "") { System.Windows.MessageBox.Show("Aucune clée API dans les setting"); } else { ows = new OpenWeatherService(Settings.Default.apiKey); } tvm.SetTemperatureService(ows); ViewModels.Add(tvm); /// TODO 01 : ConfigurationViewModel Add Configuration ViewModel ConfigurationViewModel configurationViewModel = new ConfigurationViewModel(); ViewModels.Add(configurationViewModel); CurrentViewModel = ViewModels[0]; }
public static async Task GetWeatherByCityCountry() { string cityName = "London"; string countryName = "uk"; OpenWeatherService ows = new OpenWeatherService(); dynamic res = await ows.GetWeather(cityName, countryName); }
void initViewModels() { /// TemperatureViewModel setup var tvm = new TemperatureViewModel(); /// TODO 09 : Indiquer qu'il n'y a aucune clé si le Settings apiKey est vide. /// S'il y a une valeur, instancié OpenWeatherService avec la clé if (string.IsNullOrEmpty(Properties.Settings.Default.apiKey)) { tvm.RawText = "Aucune clé API"; } else { ows = new OpenWeatherService(Properties.Settings.Default.apiKey); tvm.City = OpenWeatherProcessor.Instance.City; } tvm.SetTemperatureService(ows); ViewModels.Add(tvm); /// TODO 01 : ConfigurationViewModel Add Configuration ViewModel ViewModels.Add(new ConfigurationViewModel()); CurrentViewModel = ViewModels[0]; }
void initViewModels() { /// TemperatureViewModel setup var tvm = new TemperatureViewModel(); cvm = new ConfigurationViewModel(); /// TODO 09 (OK) Indiquer qu'il n'y a aucune clé si le Settings apiKey est vide. /// S'il y a une valeur, instancié OpenWeatherService avec la clé if (String.IsNullOrEmpty(Properties.Settings.Default.apiKey)) //cvm.ApiKey, Properties.Settings.Default.apiKey { tvm.RawText = "Mettre une cle API dans la fenetre de configuration"; ows = new OpenWeatherService(null); } else { ows = new OpenWeatherService(Properties.Settings.Default.apiKey); //ows.SetApiKey(Properties.Settings.Default.apiKey); } tvm.SetTemperatureService(ows); ViewModels.Add(tvm); /// TODO 01 (OK) ConfigurationViewModel Add Configuration ViewModel ViewModels.Add(cvm); CurrentViewModel = ViewModels[0]; }
private void ChangePage(string pageName) { /// TODO 10 : Si on a changé la clé, il faudra la mettre dans le service. /// /// Algo /// Si la vue actuelle est ConfigurationViewModel if (CurrentViewModel == ViewModels[1]) { /// Mettre la nouvelle clé dans le OpenWeatherService /// Si le service de temperature est null if (ows == null) { /// Assigner le service de température ows = new OpenWeatherService(Properties.Settings.Default.apiKey); // on ne peut pas assigné le service sans la clé //Properties.Settings.Default.Save(); //sert a rien } else { ows.SetApiKey(Properties.Settings.Default.apiKey); //si existant //Properties.Settings.Default.Save(); //sert a rien } /// Rechercher le TemperatureViewModel dans la liste des ViewModels //https://docs.microsoft.com/en-us/dotnet/api/system.linq.enumerable.firstordefault?view=net-5.0 } /// Permet de retrouver le ViewModel avec le nom indiqé CurrentViewModel = ViewModels.FirstOrDefault(x => x.Name == pageName); }
private void ChangePage(string pageName) { /// TODO 10 : Si on a changé la clé, il faudra la mettre dans le service. /// /// Algo /// Si la vue actuelle est ConfigurationViewModel /// Mettre la nouvelle clé dans le OpenWeatherService /// Rechercher le TemperatureViewModel dans la liste des ViewModels /// Si le service de temperature est null /// Assigner le service de température /// /// Permet de retrouver le ViewModel avec le nom indiqé // CurrentViewModel = ViewModels.FirstOrDefault(x => x.Name == pageName); if (CurrentViewModel.Name == "ConfigurationViewModel") { ows.SetApiKey(Properties.Settings.Default.apiKey); TemperatureViewModel t = (TemperatureViewModel)ViewModels.FirstOrDefault(x => x.Name == "TemperatureViewModel"); if (t.TemperatureService == null) { ITemperatureService itmps = new OpenWeatherService(AppConfiguration.GetValue("apikey")); t.SetTemperatureService(itmps); } } CurrentViewModel = ViewModels.FirstOrDefault(x => x.Name == pageName); }
void initViewModels() { /// TemperatureViewModel setup var tvm = new TemperatureViewModel(); ConfigurationViewModel cvm = new ConfigurationViewModel(); /// TODO 09 : Indiquer qu'il n'y a aucune clé si le Settings apiKey est vide. /// S'il y a une valeur, instancié OpenWeatherService avec la clé ows = new OpenWeatherService(Properties.Settings.Default.apiKey); if (String.IsNullOrEmpty(Properties.Settings.Default.apiKey)) { tvm.RawText = "entrez une clef api dans file et dans les préférences "; } else { tvm.RawText = ""; } tvm.SetTemperatureService(ows); ViewModels.Add(tvm); /// TODO 01 : ConfigurationViewModel Add Configuration ViewModel ViewModels.Add(cvm); CurrentViewModel = ViewModels[0]; }
void initViewModels() { /// TemperatureViewModel setup var tvm = new TemperatureViewModel(); /// TODO 09 : Indiquer qu'il n'y a aucune clé si le Settings apiKey est vide. /// S'il y a une valeur, instancié OpenWeatherService avec la clé // try // { if (string.IsNullOrEmpty(Properties.Settings.Default.apiKey)) { tvm.RawText = "Aucune clé API dans l'application, veuillez l'ajouter dans Fichier - > Préférences"; //avait mis messagebox avant... et j'ai relu... } else { ows = new OpenWeatherService(Properties.Settings.Default.apiKey); tvm.City = OpenWeatherProcessor.Instance.City; } tvm.SetTemperatureService(ows); ViewModels.Add(tvm); /// TODO 01 : ConfigurationViewModel Add Configuration ViewModel var cvm = new ConfigurationViewModel(); ViewModels.Add(cvm); CurrentViewModel = ViewModels[0]; }
private void ChangePage(string pageName) { /// TODO 10 : Si on a changé la clé, il faudra la mettre dans le service. /// /// Algo /// Si la vue actuelle est ConfigurationViewModel /// Mettre la nouvelle clé dans le OpenWeatherService /// Rechercher le TemperatureViewModel dans la liste des ViewModels /// Si le service de temperature est null /// Assigner le service de température /// if (CurrentViewModel == ViewModels.Find(x => x.Name == "ConfigurationViewModel")) { var tempCVM = CurrentViewModel as ConfigurationViewModel; var tempTVM = (ViewModels.Find(x => x.Name == "TemperatureViewModel")) as TemperatureViewModel; if (ows == null) { ows = new OpenWeatherService(Settings.Default.apiKey); } ows.SetApiKey(Settings.Default.apiKey); if (tempTVM.TemperatureService == null) { tempTVM.SetTemperatureService(ows); } } /// Permet de retrouver le ViewModel avec le nom indiqé CurrentViewModel = ViewModels.FirstOrDefault(x => x.Name == pageName); }
public async Task LoadCurrentWeatherAsync() { IsLoading = true; Status = 0; CurrentWeather = null; //get coordinate double lat = 0, lon = 0; string[] temp = Coord.Split('|'); lat = double.Parse(temp[0]); lon = double.Parse(temp[1]); //http call if (Status == 0) { if (IsInternetAvailable()) { try { CurrentWeather = await OpenWeatherService.GetWeatherByCoordinateAsync(lat, lon); } catch { Status = 1; } } else { Status = 1; } } IsLoading = false; }
public async Task OpenWeatherServiceTest() { var openWeatherService = new OpenWeatherService(); await openWeatherService.HttpRequestData("Rotterdam"); var currentWeather = openWeatherService.GetData(); Assert.IsNotNull(currentWeather); }
void initViewModels() { /// TemperatureViewModel setup var tvm = new TemperatureViewModel(); /// TODO 09 : Indiquer qu'il n'y a aucune clé si le Settings apiKey est vide. /// S'il y a une valeur, instancié OpenWeatherService avec la clé var apiKey = AppConfiguration.GetValue("OWApiKey"); if (String.IsNullOrEmpty(Settings.Default.apiKey)) { tvm.RawText = "apiKey vide!!!"; } else { ows = new OpenWeatherService(Settings.Default.apiKey); } tvm.SetTemperatureService(ows); ViewModels.Add(tvm); /// TODO 01 : ConfigurationViewModel Add Configuration ViewModel var cvm = new ConfigurationViewModel(); ViewModels.Add(cvm); CurrentViewModel = ViewModels[0]; }
private void ChangePage(string pageName) { /// TODO 10 : Si on a changé la clé, il faudra la mettre dans le service. /// /// Algo /// Si la vue actuelle est ConfigurationViewModel /// Mettre la nouvelle clé dans le OpenWeatherService /// Rechercher le TemperatureViewModel dans la liste des ViewModels /// Si le service de temperature est null /// Assigner le service de température /// if (CurrentViewModel.Name == "ConfigurationViewModel") { string key = Properties.Settings.Default.apiKey; if (!(key == null || key == string.Empty)) { ows = new OpenWeatherService(key); foreach (var x in ViewModels) { if (x.Name == "TemperatureViewModel") { TemperatureViewModel tvm = (TemperatureViewModel)x; if (tvm.TemperatureService == null) { tvm.SetTemperatureService(ows); } } } } } /// Permet de retrouver le ViewModel avec le nom indiqé CurrentViewModel = ViewModels.FirstOrDefault(x => x.Name == pageName); }
public async void SearchLocation() { if (IsInternetAvailable()) { try { IsLoading = true; if (!string.IsNullOrEmpty(QueryString)) { QueryWeather = new List <OpenWeatherObj>() { await OpenWeatherService.GetWeatherByCityNameAsync(QueryString) }; } } catch (COMException) { Status = 2; } catch (Exception) { Status = 3; } finally { IsLoading = false; } } else { Status = 3; } }
void initViewModels() { /// TemperatureViewModel setup tvm = new TemperatureViewModel(); string apiKey = ""; if (Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT") == "DEVELOPMENT") { apiKey = AppConfiguration.GetValue("OWApiKey"); } if (string.IsNullOrEmpty(Properties.Settings.Default.apiKey) && apiKey == "") { tvm.RawText = "Aucune clé API, veuillez la configurer"; } else { if (apiKey == "") { apiKey = Properties.Settings.Default.apiKey; } ows = new OpenWeatherService(apiKey); } tvm.SetTemperatureService(ows); ViewModels.Add(tvm); var cvm = new ConfigurationViewModel(); ViewModels.Add(cvm); }
private async Task <Tuple <WeatherApiResonseData, OneCallWeatherAPIResponseData> > SearchLocation(string searchInput) { WeatherApiResonseData weather = new WeatherApiResonseData(); OneCallWeatherAPIResponseData weatherDetails = new OneCallWeatherAPIResponseData(); if (searchInput.Any(char.IsDigit)) { try { weather = await OpenWeatherService.GetCurrentWeatherByZipCodeAsync(searchInput); weatherDetails = await OpenWeatherService.GetOneCallAPIRequestAsync(weather.coord.lat, weather.coord.lon); } catch (Exception ex) { Debug.Write(ex.Message); weather = await OpenWeatherService.GetCurrentWeatherByCityNameAsync(searchInput); weatherDetails = await OpenWeatherService.GetOneCallAPIRequestAsync(weather.coord.lat, weather.coord.lon); } } else { weather = await OpenWeatherService.GetCurrentWeatherByCityNameAsync(searchInput); weatherDetails = await OpenWeatherService.GetOneCallAPIRequestAsync(weather.coord.lat, weather.coord.lon); } return(Tuple.Create(weather, weatherDetails)); }
public static async System.Threading.Tasks.Task <IActionResult> Run([HttpTrigger] HttpRequest req, ILogger log) { log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}"); var firebaseService = new FirebaseService(); var appCenterService = new AppCenterService(new HttpClient()); var openWeatherService = new OpenWeatherService(new HttpClient()); var notificacoes = await firebaseService.ObterNotificacoes(); foreach (var notificacao in notificacoes) { var cidade = await openWeatherService.ObterClimaTempo(notificacao.Cidade); if (notificacao.DeveNotificarTemperaturaMinima(cidade.Principal.TemperaturaMinima)) { await appCenterService.AdicionarNotificacao( new[] { notificacao.IdDispositivo }, "ClimaTempo", "A temperatura caiu!", $"Cidade de {notificacao.Cidade} com temperatura atual de {cidade.Principal.TemperaturaMinima}°."); } if (notificacao.DeveNotificarVentoVelocidadeMinima(Convert.ToDouble(cidade.Vento.Velocidade))) { await appCenterService.AdicionarNotificacao( new[] { notificacao.IdDispositivo }, "ClimaTempo", "A velocidade do vendo caiu!", $"Cidade de {notificacao.Cidade} com velocidade atual do vendo em {cidade.Vento.Velocidade}."); } } return(new OkObjectResult("OK")); }
static async Task Main(string[] args) { try { ConfigHelper.InitializeConfig(); var weatherService = new OpenWeatherService(); var historyService = new HistoryLocationService(); var history = historyService.GetSavedLocations(); Console.WriteLine("Please enter the name of a city and iso country code separated by a comma, example : Perth, AU"); DisplayHistory(history); var input = Console.ReadLine().Trim(); string city; string country; ValidateInput(input, history, out city, out country); var currentWeather = await weatherService.GetCurrentWeather(city.Trim(' '), country?.Trim(' ').ToUpper()); Console.WriteLine(currentWeather); while (currentWeather.Contains("We couldn't find")) { Console.WriteLine("Please enter another city name or a number from the list."); input = Console.ReadLine(); ValidateInput(input, history, out city, out country); currentWeather = await weatherService.GetCurrentWeather(city.Trim(' '), country?.Trim(' ').ToUpper()); } Console.WriteLine(currentWeather); Console.ReadLine(); } catch (Exception ex) { logger.Error(ex); } }
public WeatherDataController( DarkSkyWeatherService darkSkyWeatherService, OpenWeatherService openWeatherService) { DarkSkyWeatherService = darkSkyWeatherService; OpenWeatherService = openWeatherService; }
public OpenWeatherServiceTestsVersion2() { _server = WireMockServer.Start(); var client = new OpenWeatherClient(_server.Urls.First(), "any string"); _sut = new OpenWeatherService(client); }
private void ConfigureWeatherService() { var openWeatherService = OpenWeatherService.CreateService(); Kernel.Bind <IWeatherService>() .ToConstant(openWeatherService) .InSingletonScope(); }
public async Task Get_Weather_With_Incorrect_City_Name_Should_Throw_HTTP_Request_Exception() { //arrange var weatherService = new OpenWeatherService(new ApiClientMock(), new MappingService()); var wrongData = TestDataValues.INCORRECT_CITY_NAME; //assert await Assert.ThrowsAsync <HttpRequestException>(async() => await weatherService.GetWeather(wrongData)); }
public async Task GetCurrentWeatherByCityName_Test() { // prepare SI WeatherConditions output = null; using (var stream = new BufferedStream(File.OpenRead("./Resources/OpenW_currentweather_SI.json"), 8192)) { var mockHttp = new MockHttpMessageHandler(); mockHttp .When(OpenWeatherService.EndPointRoot + "*") .Respond("application/json", stream); IOpenWeatherService client = new OpenWeatherService("12345", mockHttp); output = await client.GetCurrentWeather(BolognaLatitude, BolognaLongitude, OWUnit.Metric, Language.Italian); stream.Close(); } // assert output.ShouldNotBeNull(); output.City.ShouldNotBeNull(); output.City.Coordinates.Latitude.ShouldBe(44.4667); output.City.Coordinates.Longitude.ShouldBe(11.4333); output.WeatherInfo[0].Summary.ShouldBe("Clouds"); output.WeatherInfo[0].Description.ShouldBe("nubi sparse"); output.WeatherInfo[0].Icon.ShouldBe("03d"); output.City.Name.ShouldNotBeNullOrWhiteSpace(); output.City.Name.ShouldBe(BolognaCityName, StringCompareShould.IgnoreCase); output.City.CountryCode.ShouldBe("IT"); output.City.SunriseTime.ToUnixTimeSeconds().ShouldBe(1610174975); // prepare imperial WeatherConditions outputImperial = null; using (var stream = new BufferedStream(File.OpenRead("./Resources/OpenW_currentweather_Imperial.json"), 8192)) { var mockHttp = new MockHttpMessageHandler(); mockHttp .When(OpenWeatherService.EndPointRoot + "*") .Respond("application/json", stream); IOpenWeatherService client = new OpenWeatherService("12345", mockHttp); outputImperial = await client.GetCurrentWeather(BolognaCityName, OWUnit.Imperial, Language.English); stream.Close(); } // assert output.ShouldNotBeNull(); output.City.ShouldNotBeNull(); outputImperial.City.Name.ShouldBe(output.City.Name); outputImperial.City.CountryCode.ShouldBe(output.City.CountryCode); outputImperial.City.Coordinates.Latitude.ShouldBe(output.City.Coordinates.Latitude); outputImperial.City.Coordinates.Longitude.ShouldBe(output.City.Coordinates.Longitude); outputImperial.Wind.Speed.ShouldNotBe(output.Wind.Speed); outputImperial.Temperature.Daily.ShouldNotBeNull(); outputImperial.Temperature.Daily.Value.ShouldBeGreaterThan(output.Temperature.Daily.Value); outputImperial.ApparentTemperature.Daily.ShouldNotBeNull(); outputImperial.ApparentTemperature.Daily.Value.ShouldBeGreaterThan(output.ApparentTemperature.Daily.Value); }
static async Task Main(string[] args) { var client = new OpenWeatherClient("https://wiremock.azurewebsites.net", "xxx"); var service = new OpenWeatherService(client); var result = await service.GetInfoAsync("Sittard, NL"); Console.WriteLine($"{result.DegreesCelsius:##.##} celsius ({result.Description})"); }
public void BuildUrlDefaultUrlProviderDuringConstruction() { var urlBuilder = CreateFluentUrlProvider(); var serviceUnderTest = new OpenWeatherService(new Mock <IClient>().Object, urlBuilder.Object); urlBuilder.Verify(builder => builder.SetLanguage(It.IsAny <QueryLanguage>()), Times.Once()); urlBuilder.Verify(builder => builder.SetMode(It.IsAny <QueryMode>()), Times.Once()); urlBuilder.Verify(builder => builder.SetUnit(It.IsAny <QueryUnit>()), Times.Once()); }
public async Task MakeForecastRequestAsync() //INetworkService service { var userLocation = await GetUserLocationAsync(); var forecastManager = new OpenWeatherService(_network, userLocation.CountryCode); Forecast = await forecastManager.GetForecastAsync(userLocation.Latitude, userLocation.Longtitude); EventManager.Instance.PostNotification(EVENT_TYPE.WEATHER_UPDATED, this); }
public ApplicationViewModel() { ChangePageCommand = new DelegateCommand <string>(ChangePage); /// TODO 11 : Commenter cette ligne lorsque la configuration utilisateur fonctionne // var apiKey = AppConfiguration.GetValue("OWApiKey"); ows = new OpenWeatherService(Properties.Settings.Default.apiKey); initViewModels(); }
public async void showWeather() { var openWeatherService = new OpenWeatherService(); await openWeatherService.HttpRequestData("Rotterdam"); var currentWeather = openWeatherService.GetData(); var temperature = currentWeather.temp; }
/// <summary> /// Gets the current weather /// </summary> /// <param name="userLocation">The location of the user</param> /// <returns>Weather details in a OpenWeatherModel</returns> public static async Task<OpenWeatherModel> GetCurrentWeather(string userLocation) { var openWeatherService = new OpenWeatherService(); await openWeatherService.HttpRequestData(userLocation); return openWeatherService.GetData(); }