Example #1
0
        public void SaveOddsToRedis(Match match, string contents)
        {
            var rawFullTimeResult = HtmlHandler.GetImplement("Date", contents).Gets(_fullTimeResultFilter);
            var date      = DateTimeOffset.Now.ToString("yyyyMMdd");
            var timeStamp = DateTimeOffset.Now;
            var key       = $"{date}:{match.MatchId}:odds:1101";


            var db    = _fact.Connection().GetDatabase();
            var redis = new RedisVoteService <BetFieldType>(this._fact);

            if (rawFullTimeResult != null)
            {
                redis.Delete(key);
            }
            var selection = new Selection();

            selection.BetTypeSN = "1101";
            selection.BetTypeNM = "Match Result";

            var betFields = new List <BetFieldType>();

            betFields.Add(new BetFieldType
            {
                BetFieldTypeSN = "1",
                BetFieldTypeNM = "1",
                Odds           = rawFullTimeResult[0],
                TimeStamp      = timeStamp
            });
            betFields.Add(new BetFieldType
            {
                BetFieldTypeSN = "3",
                BetFieldTypeNM = "Draw",
                Odds           = rawFullTimeResult[1],
                TimeStamp      = timeStamp
            });
            betFields.Add(new BetFieldType
            {
                BetFieldTypeSN = "2",
                BetFieldTypeNM = "2",
                Odds           = rawFullTimeResult[2],
                TimeStamp      = timeStamp
            });

            selection.BetFieldList = betFields;
            redis.SaveList(key, betFields);
        }
Example #2
0
        public override async Task <object> ParseAsync(CancellationToken cancellationToken)
        {
            using (var scope = serviceScopeFactory.CreateScope())
            {
                var raceDB  = scope.ServiceProvider.GetService <RaceDB.Models.RaceDBContext>();
                var leagues = raceDB.League.Where(x => x.Status == 1).ToList();
                foreach (var league in leagues)
                {
                    var totalMatchHtml = await GetMatchListAsync(league.LeagueKey);//await _engine.LoadHtml(string.Format(totalMatchUrl, league.LeagueKey.Trim()), JobTimeout);

                    var rawDate = HtmlHandler.GetImplement("Date", totalMatchHtml).Get(_DateFilter) + " 2018";
                    var attrs   = HtmlHandler.GetImplement("TotalMatchAttrs", totalMatchHtml).GetsAttributes(_totalMatchValueFilter);
                    var values  = HtmlHandler.GetImplement("TotalLeagueValues", totalMatchHtml).Gets(_totalMatchValueFilter);

                    if (values == null)
                    {
                        continue;
                    }
                    var matchDataList = (from a in attrs
                                         from b in values
                                         where a.Key == b.Key
                                         where a.Value.Any(x => x.Key == "data-fixtureid")
                                         select new
                    {
                        MatchKey = a.Value.Where(x => x.Key == "data-fixtureid").FirstOrDefault().Value,
                        MatchValue = b.Value
                    });
                    var redis = new RedisVoteService <int>(this._fact);
                    var date  = Convert.ToDateTime(rawDate).ToString("yyyyMMdd");

                    foreach (var match in matchDataList)
                    {
                        var matchData     = HtmlHandler.GetImplement("matchData", match.MatchValue).Gets(_matchCompetitor);
                        var matchDate     = HtmlHandler.GetImplement("matchDate", match.MatchValue).Get(_matchDate);
                        var gameStartDate = new DateTimeOffset(Convert.ToDateTime(matchDate + " " + rawDate), new TimeSpan(1, 0, 0));

                        RaceDB.Models.Match matchModel = new RaceDB.Models.Match();
                        var existMatch = raceDB.Match.Where(x => x.MatchKey == match.MatchKey && x.StartDateTime == gameStartDate).FirstOrDefault();
                        if (existMatch != null)
                        {
                            matchModel = existMatch;
                        }

                        var homeCompetitor = matchData[0];
                        var awayCompetitor = matchData[1];

                        matchModel.MatchKey           = match.MatchKey;
                        matchModel.LeagueId           = league.LeagueId;
                        matchModel.CategoryId         = league.CategoryId;
                        matchModel.HomeCompetitorName = homeCompetitor;
                        matchModel.AwayCompetitorName = awayCompetitor;
                        matchModel.Status             = 2;
                        matchModel.InPlay             = false;
                        matchModel.SportId            = 0;
                        matchModel.StartDateTime      = gameStartDate;
                        matchModel.CreateDate         = DateTimeOffset.Now.ToOffset(new TimeSpan(-4, 0, 0));
                        matchModel.UpdateDate         = DateTimeOffset.Now.ToOffset(new TimeSpan(-4, 0, 0));
                        matchModel.ResultStatus       = 0;

                        if (existMatch == null)
                        {
                            raceDB.Add(matchModel);
                        }
                        raceDB.SaveChanges();
                    }
                    if (redis.GetList($"{date}:matches") == null)
                    {
                        var matchList = raceDB.Match.Where(x => x.StartDateTime.ToString("yyyyMMdd") == date).Select(x => x.MatchId).ToList();
                        redis.SaveList($"{date}:matches", matchList);
                    }
                }
            }
            return(null);
        }