Ejemplo n.º 1
0
        /// <summary>
        /// Get a list of all champions asynchronously.
        /// </summary>
        /// <param name="region">Region from which to retrieve the data.</param>
        /// <param name="championData">Data to retrieve.</param>
        /// <param name="language">Language of the data to be retrieved.</param>
        /// <returns>A ChampionListStatic object containing all champions.</returns>
        public async Task <ChampionListStatic> GetChampionsAsync(Region region,
                                                                 ChampionData championData = ChampionData.none, Language language = Language.en_US)
        {
            var wrapper = Cache.Get <ChampionListStaticWrapper>(ChampionsCacheKey);

            if (wrapper != null && language == wrapper.Language && championData == wrapper.ChampionData)
            {
                return(wrapper.ChampionListStatic);
            }
            var json = await requester.CreateRequestAsync(
                string.Format(ChampionRootUrl, region.ToString()),
                RootDomain,
                new List <string>
            {
                string.Format("locale={0}", language.ToString()),
                championData == ChampionData.none ?
                string.Empty :
                string.Format("champData={0}", championData.ToString())
            });

            var champs = await Task.Factory.StartNew(() =>
                                                     JsonConvert.DeserializeObject <ChampionListStatic>(json));

            wrapper = new ChampionListStaticWrapper(champs, language, championData);
            Cache.Add(ChampionsCacheKey, wrapper);
            return(wrapper.ChampionListStatic);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Get a list of all champions synchronously.
 /// </summary>
 /// <param name="region">Region from which to retrieve the data.</param>
 /// <param name="championData">Data to retrieve.</param>
 /// <param name="language">Language of the data to be retrieved.</param>
 /// <returns>A ChampionListStatic object containing all champions.</returns>
 public ChampionListStatic GetChampions(Region region, ChampionData championData = ChampionData.none
     , Language language = Language.en_US)
 {
     var wrapper = Cache.Get<ChampionListStaticWrapper>(ChampionsCacheKey);
     if (wrapper == null || language != wrapper.Language || championData != wrapper.ChampionData)
     {
         var json = requester.CreateRequest(string.Format(ChampionRootUrl, region.ToString())
             , new List<string>() { string.Format("locale={0}", language.ToString())
                 , championData == ChampionData.none ? string.Empty 
                     : string.Format("champData={0}", championData.ToString()) });
         var champs = JsonConvert.DeserializeObject<ChampionListStatic>(json);
         wrapper = new ChampionListStaticWrapper(champs, language, championData);
         Cache.Add<ChampionListStaticWrapper>(ChampionsCacheKey, wrapper);
     }
     return wrapper.ChampionListStatic;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Get a list of all champions asynchronously.
        /// </summary>
        /// <param name="region">Region from which to retrieve the data.</param>
        /// <param name="championData">Data to retrieve.</param>
        /// <param name="language">Language of the data to be retrieved.</param>
        /// <returns>A ChampionListStatic object containing all champions.</returns>
        public async Task <ChampionListStatic> GetChampionsAsync(Region region
                                                                 , ChampionData championData = ChampionData.none, Language language = Language.en_US)
        {
            var wrapper = Cache.Get <ChampionListStaticWrapper>(ChampionsCacheKey);

            if (wrapper == null || language != wrapper.Language || championData != wrapper.ChampionData)
            {
                var json = await requester.CreateRequestAsync(string.Format(ChampionRootUrl, region.ToString())
                                                              , new List <string>() { string.Format("locale={0}", language.ToString())
                                                                                      , championData == ChampionData.none ? string.Empty
                            : string.Format("champData={0}", championData.ToString()) });

                var champs = await JsonConvert.DeserializeObjectAsync <ChampionListStatic>(json);

                wrapper = new ChampionListStaticWrapper(champs, language, championData);
                Cache.Add <ChampionListStaticWrapper>(ChampionsCacheKey, wrapper);
            }
            return(wrapper.ChampionListStatic);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="region"></param>
        /// <param name="championData"></param>
        /// <param name="language"></param>
        /// <returns></returns>
        public ChampionListDtoStatic GetStaticChampions(Region region, ChampionData championData = ChampionData.basic,
                                                        Language language = Language.en_US)
        {
            var wrapper = cache.Get <string, ChampionListStaticWrapper>(ChampionsCacheKey);

            if (wrapper == null || language != wrapper.Language || championData != wrapper.ChampionData)
            {
                var json = requester.CreateGetRequest(StaticDataRootUrl + ChampionsUrl, region,
                                                      new List <string> {
                    string.Format("locale={0}", language.ToString()),
                    championData == ChampionData.basic ?
                    string.Empty :
                    string.Format(StaticTagsFormat, championData.ToString())
                });
                var champs = JsonConvert.DeserializeObject <ChampionListDtoStatic>(json);
                wrapper = new ChampionListStaticWrapper(champs, language, championData);
                cache.Add(ChampionsCacheKey, wrapper, DefaultSlidingExpiry);
            }
            return(wrapper.ChampionListStatic);
        }