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 static Task <ResultCheckItem> CheckLastItem(string link) { string response = await CookieClient.GetHttpAsync(link); if (response != "") { InventoryResponse resp = JsonConvert.DeserializeObject <InventoryResponse>(response); if (resp != null) { if (resp.success) { if (resp.dicInventory.Count > 0) { foreach (var item in resp.dicInventory) { if (item.Value.pos == 1) { var firstDsc = resp.dicDescriptions[$"{item.Value.classid}_{item.Value.instanceid}"]; return(new ResultCheckItem() { itemId = item.Value.id, picUrl = $"http://steamcommunity-a.akamaihd.net/economy/image/{firstDsc.icon_url}/96fx96f", itemName = $"{firstDsc.name}", error = "" }); } } } else { return(new ResultCheckItem() { itemId = "0", picUrl = "empty", itemName = "Empty CS:GO inventory :(", error = "" }); } } else { return(new ResultCheckItem() { itemId = "", picUrl = "", itemName = "", error = resp.Error }); } //Logger.Write($"{DateTime.Now} - Normal update - {link}{Environment.NewLine}"); } else { //Logger.Write($"{DateTime.Now} - {response} - {link}{Environment.NewLine}"); } } else { //Logger.Write($"{DateTime.Now} - Empty response {link}{Environment.NewLine}"); } return(null); }