コード例 #1
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;
        }
コード例 #2
0
        /// <summary>
        /// Get information abount all available games with cards
        /// </summary>
        public void GetAvailableGamesCardsInfo()
        {
            var isContinueGames = _parseService.GetUserGamesInfo();

            _page.Dispatcher.Invoke(() =>
            {
                if (UserName is null)
                {
                    MessageBox.Show("No entered user", "No user error");
                    return;
                }

                if (ViewModelHelper.DigGames.Count != 0)
                {
                    var tempList = ViewModelHelper.DigGamesWithCards
                                   .Where(item => !UserGames.Contains(item))
                                   .ToList();

                    TempList = tempList;

                    var twmpList = new int[ViewModelHelper.DigGamesWithCards.Count];

                    for (int i = 0; i < ViewModelHelper.DigGamesWithCards.Count; i++)
                    {
                        if (!UserGames.Any(x => x == ViewModelHelper.DigGamesWithCards[i]))
                        {
                            twmpList[i] = i;
                        }
                        else
                        {
                            twmpList[i] = 0;
                        }
                    }

                    PricesOnlyCards.Clear();
                    PricesOnlyCards.Add(0.1);
                    for (int i = 0; i < twmpList.Length; i++)
                    {
                        if (twmpList[i] != 0)
                        {
                            PricesOnlyCards.Add(ViewModelHelper.PricesWithCards[i]);
                        }
                    }

                    GamesWithCardsSumm = Math.Round(PricesOnlyCards.Sum(), 3);

                    AmountGamesWithCards = TempList.Distinct().Count();

                    /// write user cards info into helper class

                    ViewModelHelper.AllGamesCardsUserHelper      = AmountGamesWithCards;
                    ViewModelHelper.AllGamesPriceCardsUserHelper = GamesWithCardsSumm;

                    for (var i = 0; i < TempList.Count; i++)
                    {
                        if (!UserCardGamesDict.ContainsKey(TempList[i]))
                        {
                            UserCardGamesDict.Add(TempList[i], PricesOnlyCards[i]);
                        }
                    }

                    TempList.Clear();
                    ListViewSourse.Clear();

                    foreach (var item in UserCardGamesDict)
                    {
                        ListViewSourse.Add($"Game: {item.Key} | Price: ${item.Value}");
                    }

                    CanCloseSaveCards = true;
                }

                else
                {
                    MessageBox.Show("No games from DIG", "No dig games error");
                    return;
                }
            });
        }