void TrackGetWeatherEvent() { var eventDictionaryHockeyApp = new Dictionary <string, string> { { "Use GPS Enabled", UseGPS.ToString() } }; try { if (!Temp.Contains(_errorMessage)) { var locationCityName = UseGPS ? Condition?.Substring(0, Condition.IndexOf(":", StringComparison.Ordinal)) : Location; eventDictionaryHockeyApp.Add("Location", locationCityName); } } catch (Exception ex) { HockeyappHelpers.Report(ex); } finally { HockeyappHelpers.TrackEvent("Weather Button Tapped", eventDictionaryHockeyApp, null); } }
private async Task ExecuteGetWeatherCommand() { if (IsBusy) { return; } IsBusy = true; try { WeatherRoot weatherRoot = null; var units = IsImperial ? Units.Imperial : Units.Metric; if (UseGPS) { var gps = await CrossGeolocator.Current.GetPositionAsync(10000); weatherRoot = await WeatherService.GetWeather(gps.Latitude, gps.Longitude, units); } else { //Get weather by city weatherRoot = await WeatherService.GetWeather(Location.Trim(), units); } //Get forecast based on cityId Forecast = await WeatherService.GetForecast(weatherRoot.CityId, units); var unit = IsImperial ? "F" : "C"; Temp = $"Temp: {weatherRoot?.MainWeather?.Temperature ?? 0}°{unit}"; Condition = $"{weatherRoot?.Name}: {weatherRoot?.Weather?[0]?.Description ?? string.Empty}"; CrossTextToSpeech.Current.Speak(Temp + " " + Condition); } catch (Exception ex) { Temp = _errorMessage; HockeyappHelpers.Report(ex); } finally { IsBusy = false; TrackGetWeatherEvent(); } }
public async Task <WeatherRoot> GetWeather(string city, Units units = Units.Imperial) { try { var arguments = new Dictionary <string, string> { { ("city"), ($"{city}") } }; var res = await MobileService.InvokeApiAsync <WeatherRoot>("getWeather/city", HttpMethod.Get, arguments); return(res); } catch (Exception e) { HockeyappHelpers.Report(e); return(null); } }
public async Task <WeatherRoot> GetWeather(double latitude, double longitude, Units units = Units.Imperial) { try { var arguments = new Dictionary <string, string> { { ("latitude"), ($"{latitude}") }, { ("longitude"), ($"{longitude}") } }; var res = await MobileService.InvokeApiAsync <WeatherRoot>("getWeather/location", HttpMethod.Get, arguments); return(res); } catch (Exception e) { HockeyappHelpers.Report(e); return(null); } }
static async Task <T> GetDataObjectFromAPI <T>(string apiUrl) { try { using (var stream = await _client.GetStreamAsync(apiUrl).ConfigureAwait(false)) using (var reader = new StreamReader(stream)) using (var json = new JsonTextReader(reader)) { if (json == null) { return(default(T)); } return(await Task.Run(() => _serializer.Deserialize <T>(json))); } } catch (Exception e) { HockeyappHelpers.Report(e); return(default(T)); } }
static async Task <T> GetDataObjectFromAPI <T>(string apiUrl) { return(await Task.Run(async() => { try { var json = await Client.GetStringAsync(apiUrl); if (string.IsNullOrWhiteSpace(json)) { return default(T); } return DeserializeObject <T>(json); } catch (Exception e) { HockeyappHelpers.Report(e); return default(T); } })); }
public async Task <WeatherForecastRoot> GetForecast(int id, Units units = Units.Imperial) { return(await Task.Run(async() => { try { var arguments = new Dictionary <string, string> { { ("id"), ($"{id}") }, { ("numDays"), ("16") } }; var res = await MobileService.InvokeApiAsync <WeatherForecastRoot>("getWeather/forecast", HttpMethod.Get, arguments); return res; } catch (Exception e) { HockeyappHelpers.Report(e); return null; } })); }