public static async Task <RunePage> GetActivePageFromClient(IPerks perks) { var page = await perks.GetCurrentPageAsync(); return(new RunePage(page.selectedPerkIds, page.primaryStyleId, page.subStyleId, 0, Position.Fill) { Name = page.name }); }
public async Task UploadToClient(IPerks perks) { if (!GameState.CanUpload) { return; } VerifyRunes(); var page = new LolPerksPerkPageResource { primaryStyleId = PrimaryTree, subStyleId = SecondaryTree, selectedPerkIds = RuneIDs, name = this.Name ?? Riot.GetChampion(ChampionID).Name + " - " + Enum.GetName(typeof(Position), Position) }; LogTo.Debug("Uploading rune page with name '{0}' and runes [ {1} ]", page.name, string.Join(", ", RuneIDs)); if (Config.Current.LastRunePageId != default) { try { await perks.DeletePageAsync(Config.Current.LastRunePageId); } catch { } } try { var pageRet = await perks.PostPageAsync(page); Config.Current.LastRunePageId = pageRet.id; } catch (APIErrorException ex) when(ex.Message == "Max pages reached") { LogTo.Info("Max number of rune pages reached, deleting current page and trying again"); var currentPage = await perks.GetCurrentPageAsync(); if (currentPage.isDeletable) { await perks.DeletePageAsync(currentPage.id); await UploadToClient(perks); } else { MainWindow.ShowNotification(Text.CantUploadPageTitle, Text.CantUploadPageMessage); return; } } }
public async Task UploadToClient(IPerks perks) { if (!GameState.CanUpload) { return; } var page = new LolPerksPerkPageResource { primaryStyleId = PrimaryTree, subStyleId = SecondaryTree, selectedPerkIds = RuneIDs, name = this.Name ?? (await Riot.GetChampion(ChampionID)).Name + " - " + Enum.GetName(typeof(Position), Position) }; LogTo.Debug("Uploading rune page with name '{0}' and runes [ {1} ]", page.name, string.Join(", ", RuneIDs)); if (Config.Current.LastRunePageId != default) { try { await perks.DeletePageAsync(Config.Current.LastRunePageId); } catch { } } try { var pageRet = await perks.PostPageAsync(page); Config.Current.LastRunePageId = pageRet.id; } catch (APIErrorException ex) when(ex.Message == "Max pages reached") { LogTo.Info("Max number of rune pages reached, deleting previous page and trying again"); var pages = await perks.GetPagesAsync(); var replacedPage = pages.FirstOrDefault(p => p.name.StartsWith(Config.Current.LockLoadProvider)); if (replacedPage == null) { replacedPage = await perks.GetCurrentPageAsync(); } if (replacedPage.isDeletable) { await perks.DeletePageAsync(replacedPage.id); await UploadToClient(perks); } else { LCUApp.MainWindow.ShowNotification("Couldn't upload rune page", "There is no room for more pages."); return; } } }