예제 #1
0
    string buildOtherRunePagesFromFile(SummonerDto summoner)
    {
        string[] lines = SummonerDataManager.ReadRuneTotals(summoner, regionRadioList.SelectedValue, Server);

        StringBuilder sb = new StringBuilder();

        for (int i = 2; i < lines.Length; i += 2)
        {
            if (lines[i + 1] != "")
            {
                sb.Append("<span class=\"PageName\">");
                sb.Append(lines[i]);
                sb.Append("</span><br/><br/>");

                sb.Append("<span class=\"RuneTotals\">");
                sb.Append(lines[i + 1]);
                sb.Append("</span><br/><br/>");
            }
        }

        if (sb.Length > 10)
        {
            sb.Remove(sb.Length - 10, 10);
        }

        if (sb.Length == 0)
        {
            sb.Append("<span class=\"PageName\">none</span><br/>");
        }

        return(sb.ToString());
    }
예제 #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            HttpCookie region = Request.Cookies.Get("region");
            if (region != null)
            {
                foreach (ListItem item in regionRadioList.Items)
                {
                    if (item.Value == region.Value)
                    {
                        item.Selected = true;
                        break;
                    }
                }
            }

            HttpCookie showCurrent = Request.Cookies.Get("showCurrent");
            if (showCurrent != null)
            {
                currentCheckBox.Checked = bool.Parse(showCurrent.Value);
            }

            //SummonerDataManager.ClearCache(Server);
            greetingLabel.Style.Add(HtmlTextWriterStyle.Display, "inline");
        }
        else
        {
            greetingLabel.Style.Add(HtmlTextWriterStyle.Display, "none");
        }

        long cacheSize = (SummonerDataManager.CacheSize(Server) / 1024);

        cacheLabel.Text = cacheSize + "kB (up to " + (long)(cacheSize * 1.75) + "kB on disk)";
    }
예제 #3
0
    string buildCurrentRunePageFromFile(SummonerDto summoner)
    {
        string[] lines = SummonerDataManager.ReadRuneTotals(summoner, regionRadioList.SelectedValue, Server);

        string str = "";

        if (lines[1] == "")
        {
            str += "<span class=\"PageName\">none</span><br/>";
        }
        else
        {
            str += "<span class=\"PageName\">" + lines[0] + "</span><br/><br/>";
            str += "<span class=\"RuneTotals\">" + lines[1] + "</span>";
        }

        return(str);
    }
예제 #4
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        playerInfoLabel.Text = resultsLabel.Text = "";

        if (!Page.IsValid)
        {
            return;
        }

        HttpResponseMessage response = client.GetAsync("https://prod.api.pvp.net/api/lol/" + regionRadioList.SelectedItem.Value.ToLower() + "/v1.2/summoner/by-name/" + nameTxtBox.Text + "?api_key=995d135e-ab6f-4412-bb3c-1bbcd217c252").Result;

        SummonerDto summonerDto;
        bool        hasSummonerChanged;

        if (response.StatusCode == HttpStatusCode.OK)
        {
            summonerDto = response.Content.ReadAsAsync <SummonerDto>().Result;

            Header.Title = summonerDto.name + "'s runes/masteries.";

            idHiddenField.Value = summonerDto.id.ToString();
            showPlayerInfo(summonerDto);

            hasSummonerChanged = SummonerDataManager.HasSummonerChanged(summonerDto, regionRadioList.SelectedValue, Server);
            SummonerDataManager.WriteSummonerInfoFile(summonerDto, regionRadioList.SelectedValue, Server);
        }
        else
        {
            playerInfoLabel.Text = "";
            if (response.StatusCode.ToString() == "NotFound")
            {
                resultsLabel.Text = "<br/><br/><div style=\"width: 250px; margin: auto\" class=\"errorMessage\">Summoner not found</div>";
            }
            else if (response.StatusCode.ToString() == "429")
            {
                resultsLabel.Text = "<br/><br/><div style=\"width: 250px; margin: auto\" class=\"errorMessage\">Too many requests</div>";
            }
            else
            {
                resultsLabel.Text = "<br/><br/><div style=\"width: 250px; margin: auto\" class=\"errorMessage\">Error: " + response.StatusCode + "</div>";
            }
            return;
        }

        // get rune pages
        RunePagesDto        runePages;
        RunePagesDtoManager runePagesManager;
        string currentRunes = "", otherRunes = "";

        if (hasSummonerChanged)
        {
            response = client.GetAsync("https://prod.api.pvp.net/api/lol/" + regionRadioList.SelectedItem.Value.ToLower() + "/v1.2/summoner/" + summonerDto.id + "/runes?api_key=995d135e-ab6f-4412-bb3c-1bbcd217c252").Result;

            if (response.StatusCode == HttpStatusCode.OK)
            {
                runePages        = response.Content.ReadAsAsync <RunePagesDto>().Result;
                runePagesManager = new RunePagesDtoManager(runePages);

                currentRunes = buildCurrentRunePage(runePagesManager);
                otherRunes   = buildOtherRunePages(runePagesManager);

                SummonerDataManager.WriteRuneTotals(summonerDto, runePagesManager, regionRadioList.SelectedValue, Server);
            }
            else
            {
                currentRunes = otherRunes = "<span style=\"color: red\"Runes error: " + response.StatusCode + "</span>";
                SummonerDataManager.ResetSummonerRevisionDate(summonerDto, regionRadioList.SelectedValue, Server);
            }
        }
        else
        {
            if (SummonerDataManager.RunesFileExists(summonerDto, regionRadioList.SelectedValue, Server))
            {
                currentRunes = buildCurrentRunePageFromFile(summonerDto);
                otherRunes   = buildOtherRunePagesFromFile(summonerDto);
            }
            else
            {
                currentRunes = otherRunes = "<span style=\"color: red\">Runes error: cache error. just search again</span>";
            }
        }


        // get mastery pages
        MasteryPagesDto masteryPages;
        string          currentMasteries = "", otherMasteries = "";

        if (hasSummonerChanged)
        {
            response = client.GetAsync("https://prod.api.pvp.net/api/lol/" + regionRadioList.SelectedItem.Value.ToLower() + "/v1.2/summoner/" + summonerDto.id + "/masteries?api_key=995d135e-ab6f-4412-bb3c-1bbcd217c252").Result;

            if (response.StatusCode == HttpStatusCode.OK)
            {
                masteryPages = response.Content.ReadAsAsync <MasteryPagesDto>().Result;

                masteryPages.DoAllCalculations();

                currentMasteries = buildCurrentMasteryPage(masteryPages);
                otherMasteries   = buildOtherMasteryPages(masteryPages);

                SummonerDataManager.WriteSummonerMasteriesFile(summonerDto, masteryPages, regionRadioList.SelectedValue, Server);
            }
            else
            {
                currentMasteries = otherMasteries = "<span style=\"color: red\">Masteries error: " + response.StatusCode + "</span>";
                SummonerDataManager.ResetSummonerRevisionDate(summonerDto, regionRadioList.SelectedValue, Server);
            }
        }
        else
        {
            if (SummonerDataManager.MasteriesFileExists(summonerDto, regionRadioList.SelectedValue, Server))
            {
                masteryPages     = SummonerDataManager.ReadSummonerMasteriesFile(summonerDto, regionRadioList.SelectedValue, Server);
                currentMasteries = buildCurrentMasteryPage(masteryPages);
                otherMasteries   = buildOtherMasteryPages(masteryPages);
            }
            else
            {
                currentMasteries = otherMasteries = "<span style=\"color: red\">Masteries error: cache error. just search again</span>";
                SummonerDataManager.ResetSummonerRevisionDate(summonerDto, regionRadioList.SelectedValue, Server);
            }
        }

        showCombinedCurrentTable(currentRunes, currentMasteries);

        showCombinedOtherTable(otherRunes, otherMasteries);

        setCookies();
    }