public static async Task <string> GetHttpAsync(string url, int count = 3) { while (true) { var client = new CookieClient(); var content = string.Empty; try { // If user is NOT authenticated (cookie got deleted in GetWebResponse()), return empty result if (String.IsNullOrEmpty(Settings.Default.sessionid)) { return(string.Empty); } content = await client.DownloadStringTaskAsync(url); } catch (Exception ex) { Logger.Exception(ex, "CookieClient -> GetHttpAsync, for url = " + url); } if (!string.IsNullOrWhiteSpace(content) || count == 0) { return(content); } count = count - 1; } }
public async Task <bool> CanCardDrops() { try { var document = new HtmlDocument(); var response = await CookieClient.GetHttpAsync(Settings.Default.myProfileURL + "/gamecards/" + StringId); // Response should be empty. User should be unauthorised. if (string.IsNullOrEmpty(response)) { return(false); } document.LoadHtml(response); var hoursNode = document.DocumentNode.SelectSingleNode("//div[@class=\"badge_title_stats_playtime\"]"); var hours = Regex.Match(hoursNode.InnerText, @"[0-9\.,]+").Value; var cardNode = hoursNode.ParentNode.SelectSingleNode(".//span[@class=\"progress_info_bold\"]"); var cards = cardNode == null ? string.Empty : Regex.Match(cardNode.InnerText, @"[0-9]+").Value; UpdateStats(cards, hours); return(RemainingCard != 0); } catch (Exception ex) { Logger.Exception(ex, "Badge -> CanCardDrops, for id = " + AppId); } return(false); }
private async Task CheckAndSave() { try { Settings.Default.sessionid = txtSessionID.Text.Trim(); Settings.Default.steamLogin = txtSteamLogin.Text.Trim(); Settings.Default.myProfileURL = SteamProfile.GetSteamUrl(); Settings.Default.steamparental = txtSteamParental.Text.Trim(); if (await CookieClient.IsLogined()) { Settings.Default.Save(); Close(); return; } } catch (Exception ex) { Logger.Exception(ex, "frmSettingsAdvanced -> CheckAndSave"); } // Invalid cookie data, reset the form btnUpdate.Text = localization.strings.update; txtSessionID.Text = ""; txtSteamLogin.Text = ""; txtSteamParental.Text = ""; txtSessionID.PasswordChar = '\0'; txtSteamLogin.PasswordChar = '\0'; txtSteamParental.PasswordChar = '\0'; txtSessionID.Enabled = true; txtSteamLogin.Enabled = true; txtSteamParental.Enabled = true; txtSessionID.Focus(); MessageBox.Show(localization.strings.validate_failed); btnUpdate.Enabled = true; }