/// <summary>
        /// Asynchronously receives the currently authenticated athlete.
        /// </summary>
        /// <returns>The currently authenticated athlete.</returns>
        public async Task <Athlete> GetAthleteAsync()
        {
            _perflog.GetAthleteAsync(false);
            if (Athlete == null)
            {
                try
                {
                    string json = await LocalCacheService.ReadCacheData("Athlete");

                    if (json == null || json.Length < 10)
                    {
                        var accessToken = await _settingsService.GetStoredStravaAccessTokenAsync();

                        string getUrl = $"{Endpoints.Athlete}?access_token={accessToken}";
                        json = await _stravaWebClient.GetAsync(new Uri(getUrl));

                        LocalCacheService.PersistCacheData(json, "Athlete");
                    }
                    return(Athlete = Unmarshaller <Athlete> .Unmarshal(json));
                }
                catch (Exception)
                {
                    //TODO: Glenn - Use logger to log errors ( Google )
                }
            }
            _perflog.GetAthleteAsync(true);
            return(Athlete);
        }
Beispiel #2
0
        /// <summary>
        /// Asynchronously receives the currently authenticated athlete.
        /// </summary>
        /// <returns>The currently authenticated athlete.</returns>
        public async Task <Athlete> GetAthleteAsync()
        {
            _perflog.GetAthleteAsync(false);
            if (Athlete == null)
            {
                try
                {
                    string json = await LocalCacheService.ReadCacheData("Athlete");

                    if (json == null || json.Length < 10)
                    {
                        var accessToken = await _settingsService.GetStoredStravaAccessTokenAsync();

                        string getUrl = $"{Endpoints.Athlete}?access_token={accessToken}";
                        json = await _stravaWebClient.GetAsync(new Uri(getUrl));

                        LocalCacheService.PersistCacheData(json, "Athlete");
                    }

                    Athlete = Unmarshaller <Athlete> .Unmarshal(json);

                    string athleteUri = $"{Endpoints.PublicAthlete}/{Athlete.Id}";
                    _logService.Log("API", "GetAthleteAsync", athleteUri);

                    return(Athlete);
                }
                catch (Exception ex)
                {
                    string title = "StravaAthleteService.GetAthleteAsync";
                    _logService.LogException(title, ex);
                }
            }
            _perflog.GetAthleteAsync(true);
            return(Athlete);
        }
        /// <summary>
        /// Asynchronously receives the currently authenticated athlete.
        /// </summary>
        /// <returns>The currently authenticated athlete.</returns>
        public async Task <Athlete> GetAthleteAsync()
        {
            _perflog.GetAthleteAsync(false);
            if (Athlete == null)
            {
                try
                {
                    string json = await LocalCacheService.ReadCacheData("Athlete");

                    if (json == null || json.Length < 10)
                    {
                        var accessToken = await _settingsService.GetStoredStravaAccessTokenAsync();

                        string getUrl = $"{Endpoints.Athlete}?access_token={accessToken}";
                        json = await _stravaWebClient.GetAsync(new Uri(getUrl));

                        LocalCacheService.PersistCacheData(json, "Athlete");
                    }

                    Athlete = Unmarshaller <Athlete> .Unmarshal(json);

#if !DEBUG
                    ServiceLocator.Current.GetInstance <IGoogleAnalyticsService>().Tracker.SendEvent("API", "GetAthleteAsync", Athlete.FullName, 0);
#endif
                    return(Athlete);
                }
                catch (Exception ex)
                {
#if !DEBUG
                    _errorMessage.Clear();
                    _errorMessage.AppendLine($"StravaAthleteService.GetAthleteAsync");
                    _errorMessage.AppendLine(ex.Message);
                    ServiceLocator.Current.GetInstance <IGoogleAnalyticsService>().Tracker.SendException(_errorMessage.ToString(), false);
#endif
                }
            }
            _perflog.GetAthleteAsync(true);
            return(Athlete);
        }