public async Task UploadToClient(ILogin login, IItemsSets itemSets)
        {
            var session = await login.GetSessionAsync();

            bool saveToConfig = !Config.Current.KeepItemSets;

            if (this.Name.Contains("{0}"))
            {
                this.Name = string.Format(this.Name, Riot.GetChampion(Champion).Name);
            }

            var itemSet = new LolItemSetsItemSet
            {
                map                 = "any",
                mode                = "any",
                startedFrom         = "blank",
                type                = "custom",
                associatedChampions = new[] { Champion },
                title               = Name,
                blocks              = Blocks.Select(o => new LolItemSetsItemSetBlock
                {
                    items = o.Items.Select(i => new LolItemSetsItemSetItem {
                        id = i.ToString(), count = 1
                    }).ToArray(),
                    type = o.Name
                }).ToArray(),
                uid = Guid.NewGuid().ToString()
            };

            LogTo.Debug($"Uploading item set with title '{itemSet.title}' ('{this.Name}' in model)");

            var currentSetInfo = await itemSets.GetItemSets(session.summonerId);

            var currentSetsList = currentSetInfo.itemSets.ToList();

            currentSetsList.Add(itemSet);

            if (saveToConfig && Config.Current.LastItemSetUid != null)
            {
                LogTo.Debug("Deleting last item set with ID {0}", Config.Current.LastItemSetUid);
                currentSetsList.RemoveAll(o => o.uid == Config.Current.LastItemSetUid);
            }

            if (saveToConfig)
            {
                Config.Current.LastItemSetUid = itemSet.uid;
                Config.Current.Save();
            }

            currentSetInfo.itemSets  = currentSetsList.ToArray();
            currentSetInfo.timestamp = (long)DateTime.Now.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds;

            await itemSets.PutItemSets(session.summonerId, currentSetInfo);
        }
Exemple #2
0
        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;
                }
            }
        }
Exemple #3
0
        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;
                }
            }
        }