/// <summary> /// Find all dig games /// </summary> /// <param name="textItemValue"> string to parse </param> private void FindAllGames(string textItemValue) { var updatedResult = string.Join(" ", textItemValue.Replace("Buy key", string.Empty).Split().Where(x => x != "")); updatedResult = updatedResult.Remove(0, updatedResult.IndexOf(' ') + 1); _page.Dispatcher.Invoke(() => DigGames.Add(updatedResult)); var price = updatedResult.Remove(0, updatedResult.IndexOf("$") + 1).Replace(".", ","); Prices.Add(Convert.ToDouble(price)); }
/// <summary> /// Clear all page /// </summary> private void Clear() { _page.Dispatcher.Invoke(() => { DigGames.Clear(); DigGamesWithCrads.Clear(); Prices.Clear(); PricesOnlyCards.Clear(); TotalSumm = 0; TotalSummWithCards = 0; AllGames = 0; AllGamesWithCards = 0; }); }
/// <summary> /// Parse needed info from DIG /// </summary> /// <param name="token"> token to check if task was cancelled </param> public void Parse(CancellationToken token) { _page.Dispatcher.Invoke(() => { DigGames.Clear(); DigGamesWithCrads.Clear(); Prices.Clear(); PricesOnlyCards.Clear(); TotalSumm = 0; TotalSummWithCards = 0; AllGames = 0; AllGamesWithCards = 0; }); for (int i = _digSettings.StartPoint; i <= _digSettings.EndPoint; i++) { var document = ParseSettingsAsync(i).Result; if (document is null) { return; } if (token.IsCancellationRequested) { return; //token.ThrowIfCancellationRequested(); } var menuItems = document.QuerySelectorAll("tr").Where(item => item.ClassName != null && item.ClassName.Contains("DIG3_14_Gray")); foreach (var item in menuItems) { FindAllGames(item.TextContent); if (item.TextContent.Contains("Yes")) { FindCardGames(item.TextContent); } } } TotalSumm = Math.Round(Prices.Sum(), 3); AllGames = DigGames.Count; TotalSummWithCards = Math.Round(PricesOnlyCards.Sum(), 3); AllGamesWithCards = DigGamesWithCrads.Count; /// write into helper class amount and values ViewModelHelper.AllGamesHelper = AllGames; ViewModelHelper.AllGamesCardsHelper = AllGamesWithCards; ViewModelHelper.AllGamesPriceHelper = TotalSumm; ViewModelHelper.AllGamesPriceCardsHelper = TotalSummWithCards; var nameDigGames = new ObservableCollection <string>(); var nameDigGamesWithCards = new ObservableCollection <string>(); foreach (var item in DigGames) { nameDigGames.Add(item.Remove(item.LastIndexOf("STEAM")).TrimEnd()); } foreach (var item in DigGamesWithCrads) { var temp = item.Remove(item.LastIndexOf("STEAM")).TrimEnd(); if (temp.Contains("Yes")) { temp = item.Remove(item.LastIndexOf("Yes")).TrimEnd(); } nameDigGamesWithCards.Add(temp); } ViewModelHelper.DigGames.Clear(); ViewModelHelper.DigGamesWithCards.Clear(); ViewModelHelper.PricesAll.Clear(); ViewModelHelper.PricesWithCards.Clear(); foreach (var item in nameDigGames) { ViewModelHelper.DigGames.Add(item); } foreach (var item in nameDigGamesWithCards) { ViewModelHelper.DigGamesWithCards.Add(item); } foreach (var item in Prices) { ViewModelHelper.PricesAll.Add(item); } foreach (var item in PricesOnlyCards) { ViewModelHelper.PricesWithCards.Add(item); } CanCloseGetAll = true; CanCloseClear = true; }