Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        private async Task ExecuteGetWeatherCommand()
        {
            if (IsBusy)
            {
                return;
            }

            Microsoft.AppCenter.Analytics.Analytics.TrackEvent($"Get weather requested");

            if (string.IsNullOrWhiteSpace(Location))
            {
                throw new Exception("Location crash bug!");
            }

            IsBusy = true;
            try
            {
                WeatherRoot weatherRoot = null;
                var         units       = IsImperial ? Units.Imperial : Units.Metric;


                if (UseGPS)
                {
                    var hasPermission = await CheckPermissions();

                    if (!hasPermission)
                    {
                        return;
                    }

                    var gps = await CrossGeolocator.Current.GetPositionAsync(TimeSpan.FromSeconds(10));

                    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 = "Unable to get Weather";

                Microsoft.AppCenter.Crashes.Crashes.TrackError(ex,
                                                               new System.Collections.Generic.Dictionary <string, string>
                {
                    { "Location", Location.Trim() },
                    { "UseGPS", UseGPS.ToString() },
                    { "Issue", "Unable to get weather" }
                });
            }
            finally
            {
                IsBusy = false;
            }
        }