/// <inheritdoc />
        public async Task <MasteryListStatic> GetAllAsync(string version, Language language = Language.en_US)
        {
            var cacheKey = MasteriesCacheKey + language + version;
            var wrapper  = cache.Get <string, MasteryListStaticWrapper>(cacheKey);

            if (wrapper != null && language == wrapper.Language && version == wrapper.Version)
            {
                return(wrapper.MasteryListStatic);
            }
            var json = await requester.CreateGetRequestAsync(Host, CreateUrl(version, language, MasteriesDataKey)).ConfigureAwait(false);

            var masteries = JsonConvert.DeserializeObject <MasteryListStatic>(json);

            wrapper = new MasteryListStaticWrapper(masteries, language, version);
            cache.Add(cacheKey, wrapper, SlidingExpirationTime);
            return(wrapper.MasteryListStatic);
        }
        public async Task <MasteryListStatic> GetMasteriesAsync(Region region,
                                                                MasteryData masteryData = MasteryData.All, Language language = Language.en_US)
        {
            var wrapper = cache.Get <string, MasteryListStaticWrapper>(MasteriesCacheKey);

            if (wrapper != null && language == wrapper.Language && masteryData == wrapper.MasteryData)
            {
                return(wrapper.MasteryListStatic);
            }
            var json = await requester.CreateGetRequestAsync(StaticDataRootUrl + MasteriesUrl, region,
                                                             new List <string>
            {
                $"locale={language}",
                masteryData == MasteryData.Basic ?
                string.Empty :
                string.Format(TagsParameter, masteryData.ToString().ToLower())
            }).ConfigureAwait(false);

            var masteries = JsonConvert.DeserializeObject <MasteryListStatic>(json);

            wrapper = new MasteryListStaticWrapper(masteries, language, masteryData);
            cache.Add(MasteriesCacheKey, wrapper, SlidingExpirationTime);
            return(wrapper.MasteryListStatic);
        }
Пример #3
0
 /// <summary>
 /// Get a list of all masteries asynchronously.
 /// </summary>
 /// <param name="region">Region from which to retrieve the data.</param>
 /// <param name="masteryData">Data to retrieve.</param>
 /// <param name="language">Language of the data to be retrieved.</param>
 /// <returns>An MasteryListStatic object containing all masteries.</returns>
 public async Task<MasteryListStatic> GetMasteriesAsync(Region region,
     MasteryData masteryData = MasteryData.none, Language language = Language.en_US)
 {
     var wrapper = cache.Get<string, MasteryListStaticWrapper>(MasteriesCacheKey);
     if (wrapper != null && language == wrapper.Language && masteryData == wrapper.MasteryData)
     {
         return wrapper.MasteryListStatic;
     }
     var json = await requester.CreateGetRequestAsync(
         string.Format(MasteryRootUrl, region.ToString()),
         RootDomain,
         new List<string>
         {
             string.Format("locale={0}", language.ToString()),
             masteryData == MasteryData.none ?
                 string.Empty :
                 string.Format("masteryListData={0}", masteryData.ToString())
         });
     var masteries = await Task.Factory.StartNew(() =>
         JsonConvert.DeserializeObject<MasteryListStatic>(json));
     wrapper = new MasteryListStaticWrapper(masteries, language, masteryData);
     cache.Add(MasteriesCacheKey, wrapper, DefaultSlidingExpiry);
     return wrapper.MasteryListStatic;
 }
Пример #4
0
 /// <summary>
 /// Get a list of all masteries synchronously.
 /// </summary>
 /// <param name="region">Region from which to retrieve the data.</param>
 /// <param name="masteryData">Data to retrieve.</param>
 /// <param name="language">Language of the data to be retrieved.</param>
 /// <returns>An MasteryListStatic object containing all masteries.</returns>
 public MasteryListStatic GetMasteries(Region region, MasteryData masteryData = MasteryData.none,
     Language language = Language.en_US)
 {
     var wrapper = cache.Get<string, MasteryListStaticWrapper>(MasteriesCacheKey);
     if (wrapper == null || language != wrapper.Language || masteryData != wrapper.MasteryData)
     {
         var json = requester.CreateGetRequest(
             string.Format(MasteryRootUrl, region.ToString()),
             RootDomain,
             new List<string>
             {
                 string.Format("locale={0}", language.ToString()),
                 masteryData == MasteryData.none ?
                 string.Empty :
                 string.Format("masteryListData={0}", masteryData.ToString())
             });
         var masteries = JsonConvert.DeserializeObject<MasteryListStatic>(json);
         wrapper = new MasteryListStaticWrapper(masteries, language, masteryData);
         cache.Add(MasteriesCacheKey, wrapper, DefaultSlidingExpiry);
     }
     return wrapper.MasteryListStatic;
 }