コード例 #1
0
        /// <summary>
        /// Get a list of all items synchronously.
        /// </summary>
        /// <param name="region">Region from which to retrieve the data.</param>
        /// <param name="itemData">Data to retrieve.</param>
        /// <param name="language">Language of the data to be retrieved.</param>
        /// <returns>An ItemListStatic object containing all items.</returns>
        public async Task <ItemListStatic> GetItemsAsync(Region region, ItemData itemData = ItemData.none,
                                                         Language language = Language.en_US)
        {
            var wrapper = Cache.Get <ItemListStaticWrapper>(ItemsCacheKey);

            if (wrapper != null && language == wrapper.Language && itemData == wrapper.ItemData)
            {
                return(wrapper.ItemListStatic);
            }
            var json = await requester.CreateRequestAsync(
                string.Format(ItemRootUrl, region.ToString()),
                RootDomain,
                new List <string>
            {
                string.Format("locale={0}", language.ToString()),
                itemData == ItemData.none ?
                string.Empty :
                string.Format("itemListData={0}", itemData.ToString())
            });

            var items = await Task.Factory.StartNew(() =>
                                                    JsonConvert.DeserializeObject <ItemListStatic>(json));

            wrapper = new ItemListStaticWrapper(items, language, itemData);
            Cache.Add(ItemsCacheKey, wrapper);
            return(wrapper.ItemListStatic);
        }
コード例 #2
0
ファイル: StaticRiotApi.cs プロジェクト: Karunp/RiotSharp
        /// <summary>
        /// Get a list of all items synchronously.
        /// </summary>
        /// <param name="region">Region from which to retrieve the data.</param>
        /// <param name="itemData">Data to retrieve.</param>
        /// <param name="language">Language of the data to be retrieved.</param>
        /// <returns>An ItemListStatic object containing all items.</returns>
        public async Task <ItemListStatic> GetItemsAsync(Region region, ItemData itemData = ItemData.none
                                                         , Language language = Language.en_US)
        {
            var wrapper = Cache.Get <ItemListStaticWrapper>(ItemsCacheKey);

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

                var items = await JsonConvert.DeserializeObjectAsync <ItemListStatic>(json);

                wrapper = new ItemListStaticWrapper(items, language, itemData);
                Cache.Add <ItemListStaticWrapper>(ItemsCacheKey, wrapper);
            }
            return(wrapper.ItemListStatic);
        }
コード例 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="region"></param>
        /// <param name="itemData"></param>
        /// <param name="language"></param>
        /// <returns></returns>
        public ItemListDtoStatic GetStaticItems(Region region, ItemData itemData = ItemData.basic,
                                                Language language = Language.en_US)
        {
            var wrapper = cache.Get <string, ItemListStaticWrapper>(ItemsCacheKey);

            if (wrapper == null || language != wrapper.Language || itemData != wrapper.ItemData)
            {
                var json = requester.CreateGetRequest(StaticDataRootUrl + ItemsUrl, region,
                                                      new List <string>
                {
                    string.Format("locale={0}", language.ToString()),
                    itemData == ItemData.basic ?
                    string.Empty :
                    string.Format(StaticTagsFormat, itemData.ToString())
                });
                var items = JsonConvert.DeserializeObject <ItemListDtoStatic>(json);
                wrapper = new ItemListStaticWrapper(items, language, itemData);
                cache.Add(ItemsCacheKey, wrapper, DefaultSlidingExpiry);
            }
            return(wrapper.ItemListStatic);
        }
コード例 #4
0
ファイル: StaticRiotApi.cs プロジェクト: Karunp/RiotSharp
 /// <summary>
 /// Get a list of all items synchronously.
 /// </summary>
 /// <param name="region">Region from which to retrieve the data.</param>
 /// <param name="itemData">Data to retrieve.</param>
 /// <param name="language">Language of the data to be retrieved.</param>
 /// <returns>An ItemListStatic object containing all items.</returns>
 public async Task<ItemListStatic> GetItemsAsync(Region region, ItemData itemData = ItemData.none
     , Language language = Language.en_US)
 {
     var wrapper = Cache.Get<ItemListStaticWrapper>(ItemsCacheKey);
     if (wrapper == null || language != wrapper.Language || itemData != wrapper.ItemData)
     {
         var json = await requester.CreateRequestAsync(string.Format(ItemRootUrl, region.ToString())
             , new List<string>() { string.Format("locale={0}", language.ToString())
                 , itemData == ItemData.none ? string.Empty
                     : string.Format("itemListData={0}", itemData.ToString()) });
         var items = await JsonConvert.DeserializeObjectAsync<ItemListStatic>(json);
         wrapper = new ItemListStaticWrapper(items, language, itemData);
         Cache.Add<ItemListStaticWrapper>(ItemsCacheKey, wrapper);
     }
     return wrapper.ItemListStatic;
 }