Exemplo n.º 1
0
        public void DeletePage()
        {
            if (DeleteCheck.Checked)
            {
                http = new HttpClient();
                EasyHttp.Http.HttpResponse response = null;
                try
                {
                    http.Request.Accept         = HttpContentTypes.ApplicationJson;
                    http.Request.ForceBasicAuth = true;
                    http.Request.SetBasicAuthentication("riot", token);
                    response = http.Get("https://127.0.0.1:" + port + "/lol-perks/v1/currentpage");
                }
                catch (Exception e) // lol client closed / reopened
                {
                    Leagueconnect();
                    http.Request.Accept         = HttpContentTypes.ApplicationJson;
                    http.Request.ForceBasicAuth = true;
                    http.Request.SetBasicAuthentication("riot", token);
                    response = http.Get("https://127.0.0.1:" + port + "/lol-perks/v1/currentpage");
                }
                var currentpage = response.DynamicBody;

                int deleteid = currentpage.id;

                if (deleteid == 54 || deleteid == 53 || deleteid == 52 || deleteid == 51 || deleteid == 50)
                {
                    MessageBox.Show("Cant Delete Pages, Looks like its only Riots default pages left, if you know this is wrong, click the page once so it gets set to current.");
                }
                else
                {
                    http.Delete("https://127.0.0.1:" + port + "/lol-perks/v1/pages/" + deleteid);
                }
            }
        }
 /// <summary>
 /// <para>If the <paramref name="response"/> is OK (see <see cref="IsHttpError"/> for definition), does nothing.</para>
 /// <para>Otherwise, throws an exception which includes also the response raw text.
 /// This would often contain a Java exception dump from the TeamCity REST Plugin, which reveals the cause of some cryptic cases otherwise showing just "Bad Request" in the HTTP error.
 /// Also this comes in handy when TeamCity goes into maintenance, and you get back the banner in HTML instead of your data.</para>
 /// </summary>
 private static void ThrowIfHttpError(HttpResponse response, string url)
 {
     if (!IsHttpError(response))
     {
         return;
     }
     throw new HttpException(response.StatusCode, string.Format("Error: {0}\nHTTP: {3}\nURL: {1}\n{2}", response.StatusDescription, url, response.RawText, response.StatusCode));
 }
Exemplo n.º 3
0
 /// <summary>
 /// <para>If the <paramref name="response"/> is OK (see <see cref="IsHttpError"/> for definition), does nothing.</para>
 /// <para>Otherwise, throws an exception which includes also the response raw text.
 /// This would often contain a Java exception dump from the TeamCity REST Plugin, which reveals the cause of some cryptic cases otherwise showing just "Bad Request" in the HTTP error.
 /// Also this comes in handy when TeamCity goes into maintenance, and you get back the banner in HTML instead of your data.</para>
 /// </summary>
 private static void ThrowIfHttpError(HttpResponse response, string url)
 {
     if (!IsHttpError(response))
     {
         return;
     }
     throw new HttpException(response.StatusCode,
                             $"Error: {response.StatusDescription}\nHTTP: {response.StatusCode}\nURL: {url}\n{response.RawText}");
 }
Exemplo n.º 4
0
        private bool IsHttpError(HttpResponse response)
        {
            var num = (int)response.StatusCode / 100;

            return(num == 4 || num == 5);
        }
Exemplo n.º 5
0
        private void Runebtn_Click(object sender, EventArgs e)
        {
            DeletePage();
            if (Pagebox.SelectedItem == null)
            {
                Pagebox.SelectedIndex = 0;
            }
            var selectedPage = Pagebox.SelectedItem.ToString();
            var index        = Pagebox.SelectedIndex;

            Champion     c            = champs.Find(x => x.Champname == Champbox.SelectedValue.ToString());
            List <Pages> runes        = Pagelist.FindAll(p => p.Id == c.Id);
            Pages        correctrunes = runes[index];

            try
            {
                long   Runestart = correctrunes.RuneStart;
                string name      = correctrunes.PageName;
                long   rune1     = correctrunes.Rune1;
                long   rune2     = correctrunes.Rune2;
                long   rune3     = correctrunes.Rune3;
                long   rune4     = correctrunes.Rune4;
                long   rune5     = correctrunes.Rune5;
                long   rune6     = correctrunes.Rune6;
                long   rune7     = correctrunes.Rune7;
                long   rune8     = correctrunes.Rune8;
                long   rune9     = correctrunes.Rune9;
                long   secondary = correctrunes.RuneSecondary;

                var inputLCUx = @"{""current"": true, ""name"":""" + name + "\",\"primaryStyleId\":" + Runestart + ",\"selectedPerkIds\": [" +
                                rune1 + "," + rune2 + "," + rune3 + "," + rune4 + "," + rune5 + "," + rune6 + "," + rune7 + "," + rune8 + "," + rune9 +
                                "],\"subStyleId\":" + secondary + "}";

                EasyHttp.Http.HttpResponse response = null;
                try
                {
                    string password = token;

                    http.Request.Accept = HttpContentTypes.ApplicationJson;
                    http.Request.SetBasicAuthentication("riot", password);

                    response = http.Post("https://127.0.0.1:" + port + "/lol-perks/v1/pages", inputLCUx, HttpContentTypes.ApplicationJson);
                }
                catch (Exception e2)
                {
                    Leagueconnect();
                    string password = token;

                    http.Request.Accept = HttpContentTypes.ApplicationJson;
                    http.Request.SetBasicAuthentication("riot", password);

                    response = http.Post("https://127.0.0.1:" + port + "/lol-perks/v1/pages", inputLCUx, HttpContentTypes.ApplicationJson);
                }
                if (response.StatusCode != System.Net.HttpStatusCode.OK)
                {
                    var error = response.StaticBody <Error>();
                    if (error.message.Equals("Max pages reached"))
                    {
                        MessageBox.Show("Max Pages Reached");
                    }
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }