public string ReadNumber(out Region reg) { reg = StartRegion(); if ((CurChar == '+' || CurChar == '-') && Peek(1) == '.' && !IsDigit(Peek(2))) { Throw($"Expected number, got {new string(new char[] { CurChar, Peek(1), Peek(2) }).Inspect()}..."); } else if ((CurChar == '+' || CurChar == '-') && !IsDigit(Peek(1))) { Throw($"Expected number, got {new string(new char[] { CurChar, Peek(1) }).Inspect()}..."); } else if (CurChar == '.' && !IsDigit(Peek(1))) { Throw($"Expected number, got {new string(new char[] { CurChar, Peek(1) }).Inspect()}..."); } else if (!IsDigit(CurChar)) { Throw($"Expected number, got {CurChar.Inspect()}"); } if (CurChar == '0' && Peek(1) == 'x') { Move(2); while (!EOF && IsHexDigit(CurChar)) { Move(); } reg.End(); return(reg.ToString()); } Move(); if (CurChar == '.') { Move(); } while (!EOF && IsDigit(CurChar)) { Move(); } if (CurChar == '.') { Move(); while (!EOF && IsDigit(CurChar)) { Move(); } } reg.End(); return(reg.ToString()); }
public static bool Register(RegionLink __instance, Region reg) { Region regionA = __instance.RegionA; Region regionB = __instance.RegionB; if (__instance.regions[0] == reg || __instance.regions[1] == reg) { Log.Error("Tried to double-register region " + reg.ToString() + " in " + __instance); } else if (regionA == null || !regionA.valid) { __instance.RegionA = reg; } else if (regionB == null || !regionB.valid) { __instance.RegionB = reg; } else { Log.Warning("Could not register region " + reg.ToString() + " in link " + __instance + ": > 2 regions on link!\nRegionA: " + __instance.RegionA.DebugString + "\nRegionB: " + __instance.RegionB.DebugString); //TODO find root cause RegionAndRoomUpdater_Patch.regionsToReDirty.Add(regionA); RegionAndRoomUpdater_Patch.regionsToReDirty.Add(regionB); RegionAndRoomUpdater_Patch.regionsToReDirty.Add(reg); //RegionDirtyer_Patch.SetRegionDirty(reg.Map.regionDirtyer, regionA); //RegionDirtyer_Patch.SetRegionDirty(reg.Map.regionDirtyer, regionB); /* * foreach (IntVec3 cell in reg.Cells) * { * if (regionA.Cells.Contains(cell)) * { * __instance.RegionA = reg; * RegionDirtyer_Patch.SetRegionDirty(reg.Map.regionDirtyer, regionA); * break; * } * if (regionB.Cells.Contains(cell)) * { * __instance.RegionB = reg; * RegionDirtyer_Patch.SetRegionDirty(reg.Map.regionDirtyer, regionB); * break; * } * } */ } return(false); }
public void Connect(string user, string password, Region region) { if (!this.isConnected && HFL_3._0.Rotator.running) { new Thread(delegate(object state) { this.user = user; this.password = password; reg = region; this.regionName = region.ToString(); this.clientVersion = RegionInfo.getRegionVersion(region.ToString()); this.server = RegionInfo.GetServerValue(region); this.loginQueue = RegionInfo.GetLoginQueueValue(region); this.locale = RegionInfo.GetLocaleValue(region); this.useGarena = RegionInfo.GetUseGarenaValue(region); try { this.client = new TcpClient(this.server, 2099); if ((!this.useGarena || this.GetGarenaToken()) && (this.GetAuthKey() && this.GetIpAddress())) { this.sslStream = new SslStream(this.client.GetStream(), false, new RemoteCertificateValidationCallback(this.AcceptAllCertificates)); IAsyncResult asyncResult = this.sslStream.BeginAuthenticateAsClient(this.server, null, null); using (asyncResult.AsyncWaitHandle) { if (asyncResult.AsyncWaitHandle.WaitOne(-1)) { this.sslStream.EndAuthenticateAsClient(asyncResult); } } if (this.Handshake()) { this.BeginReceive(); if (this.SendConnect() && this.Login()) { this.StartHeartbeat(); } } } } catch { this.Error("Riots servers are currently unavailable.", ErrorType.AuthKey); this.Disconnect(); } }).Start(); } }
public async Task Initialize() { string rawOpcodes; try { rawOpcodes = await http.GetStringAsync( new Uri("https://cdn.jsdelivr.net/gh/karashiiro/FFXIVOpcodes@latest/opcodes.min.json")); } catch (Exception e) { if (e is HttpRequestException || e is WebException) { await Console.Error.WriteLineAsync(e.Message); rawOpcodes = await http.GetStringAsync( new Uri("https://raw.githubusercontent.com/karashiiro/FFXIVOpcodes/master/opcodes.min.json")); } else { throw; } } OpcodeLists = JsonConvert.DeserializeObject <OpcodeList[]>(rawOpcodes); ActiveOpcodeList = OpcodeLists.FirstOrDefault(l => l.Region == Region.ToString()); }
/// <summary> /// Search the data from the summoner /// </summary> /// <param name="name">Summoner Name</param> /// <returns>Summoner Object</returns> public bool RequestByName(string name, Region region) { Rootobject root = null; // URL Request string apiKey = "fbfa3c47-9c26-4891-8e55-c50a4f3ad3ba"; string uri = "https://na.api.pvp.net/api/lol/" + region.ToString() + "/v1.4/summoner/by-name/"; string adds = name + "?api_key=" + apiKey; // Get JSON response from server HttpClient client = new HttpClient(); client.BaseAddress = new Uri(uri); var response = client.GetAsync(adds).Result; // Convert to object var responseJson = response.Content.ReadAsStringAsync().Result; root = JsonConvert.DeserializeObject<Rootobject>(responseJson); info.name = root.summoner.name; return (true); /* if (root.summoner.id != 0) { this.id = root.summoner.id; this.name = root.summoner.name; this.summonerLevel = root.summoner.summonerLevel; this.profileIconId = root.summoner.profileIconId; this.revisionDate = root.summoner.revisionDate; return (true); } else { this.name = uri + adds; return (false); }*/ }
// Построение идеально сбалансированного дерева public static PointTree IdealTree(int size, PointTree p) { PointTree r; int nl, nr; if (size == 0) { p = null; return(p); } nl = size / 2; nr = size - nl - 1; r = new PointTree(); int typeclass = random.Next(1, 4); switch (typeclass) { case 1: { Place place = new Place(); place.RandomCreate(); Console.WriteLine("The element {0} is adding...", place.ToString()); r = first(place); } break; case 2: { Region region = new Region(); region.RandomCreate(); Console.WriteLine("The element {0} is adding...", region.ToString()); r = first(region); } break; case 3: { City city = new City(); city.RandomCreate(); Console.WriteLine("The element {0} is adding...", city.ToString()); r = first(city); } break; case 4: { Megapolis megapolis = new Megapolis(); megapolis.RandomCreate(); Console.WriteLine("The element {0} is adding...", megapolis.ToString()); r = first(megapolis); } break; } r.left = IdealTree(nl, r.left); r.right = IdealTree(nr, r.right); return(r); }
/// <summary> /// Retrieve static api version data asynchronously. /// </summary> /// <param name="region">Region from which to retrieve data.</param> /// <returns>A list of versions as strings.</returns> public async Task <List <string> > GetVersionsAsync(Region region) { var wrapper = cache.Get <string, List <string> >(VersionCacheKey); if (wrapper != null) { return(wrapper); } var args = "{\"region\" : \"" + region.ToString() + "\"}"; var ir = new Amazon.Lambda.Model.InvokeRequest { FunctionName = "arn:aws:lambda:us-east-1:907841483528:function:staticGetVersion", PayloadStream = AWSSDKUtils.GenerateMemoryStreamFromString(args) }; var json = ""; var resp = await App.lambdaClient.InvokeAsync(ir); var sr = new StreamReader(resp.Payload); json = sr.ReadToEnd(); var version = await Task.Factory.StartNew(() => JsonConvert.DeserializeObject <List <string> >(json)); cache.Add(VersionCacheKey, version, DefaultSlidingExpiry); return(version); }
/// <summary> /// Get an item asynchronously. /// </summary> /// <param name="region">Region from which to retrieve the data.</param> /// <param name="itemId">Id of the item to retrieve.</param> /// <param name="itemData">Data to retrieve.</param> /// <param name="language">Language of the data to be retrieved.</param> /// <returns>An item.</returns> public async Task <ItemStatic> GetItemAsync(Region region, int itemId, ItemData itemData = ItemData.none, Language language = Language.en_US) { var wrapper = Cache.Get <ItemStaticWrapper>(ItemCacheKey + itemId); if (wrapper != null && wrapper.Language == language && wrapper.ItemData == itemData) { return(wrapper.ItemStatic); } var listWrapper = Cache.Get <ItemListStaticWrapper>(ItemsCacheKey); if (listWrapper != null && listWrapper.Language == language && listWrapper.ItemData == itemData) { return(listWrapper.ItemListStatic.Items.ContainsKey(itemId) ? listWrapper.ItemListStatic.Items[itemId] : null); } var json = await requester.CreateRequestAsync( string.Format(ItemRootUrl, region.ToString()) + string.Format(IdUrl, itemId), RootDomain, new List <string> { string.Format("locale={0}", language.ToString()), itemData == ItemData.none ? string.Empty : string.Format("itemData={0}", itemData.ToString()) }); var item = await Task.Factory.StartNew(() => JsonConvert.DeserializeObject <ItemStatic>(json)); Cache.Add(ItemCacheKey + itemId, new ItemStaticWrapper(item, language, itemData)); return(item); }
public void ToStringOverrideTest() { var expected = "Region with 0 components and the following "; expected += _area.Area; Assert.Equal(expected, _area.ToString()); }
/// <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 <MasteryListStaticWrapper>(MasteriesCacheKey); if (wrapper != null && language == wrapper.Language && masteryData == wrapper.MasteryData) { return(wrapper.MasteryListStatic); } var json = await requester.CreateRequestAsync( 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); return(wrapper.MasteryListStatic); }
private static LayoutFactory GetLayoutFactory(Region region) { var layoutAttribute = typeof(Region).GetField(region.ToString()).GetCustomAttributes(typeof(LayoutAttribute), false).FirstOrDefault(); if (layoutAttribute == null) return null; return ((LayoutAttribute)layoutAttribute).Layout; }
/// <summary> /// Get a list of all runes asynchronously. /// </summary> /// <param name="region">Region from which to retrieve the data.</param> /// <param name="runeData">Data to retrieve.</param> /// <param name="language">Language of the data to be retrieved.</param> /// <returns>A RuneListStatic object containing all runes.</returns> public async Task <RuneListStatic> GetRunesAsync(Region region, RuneData runeData = RuneData.none, Language language = Language.en_US) { var wrapper = Cache.Get <RuneListStaticWrapper>(RunesCacheKey); if (wrapper != null && !(language != wrapper.Language | runeData != wrapper.RuneData)) { return(wrapper.RuneListStatic); } var json = await requester.CreateRequestAsync( string.Format(RuneRootUrl, region.ToString()), RootDomain, new List <string> { string.Format("locale={0}", language.ToString()), runeData == RuneData.none ? string.Empty : string.Format("runeListData={0}", runeData.ToString()) }); var runes = await Task.Factory.StartNew(() => JsonConvert.DeserializeObject <RuneListStatic>(json)); wrapper = new RuneListStaticWrapper(runes, language, runeData); Cache.Add(RunesCacheKey, wrapper); return(wrapper.RuneListStatic); }
/// <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); }
public bool SetRegion(Region region) { string regionString; if (region != Region.PTR) { regionString = region.ToString(); } else { regionString = "XX"; } try { RegistryKey key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Blizzard Entertainment\Battle.net\Launch Options\Pro", true); if (key != null) { key.SetValue("REGION", regionString); } } catch (Exception ex) { return(false); } return(true); }
private object BuildReferenceDto(Region item) { return new{ StringId = _stringConverter.ToString(item), Description = item.ToString(), }; }
/// <summary> /// Get a champion from its id synchronously. /// </summary> /// <param name="region">Region in which you wish to look for a champion.</param> /// <param name="championId">Id of the champion you're looking for.</param> /// <returns>A champion.</returns> public Champion GetChampion(Region region, int championId) { var json = requester.CreateRequest( string.Format(ChampionRootUrl, region.ToString()) + string.Format(IdUrl, championId), region); return(JsonConvert.DeserializeObject <Champion>(json)); }
public static string DisplayName(this Region value) { var member = typeof(Region).GetMember($"{value}").FirstOrDefault(); var attribute = member?.GetCustomAttribute(typeof(DisplayAttribute)) as DisplayAttribute; return(attribute?.Name ?? value.ToString()); }
public async Task <RegionLadderResult> GetLeaderBoardData(Region region, int limit = 0) { _httpClient = new HttpClient(); var token = await _tokenService.GetToken(); var url = ConstructUrl(region); var uri = $"{url}{token.AccessToken}"; var response = await _httpClient.GetAsync(uri); if (!response.IsSuccessStatusCode) { throw new HttpRequestException(response.ReasonPhrase); } var content = await response.Content.ReadAsStringAsync(); var apiLadderResult = JsonConvert.DeserializeObject <RootObject>(content); var ladderResult = new RegionLadderResult { Region = region.ToString(), Players = limit == 0 ? apiLadderResult.LadderTeams.Select(Player.Convert).ToList() : apiLadderResult.LadderTeams.Select(Player.Convert).Take(limit).ToList() }; return(ladderResult); }
///GENMHASH:03B1F797E02E1089DCD5EB13134EB163:0206C7B1F86570DBFF6507721145FD4A public IUpdate WithoutRegionAvailability(Region region) { if (this.Inner.PublishingProfile != null && this.Inner.PublishingProfile.Regions != null) { int foundIndex = -1; int i = 0; string regionNameToRemove = region.ToString(); string regionNameToRemoveTrimmed = regionNameToRemove.Replace(" ", ""); // foreach (var regionStr in this.Inner.PublishingProfile.Regions) { string regionStrTrimmed = regionStr.Replace(" ", ""); if (regionStrTrimmed.Equals(regionNameToRemoveTrimmed, StringComparison.OrdinalIgnoreCase)) { foundIndex = i; break; } i++; } if (foundIndex != -1) { this.Inner.PublishingProfile.Regions.RemoveAt(foundIndex); } } return(this); }
public void RandomizeTask() { currentTask = (Task)Random.Range(0, 3); currentRegion = (Region)Random.Range(0, 3); taskText.text = currentTask.ToString() + " " + currentRegion.ToString(); currentPurrPower = startingPower; }
/// <summary> /// Get the match history of this summoner synchronously. /// </summary> /// <param name="beginIndex">The begin index to use for fetching games. /// The range has to be less than or equal to 15.</param> /// <param name="endIndex">The end index to use for fetching games. /// The range has to be less than or equal to 15.</param> /// <param name="championIds">List of champion IDs to use for fetching games.</param> /// <param name="rankedQueues">List of ranked queue types to use for fetching games. Non-ranked queue types /// will be ignored.</param> /// <returns>A list of match summaries object.</returns> public List <MatchSummary> GetMatchHistory(int beginIndex = 0, int endIndex = 14, List <long> championIds = null, List <Queue> rankedQueues = null) { var addedArguments = new List <string> { string.Format("beginIndex={0}", beginIndex), string.Format("endIndex={0}", endIndex), }; if (championIds != null) { addedArguments.Add(string.Format("championIds={0}", Util.BuildIdsString(championIds))); } if (rankedQueues != null) { addedArguments.Add(string.Format("rankedQueues={0}", Util.BuildQueuesString(rankedQueues))); } var json = requester.CreateRequest( string.Format(MatchHistoryRootUrl, Region.ToString()) + string.Format(IdUrl, Id), Region, addedArguments); return(JsonConvert.DeserializeObject <PlayerHistory>(json).Matches); }
/// <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); }
/// <summary> /// Retrieve static api version data asynchronously. /// </summary> /// <param name="region">Region from which to retrieve data.</param> /// <returns>A list of versions as strings.</returns> public async Task <List <string> > GetVersionsAsync(Region region) { var json = await requester.CreateRequestAsync(string.Format(VersionRootUrl, region.ToString()), RootDomain); return(await Task.Factory.StartNew(() => JsonConvert.DeserializeObject <List <string> >(json))); }
/// <summary> /// Get a champion asynchronously. /// </summary> /// <param name="region">Region from which to retrieve the data.</param> /// <param name="championId">Id of the champion to retrieve.</param> /// <param name="championData">Data to retrieve.</param> /// <param name="language">Language of the data to be retrieved.</param> /// <returns>A champion.</returns> public async Task <ChampionStatic> GetChampionAsync(Region region, int championId, ChampionData championData = ChampionData.none, Language language = Language.en_US) { var wrapper = Cache.Get <ChampionStaticWrapper>(ChampionCacheKey + championId); if (wrapper != null && wrapper.Language == language && wrapper.ChampionData == championData) { return(wrapper.ChampionStatic); } var listWrapper = Cache.Get <ChampionListStaticWrapper>(ChampionsCacheKey); if (listWrapper != null && listWrapper.Language == language && listWrapper.ChampionData == championData) { return(listWrapper.ChampionListStatic.Champions.Values.FirstOrDefault(c => c.Id == championId)); } var json = await requester.CreateRequestAsync( string.Format(ChampionRootUrl, region.ToString()) + string.Format(IdUrl, championId), RootDomain, new List <string> { string.Format("locale={0}", language.ToString()), championData == ChampionData.none ? string.Empty : string.Format("champData={0}", championData.ToString()) }); var champ = await Task.Factory.StartNew(() => JsonConvert.DeserializeObject <ChampionStatic>(json)); Cache.Add(ChampionCacheKey + championId, new ChampionStaticWrapper(champ, language, championData)); return(champ); }
/// <summary> /// Get a list of all summoner spells asynchronously. /// </summary> /// <param name="region">Region from which to retrieve the data.</param> /// <param name="summonerSpellData">Data to retrieve.</param> /// <param name="language">Language of the data to be retrieved.</param> /// <returns>A SummonerSpellListStatic object containing all summoner spells.</returns> public async Task <SummonerSpellListStatic> GetSummonerSpellsAsync(Region region, SummonerSpellData summonerSpellData = SummonerSpellData.none, Language language = Language.en_US) { var wrapper = Cache.Get <SummonerSpellListStaticWrapper>(SummonerSpellsCacheKey); if (wrapper != null && wrapper.Language == language && wrapper.SummonerSpellData == summonerSpellData) { return(wrapper.SummonerSpellListStatic); } var json = await requester.CreateRequestAsync( string.Format(SummonerSpellRootUrl, region.ToString()), RootDomain, new List <string> { string.Format("locale={0}", language.ToString()), summonerSpellData == SummonerSpellData.none ? string.Empty : string.Format("spellData={0}", summonerSpellData.ToString()) }); var spells = await Task.Factory.StartNew(() => JsonConvert.DeserializeObject <SummonerSpellListStatic>(json)); wrapper = new SummonerSpellListStaticWrapper(spells, language, summonerSpellData); Cache.Add(SummonerSpellsCacheKey, wrapper); return(wrapper.SummonerSpellListStatic); }
public static bool IsLocaleAvailable(this Region region, Locale locale) { switch (region) { case Region.Europe: return((Locale.BritishEnglish == locale) || (Locale.SpainSpanish == locale) || (Locale.French == locale) || (Locale.Russian == locale) || (Locale.German == locale) || (Locale.PortugalPortuguese == locale) || (Locale.Italian == locale)); case Region.Korea: return(Locale.Korean == locale); case Region.Taiwan: return(Locale.TraditionalChinese == locale); case Region.SoutheastAsia: case Region.UnitedStates: return((Locale.AmericanEnglish == locale) || (Locale.MexicanSpanish == locale) || (Locale.BrazilianPortuguese == locale)); case Region.China: return(Locale.SimplifiedChinese == locale); default: throw new NotImplementedException($"The {nameof(Region)} [{region.ToString()}] does not have an associated {nameof(Locale)}"); } }
/// <summary> /// Get a rune asynchronously. /// </summary> /// <param name="region">Region from which to retrieve the data.</param> /// <param name="runeId">Id of the rune to retrieve.</param> /// <param name="runeData">Data to retrieve.</param> /// <param name="language">Language of the data to be retrieved.</param> /// <returns>A rune.</returns> public async Task <RuneStatic> GetRuneAsync(Region region, int runeId, RuneData runeData = RuneData.none, Language language = Language.en_US) { var wrapper = Cache.Get <RuneStaticWrapper>(RuneCacheKey + runeId); if (wrapper != null && wrapper.Language == language && wrapper.RuneData == RuneData.all) { return(wrapper.RuneStatic); } var listWrapper = Cache.Get <RuneListStaticWrapper>(RunesCacheKey); if (listWrapper != null && listWrapper.Language == language && listWrapper.RuneData == runeData) { return(listWrapper.RuneListStatic.Runes.ContainsKey(runeId) ? listWrapper.RuneListStatic.Runes[runeId] : null); } var json = await requester.CreateRequestAsync( string.Format(RuneRootUrl, region.ToString()) + string.Format(IdUrl, runeId), RootDomain, new List <string> { string.Format("locale={0}", language.ToString()), runeData == RuneData.none ? string.Empty : string.Format("runeData={0}", runeData.ToString()) }); var rune = await Task.Factory.StartNew(() => JsonConvert.DeserializeObject <RuneStatic>(json)); Cache.Add(RuneCacheKey + runeId, new RuneStaticWrapper(rune, language, runeData)); return(rune); }
/// <summary> /// Get a summoner by id synchronously. /// </summary> /// <param name="region">Region in which you wish to look for a summoner.</param> /// <param name="summonerId">Id of the summoner you're looking for.</param> /// <returns>A summoner.</returns> public Summoner GetSummoner(Region region, long summonerId, bool cached = true) { string json = null; if (ApiCache.CacheEnabled && cached && (json = ApiCache.GetSummoner(summonerId, region)) != null) { var obj = JsonConvert.DeserializeObject <Dictionary <long, Summoner> >(json).Values.FirstOrDefault(); if (obj != null) { obj.Region = region; } return(obj); } else { json = requester.CreateRequest( string.Format(SummonerRootUrl, region.ToString()) + string.Format(IdUrl, summonerId), region); var obj = JsonConvert.DeserializeObject <Dictionary <long, Summoner> >(json).Values.FirstOrDefault(); if (obj != null) { obj.Region = region; if (ApiCache.CacheEnabled) { ApiCache.AddSummoner(obj, json, region); } } return(obj); } }
/// <summary> /// Get a mastery asynchronously. /// </summary> /// <param name="region">Region from which to retrieve the data.</param> /// <param name="masteryId">Id of the mastery to retrieve.</param> /// <param name="masteryData">Data to retrieve.</param> /// <param name="language">Language of th data to be retrieved.</param> /// <returns>A mastery.</returns> public async Task <MasteryStatic> GetMasteryAsync(Region region, int masteryId, MasteryData masteryData = MasteryData.none, Language language = Language.en_US) { var wrapper = Cache.Get <MasteryStaticWrapper>(MasteryCacheKey + masteryId); if (wrapper != null && wrapper.Language == language && wrapper.MasteryData == masteryData) { return(wrapper.MasteryStatic); } var listWrapper = Cache.Get <MasteryListStaticWrapper>(MasteriesCacheKey); if (listWrapper != null && listWrapper.Language == language && listWrapper.MasteryData == masteryData) { return(listWrapper.MasteryListStatic.Masteries.ContainsKey(masteryId) ? listWrapper.MasteryListStatic.Masteries[masteryId] : null); } var json = await requester.CreateRequestAsync( string.Format(MasteryRootUrl, region.ToString()) + string.Format(IdUrl, masteryId.ToString()), RootDomain, new List <string> { string.Format("locale={0}", language.ToString()), masteryData == MasteryData.none ? string.Empty : string.Format("masteryData={0}", masteryData.ToString()) }); var mastery = await Task.Factory.StartNew(() => JsonConvert.DeserializeObject <MasteryStatic>(json)); Cache.Add(MasteryCacheKey + masteryId , new MasteryStaticWrapper(mastery, language, masteryData)); return(mastery); }
/// <summary> /// Get the mach history of a specific summoner asynchronously. /// </summary> /// <param name="region">Region in which the summoner is.</param> /// <param name="summonerId">Summoner ID for which you want to retrieve the match history.</param> /// <param name="beginIndex">The begin index to use for fetching games. /// endIndex - beginIndex has to be inferior to 15.</param> /// <param name="endIndex">The end index to use for fetching games. /// endIndex - beginIndex has to be inferior to 15.</param> /// <param name="championIds">List of champion IDs to use for fetching games.</param> /// <param name="rankedQueues">List of ranked queue types to use for fetching games. Non-ranked queue types /// will be ignored.</param> /// <returns>A list of match summaries object.</returns> public async Task <List <MatchSummary> > GetMatchHistoryAsync(Region region, long summonerId, int beginIndex = 0, int endIndex = 14, List <int> championIds = null, List <Queue> rankedQueues = null) { var addedArguments = new List <string> { string.Format("beginIndex={0}", beginIndex), string.Format("endIndex={0}", endIndex), }; if (championIds != null) { addedArguments.Add(string.Format("championIds={0}", Util.BuildIdsString(championIds))); } if (rankedQueues != null) { addedArguments.Add(string.Format("rankedQueues={0}", Util.BuildQueuesString(rankedQueues))); } var json = await requester.CreateRequestAsync( string.Format(MatchHistoryRootUrl, region.ToString()) + string.Format(IdUrl, summonerId), region, addedArguments); return(await Task.Factory.StartNew(() => JsonConvert.DeserializeObject <PlayerHistory>(json).Matches)); }
/// <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, List <ChampionData> championData, Language language = Language.en_US) { var stringList = new List <string> { }; foreach (var data in championData) { stringList.Add(data.ToString()); } var champData = Util.BuildNamesString(stringList); var args = "{\"data\" : \"" + champData + "\", \"region\" : \"" + region.ToString() + "\"}"; var ir = new Amazon.Lambda.Model.InvokeRequest { FunctionName = "arn:aws:lambda:us-east-1:907841483528:function:staticGetChampion", PayloadStream = AWSSDKUtils.GenerateMemoryStreamFromString(args) }; var json = ""; var resp = await App.lambdaClient.InvokeAsync(ir); var sr = new StreamReader(resp.Payload); json = sr.ReadToEnd(); var champs = await Task.Factory.StartNew(() => JsonConvert.DeserializeObject <ChampionListStatic>(json)); return(champs); }
/// <summary> /// Get a summoner spell synchronously. /// </summary> /// <param name="region">Region from which to retrieve the data.</param> /// <param name="summonerSpell">Summoner spell to retrieve.</param> /// <param name="summonerSpellData">Data to retrieve.</param> /// <param name="language">Language of the data to be retrieved.</param> /// <returns>A summoner spell.</returns> public SummonerSpellStatic GetSummonerSpell(Region region, SummonerSpell summonerSpell, List <SummonerSpellData> summonerSpellData, Language language = Language.en_US) { var stringList = new List <string>(); foreach (var data in summonerSpellData) { stringList.Add(data.ToString()); } var champData = Util.BuildNamesString(stringList); var args = "{\"data\" : \"" + champData + "\", \"region\" : \"" + region.ToString() + ", \"id\" : \"" + (int)summonerSpell + "\"}"; var ir = new Amazon.Lambda.Model.InvokeRequest { FunctionName = "arn:aws:lambda:us-east-1:907841483528:function:staticGetSummonerSpell", PayloadStream = AWSSDKUtils.GenerateMemoryStreamFromString(args) }; var json = ""; var test = Task.Run(async() => { var resp = await App.lambdaClient.InvokeAsync(ir); var sr = new StreamReader(resp.Payload); json = sr.ReadToEnd(); }); test.Wait(); var spell = JsonConvert.DeserializeObject <SummonerSpellStatic>(json); return(spell); }
/// <summary> /// Get a summoner by id asynchronously. /// </summary> /// <param name="region">Region in which you wish to look for a summoner.</param> /// <param name="summonerId">Id of the summoner you're looking for.</param> /// <returns>A summoner.</returns> public async Task<Summoner> GetSummonerAsync(Region region, int summonerId) { var json = await requester.CreateRequestAsync(string.Format(SummonerRootUrl, region.ToString()) + string.Format(IdUrl, summonerId)); var obj = (await JsonConvert.DeserializeObjectAsync<Dictionary<long, Summoner>>(json)).Values.FirstOrDefault(); obj.Region = region; return obj; }
/// <summary> /// Get a summoner by id synchronously. /// </summary> /// <param name="region">Region in which you wish to look for a summoner.</param> /// <param name="summonerId">Id of the summoner you're looking for.</param> /// <returns>A summoner.</returns> public Summoner GetSummoner(Region region, int summonerId) { var json = requester.CreateRequest(string.Format(SummonerRootUrl, region.ToString()) + string.Format(IdUrl, summonerId)); var obj = JsonConvert.DeserializeObject<Dictionary<long, Summoner>>(json).Values.FirstOrDefault(); obj.Region = region; return obj; }
/// <summary> /// Creates a tournament provider and returns its ID. /// </summary> /// <param name="region">The region in which the provider will be running tournaments.</param> /// <param name="url"> /// The provider's callback URL to which tournament game results in this region should be posted. The URL /// must be well-formed, use the http or https protocol, and use the default port for the protocol (http URLs must use /// port 80, https URLs must use port 443). /// </param> /// <returns>The ID of the provider.</returns> public TournamentProvider CreateProvider(Region region, string url) { var body = new Dictionary<string, object> { { "url", url }, { "region", region.ToString().ToUpper() } }; var json = requester.CreatePostRequest(TournamentRootUrl + CreateProviderUrl, Region.global, JsonConvert.SerializeObject(body)); // json is an int directly var provider = new TournamentProvider { Id = int.Parse(json) }; return provider; }
/// <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; }
public override string CreateRequest(string relativeUrl, Region region, List<string> addedArguments = null) { RootDomain = region.ToString() + ".api.pvp.net"; HttpWebRequest request = PrepareRequest(relativeUrl, addedArguments); semaphore.Wait(); { if (firstRequestInLastTenM == DateTime.MinValue) { firstRequestInLastTenM = DateTime.Now; } numberOfRequestInLastTenM++; if (firstRequestInLastTenS == DateTime.MinValue) { firstRequestInLastTenS = DateTime.Now; } numberOfRequestsInLastTenS++; if (!IsProdApi && numberOfRequestInLastTenM > MAX_REQUEST_PER_10M) { while ((DateTime.Now - firstRequestInLastTenM).TotalSeconds <= 601) ; numberOfRequestInLastTenM = 1; firstRequestInLastTenM = DateTime.Now; } if (!IsProdApi && numberOfRequestsInLastTenS > MAX_REQUEST_PER_10S) { while ((DateTime.Now - firstRequestInLastTenS).TotalSeconds <= 11) ; numberOfRequestsInLastTenS = 1; firstRequestInLastTenS = DateTime.Now; } if (!IsProdApi && ((DateTime.Now - firstRequestInLastTenS).TotalSeconds > 10)) { firstRequestInLastTenS = DateTime.Now; numberOfRequestsInLastTenS = 1; } if (!IsProdApi && ((DateTime.Now - firstRequestInLastTenM).TotalMinutes > 10)) { firstRequestInLastTenM = DateTime.Now; numberOfRequestInLastTenM = 1; } } semaphore.Release(); return GetResponse(request); }
public static string GetRuneNameFor( Region region ) { while ( region != null ) { BaseRegion br = region as BaseRegion; if ( br != null && br.m_RuneName != null ) return br.m_RuneName; if (br == null) return "an unknown location"; if (region.Parent != null) return region.Parent.ToString(); else return region.ToString(); } return null; }
/// <summary> /// Get a mastery asynchronously. /// </summary> /// <param name="region">Region from which to retrieve the data.</param> /// <param name="masteryId">Id of the mastery to retrieve.</param> /// <param name="masteryData">Data to retrieve.</param> /// <param name="language">Language of th data to be retrieved.</param> /// <returns>A mastery.</returns> public async Task<MasteryStatic> GetMasteryAsync(Region region, int masteryId , MasteryData masteryData = MasteryData.none, Language language = Language.en_US) { var wrapper = Cache.Get<MasteryStaticWrapper>(MasteryCacheKey + masteryId); if (wrapper != null && wrapper.Language == language && wrapper.MasteryData == masteryData) { return wrapper.MasteryStatic; } else { var listWrapper = Cache.Get<MasteryListStaticWrapper>(MasteriesCacheKey); if (listWrapper != null && listWrapper.Language == language && listWrapper.MasteryData == masteryData) { if (listWrapper.MasteryListStatic.Masteries.ContainsKey(masteryId)) { return listWrapper.MasteryListStatic.Masteries[masteryId]; } else { return null; } } else { var json = await requester.CreateRequestAsync(string.Format(MasteryRootUrl, region.ToString()) + string.Format(IdUrl, masteryId.ToString()) , new List<string>() { string.Format("locale={0}", language.ToString()) , masteryData == MasteryData.none ? string.Empty : string.Format("masteryData={0}", masteryData.ToString()) }); var mastery = await JsonConvert.DeserializeObjectAsync<MasteryStatic>(json); Cache.Add<MasteryStaticWrapper>(MasteryCacheKey + masteryId , new MasteryStaticWrapper(mastery, language, masteryData)); return mastery; } } }
/// <summary> /// Get an item asynchronously. /// </summary> /// <param name="region">Region from which to retrieve the data.</param> /// <param name="itemId">Id of the item to retrieve.</param> /// <param name="itemData">Data to retrieve.</param> /// <param name="language">Language of the data to be retrieved.</param> /// <returns>An item.</returns> public async Task<ItemStatic> GetItemAsync(Region region, int itemId, ItemData itemData = ItemData.none , Language language = Language.en_US) { var wrapper = Cache.Get<ItemStaticWrapper>(ItemCacheKey + itemId); if (wrapper != null && wrapper.Language == language && wrapper.ItemData == itemData) { return wrapper.ItemStatic; } else { var listWrapper = Cache.Get<ItemListStaticWrapper>(ItemsCacheKey); if (listWrapper != null && listWrapper.Language == language && listWrapper.ItemData == itemData) { if (listWrapper.ItemListStatic.Items.ContainsKey(itemId)) { return listWrapper.ItemListStatic.Items[itemId]; } else { return null; } } else { var json = await requester.CreateRequestAsync(string.Format(ItemRootUrl, region.ToString()) + string.Format(IdUrl, itemId) , new List<string>() { string.Format("locale={0}", language.ToString()) , itemData == ItemData.none ? string.Empty : string.Format("itemData={0}", itemData.ToString()) }); var item = await JsonConvert.DeserializeObjectAsync<ItemStatic>(json); Cache.Add<ItemStaticWrapper>(ItemCacheKey + itemId, new ItemStaticWrapper(item, language, itemData)); return item; } } }
/// <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<MasteryListStaticWrapper>(MasteriesCacheKey); if (wrapper == null || language != wrapper.Language || masteryData != wrapper.MasteryData) { var json = await requester.CreateRequestAsync(string.Format(MasteryRootUrl, region.ToString()) , new List<string>() { string.Format("locale={0}", language.ToString()) , masteryData == MasteryData.none ? string.Empty : string.Format("masteryListData={0}", masteryData.ToString()) }); var masteries = await JsonConvert.DeserializeObjectAsync<MasteryListStatic>(json); wrapper = new MasteryListStaticWrapper(masteries, language, masteryData); Cache.Add<MasteryListStaticWrapper>(MasteriesCacheKey, wrapper); } return wrapper.MasteryListStatic; }
/// <summary> /// Get the teams for the specified ids asynchronously. /// </summary> /// <param name="region">Region in which the teams are located.</param> /// <param name="teamIds">List of string of the teams' ids.</param> /// <returns>A map of teams indexed by their id.</returns> public async Task<Dictionary<string, TeamEndpoint.Team>> GetTeamsAsync(Region region, List<string> teamIds) { var json = await requester.CreateRequestAsync( string.Format(TeamRootUrl, region.ToString()) + string.Format(IdUrl, Util.BuildNamesString(teamIds)), region); return await Task.Factory.StartNew(() => JsonConvert.DeserializeObject<Dictionary<string, TeamEndpoint.Team>>(json)); }
/// <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; }
/// <summary> /// Get a list of all summoner spells asynchronously. /// </summary> /// <param name="region">Region from which to retrieve the data.</param> /// <param name="summonerSpellData">Data to retrieve.</param> /// <param name="language">Language of the data to be retrieved.</param> /// <returns>A SummonerSpellListStatic object containing all summoner spells.</returns> public async Task<SummonerSpellListStatic> GetSummonerSpellsAsync(Region region , SummonerSpellData summonerSpellData = SummonerSpellData.none, Language language = Language.en_US) { var wrapper = Cache.Get<SummonerSpellListStaticWrapper>(SummonerSpellsCacheKey); if (wrapper == null || wrapper.Language != language || wrapper.SummonerSpellData != summonerSpellData) { var json = await requester.CreateRequestAsync(string.Format(SummonerSpellRootUrl, region.ToString()) , new List<string>() { string.Format("locale={0}", language.ToString()) , summonerSpellData == SummonerSpellData.none ? string.Empty : string.Format("spellData={0}", summonerSpellData.ToString()) }); var spells = await JsonConvert.DeserializeObjectAsync<SummonerSpellListStatic>(json); wrapper = new SummonerSpellListStaticWrapper(spells, language, summonerSpellData); Cache.Add<SummonerSpellListStaticWrapper>(SummonerSpellsCacheKey, wrapper); } return wrapper.SummonerSpellListStatic; }
/// <summary> /// Get a summoner spell asynchronously. /// </summary> /// <param name="region">Region from which to retrieve the data.</param> /// <param name="summonerSpell">Summoner spell to retrieve.</param> /// <param name="summonerSpellData">Data to retrieve.</param> /// <param name="language">Language of the data to be retrieved.</param> /// <returns>A summoner spell.</returns> public async Task<SummonerSpellStatic> GetSummonerSpellAsync(Region region, SummonerSpell summonerSpell , SummonerSpellData summonerSpellData = SummonerSpellData.none, Language language = Language.en_US) { var wrapper = Cache.Get<SummonerSpellStaticWrapper>(SummonerSpellCacheKey + summonerSpell.ToCustomString()); if (wrapper != null && wrapper.SummonerSpellData == summonerSpellData && wrapper.Language == language) { return wrapper.SummonerSpellStatic; } else { var listWrapper = Cache.Get<SummonerSpellListStaticWrapper>(SummonerSpellsCacheKey); if (listWrapper != null && listWrapper.SummonerSpellData == summonerSpellData && listWrapper.Language == language) { if (listWrapper.SummonerSpellListStatic.SummonerSpells.ContainsKey(summonerSpell.ToCustomString())) { return listWrapper.SummonerSpellListStatic.SummonerSpells[summonerSpell.ToCustomString()]; } else { return null; } } else { var json = await requester.CreateRequestAsync(string.Format(SummonerSpellRootUrl, region.ToString()) + string.Format(IdUrl, (int)summonerSpell) , new List<string>() { string.Format("locale={0}", language.ToString()) , summonerSpellData == SummonerSpellData.none ? string.Empty : string.Format("spellData={0}", summonerSpellData.ToString()) }); var spell = await JsonConvert.DeserializeObjectAsync<SummonerSpellStatic>(json); Cache.Add<SummonerSpellStaticWrapper>(SummonerSpellCacheKey + summonerSpell.ToCustomString() , new SummonerSpellStaticWrapper(spell, language, summonerSpellData)); return spell; } } }
/// <summary> /// Retrieves the entire leagues for the specified teams asynchronously. /// </summary> /// <param name="region">Region in which you wish to look for the leagues of teams.</param> /// <param name="teamIds">The team ids.</param> /// <returns>A map of list of entire leagues indexed by the team id.</returns> public async Task<Dictionary<string, List<League>>> GetEntireLeaguesAsync(Region region, List<string> teamIds) { var json = await requester.CreateRequestAsync( string.Format(LeagueRootUrl, region.ToString()) + string.Format(LeagueByTeamUrl, Util.BuildNamesString(teamIds)), region); return await Task.Factory.StartNew(() => JsonConvert.DeserializeObject<Dictionary<string, List<League>>>(json)); }
/// <summary> /// Retrieves the entire leagues for the specified teams. /// </summary> /// <param name="region">Region in which you wish to look for the leagues of teams.</param> /// <param name="teamIds">The team ids.</param> /// <returns>A map of list of entire leagues indexed by the team id.</returns> public Dictionary<string, List<League>> GetEntireLeagues(Region region, List<string> teamIds) { var json = requester.CreateRequest( string.Format(LeagueRootUrl, region.ToString()) + string.Format(LeagueByTeamUrl, Util.BuildNamesString(teamIds)), region); return JsonConvert.DeserializeObject<Dictionary<string, List<League>>>(json); }
/// <summary> /// Get the challenger league for a particular queue asynchronously. /// </summary> /// <param name="region">Region in which you wish to look for a challenger league.</param> /// <param name="queue">Queue in which you wish to look for a challenger league.</param> /// <returns>A league which contains all the challengers for this specific region and queue.</returns> public async Task<League> GetChallengerLeagueAsync(Region region, Queue queue) { var json = await requester.CreateRequestAsync( string.Format(LeagueRootUrl, region.ToString()) + LeagueChallengerUrl, region, new List<string> { string.Format("type={0}", queue.ToCustomString()) }); return await Task.Factory.StartNew(() => JsonConvert.DeserializeObject<League>(json)); }
/// <summary> /// Get the challenger league for a particular queue. /// </summary> /// <param name="region">Region in which you wish to look for a challenger league.</param> /// <param name="queue">Queue in which you wish to look for a challenger league.</param> /// <returns>A league which contains all the challengers for this specific region and queue.</returns> public League GetChallengerLeague(Region region, Queue queue) { var json = requester.CreateRequest( string.Format(LeagueRootUrl, region.ToString()) + LeagueChallengerUrl, region, new List<string> { string.Format("type={0}", queue.ToCustomString()) }); return JsonConvert.DeserializeObject<League>(json); }
/// <summary> /// Get the teams for the specified ids synchronously. /// </summary> /// <param name="region">Region in which the teams are located.</param> /// <param name="summonerIds">List of summoner ids</param> /// <returns>A map of teams indexed by the summoner's id.</returns> public Dictionary<long, List<TeamEndpoint.Team>> GetTeams(Region region, List<int> summonerIds) { var json = requester.CreateRequest( string.Format(TeamRootUrl, region.ToString()) + string.Format(TeamBySummonerURL, Util.BuildIdsString(summonerIds)), region); return JsonConvert.DeserializeObject<Dictionary<long, List<TeamEndpoint.Team>>>(json); }
/// <summary> /// Get the teams for the specified ids asynchronously. /// </summary> /// <param name="region">Region in which the teams are located.</param> /// <param name="summonerIds">List of summoner ids.</param> /// <returns>A map of teams indexed by their id.</returns> public async Task<Dictionary<long, List<TeamEndpoint.Team>>> GetTeamsAsync(Region region, List<int> summonerIds) { var json = await requester.CreateRequestAsync( string.Format(TeamRootUrl, region.ToString()) + string.Format(TeamBySummonerURL, Util.BuildIdsString(summonerIds)), region); return await Task.Factory.StartNew(() => JsonConvert.DeserializeObject<Dictionary<long, List<TeamEndpoint.Team>>>(json)); }
/// <summary> /// Get the teams for the specified ids synchronously. /// </summary> /// <param name="region">Region in which the teams are located.</param> /// <param name="teamIds">List of string of the teams' ids.</param> /// <returns>A map of teams indexed by their id.</returns> public Dictionary<string, TeamEndpoint.Team> GetTeams(Region region, List<string> teamIds) { var json = requester.CreateRequest( string.Format(TeamRootUrl, region.ToString()) + string.Format(IdUrl, Util.BuildNamesString(teamIds)), region); return JsonConvert.DeserializeObject<Dictionary<string, TeamEndpoint.Team>>(json); }
/// <summary> /// Get a list of all runes asynchronously. /// </summary> /// <param name="region">Region from which to retrieve the data.</param> /// <param name="runeData">Data to retrieve.</param> /// <param name="language">Language of the data to be retrieved.</param> /// <returns>A RuneListStatic object containing all runes.</returns> public async Task<RuneListStatic> GetRunesAsync(Region region, RuneData runeData = RuneData.none , Language language = Language.en_US) { var wrapper = Cache.Get<RuneListStaticWrapper>(RunesCacheKey); if (wrapper == null || language != wrapper.Language | runeData != wrapper.RuneData) { var json = await requester.CreateRequestAsync(string.Format(RuneRootUrl, region.ToString()) , new List<string>() { string.Format("locale={0}", language.ToString()) , runeData == RuneData.none ? string.Empty : string.Format("runeListData={0}", runeData.ToString()) }); var runes = await JsonConvert.DeserializeObjectAsync<RuneListStatic>(json); wrapper = new RuneListStaticWrapper(runes, language, runeData); Cache.Add<RuneListStaticWrapper>(RunesCacheKey, wrapper); } return wrapper.RuneListStatic; }
/// <summary> /// Get the mach history of a specific summoner asynchronously. /// </summary> /// <param name="region">Region in which the summoner is.</param> /// <param name="summonerId">Summoner ID for which you want to retrieve the match history.</param> /// <param name="beginIndex">The begin index to use for fetching games. /// endIndex - beginIndex has to be inferior to 15.</param> /// <param name="endIndex">The end index to use for fetching games. /// endIndex - beginIndex has to be inferior to 15.</param> /// <param name="championIds">List of champion IDs to use for fetching games.</param> /// <param name="rankedQueues">List of ranked queue types to use for fetching games. Non-ranked queue types /// will be ignored.</param> /// <returns>A list of match summaries object.</returns> public async Task<List<MatchSummary>> GetMatchHistoryAsync(Region region, long summonerId, int beginIndex = 0, int endIndex = 14, List<int> championIds = null, List<Queue> rankedQueues = null) { var addedArguments = new List<string> { string.Format("beginIndex={0}", beginIndex), string.Format("endIndex={0}", endIndex), }; if (championIds != null) { addedArguments.Add(string.Format("championIds={0}", Util.BuildIdsString(championIds))); } if (rankedQueues != null) { addedArguments.Add(string.Format("rankedQueues={0}", Util.BuildQueuesString(rankedQueues))); } var json = await requester.CreateRequestAsync( string.Format(MatchHistoryRootUrl, region.ToString()) + string.Format(IdUrl, summonerId), region, addedArguments); return await Task.Factory.StartNew(() => JsonConvert.DeserializeObject<PlayerHistory>(json).Matches); }
/// <summary> /// Get a rune asynchronously. /// </summary> /// <param name="region">Region from which to retrieve the data.</param> /// <param name="runeId">Id of the rune to retrieve.</param> /// <param name="runeData">Data to retrieve.</param> /// <param name="language">Language of the data to be retrieved.</param> /// <returns>A rune.</returns> public async Task<RuneStatic> GetRuneAsync(Region region, int runeId, RuneData runeData = RuneData.none , Language language = Language.en_US) { var wrapper = Cache.Get<RuneStaticWrapper>(RuneCacheKey + runeId); if (wrapper != null && wrapper.Language == language && wrapper.RuneData == RuneData.all) { return wrapper.RuneStatic; } else { var listWrapper = Cache.Get<RuneListStaticWrapper>(RunesCacheKey); if (listWrapper != null && listWrapper.Language == language && listWrapper.RuneData == runeData) { if (listWrapper.RuneListStatic.Runes.ContainsKey(runeId)) { return listWrapper.RuneListStatic.Runes[runeId]; } else { return null; } } else { var json = await requester.CreateRequestAsync(string.Format(RuneRootUrl, region.ToString()) + string.Format(IdUrl, runeId) , new List<string>() { string.Format("locale={0}", language.ToString()) , runeData == RuneData.none ? string.Empty : string.Format("runeData={0}", runeData.ToString()) }); var rune = await JsonConvert.DeserializeObjectAsync<RuneStatic>(json); Cache.Add<RuneStaticWrapper>(RuneCacheKey + runeId, new RuneStaticWrapper(rune, language, runeData)); return rune; } } }
/// <summary> /// Retrieves the league entries for the specified summoners asynchronously. /// </summary> /// <param name="region">Region in which you wish to look for the leagues of summoners.</param> /// <param name="summonerIds">The summoner ids.</param> /// <returns>A map of list of league entries indexed by the summoner id.</returns> public async Task<Dictionary<long, List<League>>> GetLeaguesAsync(Region region, List<int> summonerIds) { var json = await requester.CreateRequestAsync( string.Format(LeagueRootUrl, region.ToString()) + string.Format(LeagueBySummonerUrl, Util.BuildIdsString(summonerIds)) + LeagueEntryUrl, region); return await Task.Factory.StartNew(() => JsonConvert.DeserializeObject<Dictionary<long, List<League>>>(json)); }
/// <summary> /// Get match information about a specific match asynchronously. /// </summary> /// <param name="region">Region in which the match took place.</param> /// <param name="matchId">The match ID to be retrieved.</param> /// <param name="includeTimeline">Whether or not to include timeline information.</param> /// <returns>A match detail object containing information about the match.</returns> public async Task<MatchDetail> GetMatchAsync(Region region, long matchId, bool includeTimeline = false) { var json = await requester.CreateRequestAsync( string.Format(MatchRootUrl, region.ToString()) + string.Format(IdUrl, matchId), region, new List<string> { string.Format("includeTimeline={0}", includeTimeline) }); return await Task.Factory.StartNew(() => JsonConvert.DeserializeObject<MatchDetail>(json)); }
/// <summary> /// Get a champion asynchronously. /// </summary> /// <param name="region">Region from which to retrieve the data.</param> /// <param name="championId">Id of the champion to retrieve.</param> /// <param name="championData">Data to retrieve.</param> /// <param name="language">Language of the data to be retrieved.</param> /// <returns>A champion.</returns> public async Task<ChampionStatic> GetChampionAsync(Region region, int championId , ChampionData championData = ChampionData.none, Language language = Language.en_US) { var wrapper = Cache.Get<ChampionStaticWrapper>(ChampionCacheKey + championId); if (wrapper != null && wrapper.Language == language && wrapper.ChampionData == championData) { return wrapper.ChampionStatic; } else { var listWrapper = Cache.Get<ChampionListStaticWrapper>(ChampionsCacheKey); if (listWrapper != null && listWrapper.Language == language && listWrapper.ChampionData == championData) { return listWrapper.ChampionListStatic.Champions.Values .Where((c) => c.Id == championId).FirstOrDefault(); } else { var json = await requester.CreateRequestAsync(string.Format(ChampionRootUrl, region.ToString()) + string.Format(IdUrl, championId) , new List<string>() { string.Format("locale={0}", language.ToString()) , championData == ChampionData.none ? string.Empty : string.Format("champData={0}", championData.ToString()) }); var champ = await JsonConvert.DeserializeObjectAsync<ChampionStatic>(json); Cache.Add<ChampionStaticWrapper>(ChampionCacheKey + championId , new ChampionStaticWrapper(champ, language, championData)); return champ; } } }
/// <summary> /// Retrieves the entire leagues for the specified summoners. /// </summary> /// <param name="region">Region in which you wish to look for the leagues of summoners.</param> /// <param name="summonerIds">The summoner ids.</param> /// <returns>A map of list of leagues indexed by the summoner id.</returns> public Dictionary<long, List<League>> GetEntireLeagues(Region region, List<int> summonerIds) { var json = requester.CreateRequest( string.Format(LeagueRootUrl, region.ToString()) + string.Format(LeagueBySummonerUrl, Util.BuildIdsString(summonerIds)), region); return JsonConvert.DeserializeObject<Dictionary<long, List<League>>>(json); }
/// <summary> /// Get match information about a specific match synchronously. /// </summary> /// <param name="region">Region in which the match took place.</param> /// <param name="matchId">The match ID to be retrieved.</param> /// <param name="includeTimeline">Whether or not to include timeline information.</param> /// <returns>A match detail object containing information about the match.</returns> public MatchDetail GetMatch(Region region, long matchId, bool includeTimeline = false) { var json = requester.CreateRequest( string.Format(MatchRootUrl, region.ToString()) + string.Format(IdUrl, matchId), region, new List<string> { string.Format("includeTimeline={0}", includeTimeline) }); return JsonConvert.DeserializeObject<MatchDetail>(json); }