Пример #1
0
        /// <summary>
        /// Gets a user's anime list.
        /// </summary>
        /// <param name="user"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <MalUserLookupResults> GetAnimeListForUserAsync(string user, CancellationToken cancellationToken)
        {
            Logging.Log.InfoFormat("Checking cache for user {0}.", user);

            if (m_cache.GetListForUser(user, out MalUserLookupResults cachedAnimeList))
            {
                if (cachedAnimeList != null)
                {
                    Logging.Log.InfoFormat("Got anime list for {0} from cache.", user);
                    return(cachedAnimeList);
                }
                else
                {
                    // User does not have an anime list/no such user exists
                    Logging.Log.InfoFormat("Cache indicates that user {0} does not have an anime list.", user);
                    throw new MalUserNotFoundException(string.Format("No MAL list exists for {0}.", user));
                }
            }
            else
            {
                Logging.Log.InfoFormat("Cache did not contain anime list for {0}.", user);

                try
                {
                    MalUserLookupResults animeList = await m_underlyingApi.GetAnimeListForUserAsync(user, cancellationToken)
                                                     .ConfigureAwait(continueOnCapturedContext: false);

                    m_cache.PutListForUser(user, animeList);
                    return(animeList);
                }
                catch (MalUserNotFoundException)
                {
                    // Cache the fact that the user does not have an anime list
                    m_cache.PutListForUser(user, null);
                    throw;
                }
            }
        }
Пример #2
0
        private async Task <MalUserLookupResults> GetUserLookupAsync(AnimeRecsInputJson input, IMyAnimeListApiFactory malApiFactory)
        {
            using (IMyAnimeListApi malApi = malApiFactory.GetMalApi())
            {
                _logger.LogInformation("Getting MAL list for user {0}.", input.MalName);
                MalUserLookupResults userLookup;
                try
                {
                    userLookup = await malApi.GetAnimeListForUserAsync(input.MalName).ConfigureAwait(false);

                    _logger.LogInformation("Got MAL list for user {0}.", input.MalName);
                    return(userLookup);
                }
                catch (MalUserNotFoundException)
                {
                    _logger.LogInformation("User {0} not found.", input.MalName);
                    AjaxError  error  = new AjaxError(AjaxError.NoSuchMALUser, "No such MAL user.");
                    JsonResult result = Json(error);
                    result.StatusCode = 404;
                    throw new ShortCircuitException(result);
                }
            }
        }
Пример #3
0
 public Task <MalUserLookupResults> GetAnimeListForUserAsync(string user, CancellationToken cancellationToken)
 {
     return(DoActionWithRetryAsync(() => m_underlyingApi.GetAnimeListForUserAsync(user, cancellationToken),
                                   baseErrorMessage: string.Format("Error getting anime list for user {0}", user)));
 }
Пример #4
0
 public Task <MalUserLookupResults> GetAnimeListForUserAsync(string user, CancellationToken cancellationToken)
 {
     return(DoActionWithRateLimitingAsync(() => m_underlyingApi.GetAnimeListForUserAsync(user, cancellationToken), cancellationToken));
 }
 public Task <MalUserLookupResults> GetAnimeListForUserAsync(string user)
 {
     return(_underlyingApi.GetAnimeListForUserAsync(user));
 }