private static async Task <bool> GetProps(string accName, string league) { //Trace.WriteLine(IsFetching, "isfetching props"); if (IsFetching) { return(false); } if (Properties.Settings.Default.SessionId == "") { MessageBox.Show("Missing Settings!" + Environment.NewLine + "Please set PoE Session Id."); return(false); } // check rate limit if (RateLimit.CheckForBan()) { return(false); } // -1 for 1 request + 3 times if ratelimit high exceeded if (RateLimit.RateLimitState[0] >= RateLimit.MaximumRequests - 4) { RateLimit.RateLimitExceeded = true; return(false); } IsFetching = true; Uri propsUri = new Uri($"https://www.pathofexile.com/character-window/get-stash-items?accountName={accName}&tabs=1&league={league}"); string sessionId = Properties.Settings.Default.SessionId; var cC = new CookieContainer(); cC.Add(propsUri, new Cookie("POESESSID", sessionId)); using (var handler = new HttpClientHandler() { CookieContainer = cC }) using (HttpClient client = new HttpClient(handler)) { //Trace.WriteLine("is here"); // add user agent client.DefaultRequestHeaders.Add("User-Agent", $"EnhancePoEApp/v{Assembly.GetExecutingAssembly().GetName().Version}"); using (HttpResponseMessage res = await client.GetAsync(propsUri)) { //Trace.WriteLine("is NOT here"); if (res.IsSuccessStatusCode) { //Trace.WriteLine("is not herre"); using (HttpContent content = res.Content) { string resContent = await content.ReadAsStringAsync(); //Trace.Write(resContent); PropsList = JsonSerializer.Deserialize <StashTabPropsList>(resContent); Trace.WriteLine(res.Headers, "res headers"); // get new rate limit values //RateLimit.IncreaseRequestCounter(); string rateLimit = res.Headers.GetValues("X-Rate-Limit-Account").FirstOrDefault(); string rateLimitState = res.Headers.GetValues("X-Rate-Limit-Account-State").FirstOrDefault(); string responseTime = res.Headers.GetValues("Date").FirstOrDefault(); RateLimit.DeserializeRateLimits(rateLimit, rateLimitState); RateLimit.DeserializeResponseSeconds(responseTime); } } else { System.Windows.MessageBox.Show(res.ReasonPhrase, "Error fetching data", MessageBoxButton.OK, MessageBoxImage.Error); FetchError = true; return(false); } } } //await Task.Delay(1000); IsFetching = false; return(true); }
public async static Task <bool> GetItems() { if (IsFetching) { Trace.WriteLine("already fetching"); return(false); } if (Properties.Settings.Default.SessionId == "") { MessageBox.Show("Missing Settings!" + Environment.NewLine + "Please set PoE Session Id."); return(false); } if (FetchError) { return(false); } // check rate limit if (RateLimit.RateLimitState[0] >= RateLimit.MaximumRequests - StashTabList.StashTabs.Count - 4) { RateLimit.RateLimitExceeded = true; return(false); } IsFetching = true; List <Uri> usedUris = new List <Uri>(); string sessionId = Properties.Settings.Default.SessionId; var cookieContainer = new CookieContainer(); using (var handler = new HttpClientHandler() { CookieContainer = cookieContainer }) using (HttpClient client = new HttpClient(handler)) { // add user agent client.DefaultRequestHeaders.Add("User-Agent", $"EnhancePoEApp/v{Assembly.GetExecutingAssembly().GetName().Version}"); foreach (StashTab i in StashTabList.StashTabs) { // check rate limit ban if (RateLimit.CheckForBan()) { return(false); } if (!usedUris.Contains(i.StashTabUri)) { cookieContainer.Add(i.StashTabUri, new Cookie("POESESSID", sessionId)); using (HttpResponseMessage res = await client.GetAsync(i.StashTabUri)) { usedUris.Add(i.StashTabUri); if (res.IsSuccessStatusCode) { using (HttpContent content = res.Content) { // get new rate limit values //RateLimit.IncreaseRequestCounter(); string rateLimit = res.Headers.GetValues("X-Rate-Limit-Account").FirstOrDefault(); string rateLimitState = res.Headers.GetValues("X-Rate-Limit-Account-State").FirstOrDefault(); string responseTime = res.Headers.GetValues("Date").FirstOrDefault(); RateLimit.DeserializeRateLimits(rateLimit, rateLimitState); RateLimit.DeserializeResponseSeconds(responseTime); // deserialize response string resContent = await content.ReadAsStringAsync(); ItemList deserializedContent = JsonSerializer.Deserialize <ItemList>(resContent); i.ItemList = deserializedContent.items; i.Quad = deserializedContent.quadLayout; i.CleanItemList(); } } else { FetchError = true; System.Windows.MessageBox.Show(res.ReasonPhrase, "Error fetching data", MessageBoxButton.OK, MessageBoxImage.Error); return(false); } } } //await Task.Delay(1000); } } IsFetching = false; FetchingDone = true; return(true); }
private static async Task <bool> GetProps(string accName, string league) { if (IsFetching) { return(false); } if (Settings.Default.SessionId == "") { MessageBox.Show("Missing Settings!" + Environment.NewLine + "Please set PoE Session Id."); return(false); } // check rate limit if (RateLimit.CheckForBan()) { return(false); } // -1 for 1 request + 3 times if rate limit high exceeded if (RateLimit.CurrentRequests >= RateLimit.MaximumRequests - 4) { RateLimit.RateLimitExceeded = true; return(false); } IsFetching = true; var propsUri = new Uri($"https://www.pathofexile.com/character-window/get-stash-items?accountName={accName}&tabs=1&league={league}"); var sessionId = Settings.Default.SessionId; var cC = new CookieContainer(); cC.Add(propsUri, new Cookie("POESESSID", sessionId)); using (var handler = new HttpClientHandler { CookieContainer = cC }) using (var client = new HttpClient(handler)) { // add user agent client.DefaultRequestHeaders.Add("User-Agent", $"EnhancePoEApp/v{Assembly.GetExecutingAssembly().GetName().Version}"); using (var res = await client.GetAsync(propsUri)) { if (res.IsSuccessStatusCode) { using (var content = res.Content) { var resContent = await content.ReadAsStringAsync(); PropsList = JsonSerializer.Deserialize <StashTabPropsList>(resContent); Trace.WriteLine(res.Headers, "res headers"); // get new rate limit values var rateLimit = res.Headers.GetValues("X-Rate-Limit-Account").FirstOrDefault(); var rateLimitState = res.Headers.GetValues("X-Rate-Limit-Account-State").FirstOrDefault(); var responseTime = res.Headers.GetValues("Date").FirstOrDefault(); RateLimit.DeserializeRateLimits(rateLimit, rateLimitState); RateLimit.DeserializeResponseSeconds(responseTime); } } else { MessageBox.Show(res.StatusCode == HttpStatusCode.Forbidden ? "Connection forbidden. Please check your account name and POE Session ID. You may have to refresh your POE Session ID sometimes." : res.ReasonPhrase, "Error fetching data", MessageBoxButton.OK, MessageBoxImage.Error); FetchError = true; return(false); } } } IsFetching = false; return(true); }