public async Task <ActionResult> Index(int teamId = 0) { try { if (teamId <= 0) { return(RedirectToAction("Index", "Home")); } TeamDetails td = new TeamDetails(); var players = await CacheUtil.GetObjectFromCache("AllPlayersList", 60, RequestsUtil.GetPlayers); td.playersList = players.Where(x => x.Value.Team != null && x.Value.Team.Id == teamId) .OrderByDescending(y => y.Value.Height_inches + y.Value.Height_feet) .ToDictionary(v => v.Key, v => v.Value); td.team = await CacheUtil.GetObjectFromCache($"Team_{teamId}", 60, () => RequestsUtil.GetTeam(teamId)); return(View(td)); } catch (Exception) { return(RedirectToAction("Index", "Error")); } }
private void LoadBoxes(string name) { RequestHandler.GetInstance().AddAction(RequestHandler.Priority.High, async() => { HttpWebRequest request = (HttpWebRequest)WebRequest .Create(RequestBuilder.SearchRequest(name)); HttpWebResponse response = await RequestsUtil.GetResponseAsync(request); if (response == null) { return(false); } Stream stream = response.GetResponseStream(); StreamReader streamReader = new StreamReader(stream); string content = streamReader.ReadToEnd(); response.Close(); JSONObject json = JSONParser.Parse(content); if (json.GetValue("success").ToString() == "false" || json.GetValue("total_count").ToString() == "0") { return(false); } var results = json.GetArray("results"); for (int i = 0; i < results.Count; i++) { var hashName = results[i]["asset_description"].GetValue("market_hash_name").ToString(); // skip keys if (hashName.Contains("Key")) { continue; } var iconUrl = results[i]["asset_description"].GetValue("icon_url").ToString(); var lootBox = LootBoxFactory.GetLootBox(hashName); lootBox.GetIcon(iconUrl, hashName); vm.AddLootBox(lootBox); } return(true); }, false); }
public MarketItemVM(IMarketItem item) { Item = item; Item.PropertyChanged += (s, e) => { if (e.PropertyName == "OnPriceLoaded") { RaisePropertyChanged(nameof(Price)); RaisePropertyChanged("OnItemLoaded"); } if (e.PropertyName == "OnIconLoaded") { RaisePropertyChanged(nameof(Icon)); } }; DoubleClick = new DelegateCommand(() => { RequestsUtil.OpenInBrowser(Item); }); Update = new DelegateCommand(() => { RaisePropertyChanged(nameof(Icon)); RaisePropertyChanged(nameof(Name)); RaisePropertyChanged(nameof(NameColor)); RaisePropertyChanged(nameof(Price)); }); Update.Execute(); }
public async Task <ActionResult> Index(int page = 1) { try { if (page < 1) { page = 1; } LoadItems(page, 25); var matches = await CacheUtil.GetObjectFromCache($"AllMatchesList_{page}", 60, () => RequestsUtil.GetAllMatches(page, 25)); var players = await CacheUtil.GetObjectFromCache("AllPlayersList", 60, RequestsUtil.GetPlayers); return(View(matches)); } catch (Exception) { return(RedirectToAction("Index", "Error")); } }
public override void LoadItems() { RequestHandler.GetInstance().AddAction(RequestHandler.Priority.Medium, () => { return(Task.Run(() => { State = LootBoxState.LoadStarted; return true; })); }, false); foreach (var description in Description) { if (description.Text.Contains("Exceedingly")) { continue; } RequestHandler.GetInstance().AddAction(RequestHandler.Priority.Medium, async() => { HttpWebRequest request = (HttpWebRequest)WebRequest .Create(RequestBuilder.SearchRequest(description.Text)); if (ProxySingleton.GetInstanceNext().CanUse) { request.Proxy = ProxySingleton.GetInstance().Proxy; } HttpWebResponse response = await RequestsUtil.GetResponseAsync(request); await Task.Delay(RequestHandler.Delay); if (response == null) { return(false); } Stream stream = response.GetResponseStream(); StreamReader streamReader = new StreamReader(stream); string content = streamReader.ReadToEnd(); response.Close(); JSONObject json = JSONParser.Parse(content); var results = json.GetArray("results"); if (results == null) { return(false); } string hashName, imageCode; IMarketItem item; for (int i = 0; i < results.Count; i++) { hashName = results[i]["asset_description"].GetValue("market_hash_name").ToString(); if (!hashName.ToLower().Contains(description.Text.ToLower()) || Items.Where(x => x.Name == hashName).Count() > 0) { continue; } item = new MarketItem(hashName); AddItem(item); imageCode = results[i]["asset_description"].GetValue("icon_url").ToString(); item.GetIcon(imageCode, hashName, Name); RaisePropertyChanged("OnItemLoaded"); } return(true); }); } RequestHandler.GetInstance().AddAction(RequestHandler.Priority.Medium, () => { return(Task.Run(() => { State = LootBoxState.ItemsLoaded; LoadPrices(); return true; })); }, false); }
public override void LoadItems() { RequestHandler.GetInstance().AddAction(RequestHandler.Priority.Medium, () => { return(Task.Run(() => { State = LootBoxState.LoadStarted; return true; })); }, false); RequestHandler.GetInstance().AddAction(RequestHandler.Priority.Medium, async() => { string skin = "D.A.R."; HttpWebRequest request = (HttpWebRequest)WebRequest .Create(RequestBuilder.SearchRequest(skin)); if (ProxySingleton.GetInstance().CanUse) { request.Proxy = ProxySingleton.GetInstance().Proxy; } HttpWebResponse response = await RequestsUtil.GetResponseAsync(request); if (response == null) { return(false); } Stream stream = response.GetResponseStream(); StreamReader streamReader = new StreamReader(stream); string content = streamReader.ReadToEnd(); response.Close(); JSONObject json = JSONParser.Parse(content); if (json.GetValue("success").ToString() == "false" || json.GetValue("total_count").ToString() == "0") { return(false); } var results = json.GetArray("results"); if (results == null) { return(false); } string hashName, imageCode; IMarketItem item; for (int i = 0; i < results.Count; i++) { hashName = results[i]["asset_description"].GetValue("market_hash_name").ToString(); if (hashName.Contains("Supply")) { continue; } item = new MarketItem(hashName); AddItem(item); imageCode = results[i]["asset_description"].GetValue("icon_url").ToString(); item.GetIcon(imageCode, hashName, Name); RaisePropertyChanged("OnItemLoaded"); } return(true); }); RequestHandler.GetInstance().AddAction(RequestHandler.Priority.Medium, () => { return(Task.Run(() => { State = LootBoxState.ItemsLoaded; LoadPrices(); return true; })); }, false); }
public LootBoxVM(ILootBox lootBox) { #region Commands init Update = new DelegateCommand(() => { RaisePropertyChanged(nameof(Icon)); RaisePropertyChanged(nameof(Name)); RaisePropertyChanged(nameof(ProfitWithBundle)); RaisePropertyChanged(nameof(ProfitWithBundleColor)); RaisePropertyChanged(nameof(ProfitWithoutBundle)); RaisePropertyChanged(nameof(ProfitWithoutBundleColor)); RaisePropertyChanged(nameof(BackgroundColor)); RaisePropertyChanged(nameof(NumItems)); RaisePropertyChanged(nameof(NumLoadedItems)); RaisePropertyChanged(nameof(NumErrors)); }); DoubleClick = new DelegateCommand(() => { RequestsUtil.OpenInBrowser(LootBox); }); #endregion LootBox = lootBox; LootBox.PropertyChanged += (s, e) => { if (e.PropertyName == nameof(ILootBox.State)) { switch (LootBox.State) { case LootBoxState.NotLoaded: break; case LootBoxState.Queue: break; case LootBoxState.DescriptionLoaded: RaisePropertyChanged("OnDescriptionLoaded"); break; case LootBoxState.LoadStarted: break; case LootBoxState.ItemsLoaded: break; case LootBoxState.PricesLoaded: break; } RaisePropertyChanged(nameof(ILootBox.State)); RaisePropertyChanged(nameof(BackgroundColor)); } if (e.PropertyName == "OnItemLoaded") { var item = LootBox.Items?.Last(); if (item != null) { MarketItemListVM.AddLootBox(item); } Update.Execute(); RaisePropertyChanged("OnItemLoaded"); } if (e.PropertyName == "OnPriceLoaded") { if (LootBox.Count > 0 && LootBox.Items.ToArray().Count(x => x.Price == 0) == 0) { if (LootBox.State != LootBoxState.PricesLoaded) { LootBox.State = LootBoxState.PricesLoaded; } } Update.Execute(); } if (e.PropertyName == "OnIconLoaded") { RaisePropertyChanged(nameof(Icon)); } }; MarketItemListVM = new MarketItemListVM(this, LootBox.Items? .Select(x => new MarketItemVM(x))); Update.Execute(); if (LootBox.State >= LootBoxState.DescriptionLoaded) { RaisePropertyChanged("OnDescriptionLoaded"); } }