Beispiel #1
0
        public async void FullUpdateOfResults()
        {
            int            countTimeout  = 0;
            RecalledMatch  reviewedMatch = new RecalledMatch();
            Data_Organiser dor           = new Data_Organiser();
            Fixture        fixture       = new Fixture();

            using (IDbConnection conn = dor.Connection())
            {
                try
                {
                    var links = conn.Query <Team>("  SELECT * FROM [Football].[dbo].[TEAM]");
                    foreach (Team linksItem in links)
                    {
                        HttpClient httpClient = new HttpClient();
                        String     html       = await httpClient.GetStringAsync(constantUrl + linksItem.link);

                        HtmlAgilityPack.HtmlDocument htmlDocument = new HtmlAgilityPack.HtmlDocument();
                        htmlDocument.LoadHtml(html);

                        List <HtmlNode> MatchHtml = htmlDocument.DocumentNode.Descendants("tr")
                                                    .Where(node => (node.GetAttributeValue("id", "")
                                                                    .Contains("page_team_1_block_team_matches"))).ToList();

                        foreach (HtmlNode MatchListItem in MatchHtml)
                        {
                            string   date          = GetMatchData(MatchListItem).Item1;
                            DateTime evaluatedDate = Convert.ToDateTime(date);

                            string homeTeam = GetMatchData(MatchListItem).Item2;

                            string awayTeam = GetMatchData(MatchListItem).Item3;

                            string score = GetMatchData(MatchListItem).Item4;

                            string      homeScore   = "";
                            string      awayScore   = "";
                            ResultState state       = ResultState.UNDEFINED;
                            OptionState optionState = OptionState.Result;
                            string      time        = "";
                            if (dor.IsSubstringable(score, ref homeScore, ref awayScore) && score.Contains(':'))
                            {
                                optionState = OptionState.Fixture;
                                time        = score;
                                //dor.SlicingData(linksItem.country, linksItem.currentCompetition, evaluatedDate, homeTeam, awayTeam,
                                //            homeScore, awayScore, OptionState.Fixture.ToString(), score);
                                fixture.InsertFixture(linksItem.country, linksItem.currentCompetition, homeTeam, awayTeam, evaluatedDate, score);
                            }
                            else if (dor.IsSubstringable(score, ref homeScore, ref awayScore) && score.Contains('P') || score.Contains('E') || score.Contains("PSTP"))
                            {
                                state = ResultState.POSTPONED;
                                reviewedMatch.InsertRecalledMatch(linksItem.country, linksItem.currentCompetition, evaluatedDate,
                                                                  homeTeam, awayTeam, state.ToString());
                                continue;
                            }
                            else if (dor.IsSubstringable(score, ref homeScore, ref awayScore) && score == "CANC")
                            {
                                state = ResultState.CANCELLED;
                                reviewedMatch.InsertRecalledMatch(linksItem.country, linksItem.currentCompetition, evaluatedDate,
                                                                  homeTeam, awayTeam, state.ToString());
                                continue;
                            }
                            else if (dor.IsSubstringable(score, ref homeScore, ref awayScore) && dor.IsNumber(homeScore, awayScore))
                            {
                                optionState = OptionState.Result;
                                dor.SlicingData(linksItem.country, linksItem.currentCompetition, evaluatedDate, homeTeam, awayTeam,
                                                homeScore, awayScore, OptionState.Result.ToString(), time);
                            }
                            else
                            {
                                state = ResultState.UNDEFINED;
                                reviewedMatch.InsertRecalledMatch(linksItem.country, linksItem.currentCompetition, evaluatedDate,
                                                                  homeTeam, awayTeam, state.ToString());
                                continue;
                            }
                        }
                    }
                }
                catch (TaskCanceledException tex)
                {
                    Debug.WriteLine("\n" + tex.Message + " " + DateTime.Now + "\n");
                    FullUpdateOfResults();
                    //countTimeout++;
                    //if (countTimeout >= 5)
                    //{

                    //}
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("\n" + ex.Message + " " + DateTime.Now + "\n");
                    //FullUpdateOfResults();
                    //reviewedMatch.InsertRecalledMatch("COUNTRY", "COMPETITION", DateTime.Now,
                    //                "HOME", "AWAY", "UNDEFINED");
                }
            }
        }