Example #1
0
        public async Task <IEnumerable <string> > GetAsync()
        {
            var db    = _fact.Connection().GetDatabase();
            var redis = new RedisVoteService <Selection>(this._fact);

            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           = "1.2"
            });
            betFields.Add(new BetFieldType
            {
                BetFieldTypeSN = "2",
                BetFieldTypeNM = "2",
                Odds           = "2.1"
            });
            betFields.Add(new BetFieldType
            {
                BetFieldTypeSN = "3",
                BetFieldTypeNM = "Draw",
                Odds           = "1.8"
            });

            selection.BetFieldList = betFields;
            redis.Save("RedisVote:Black", selection);

            return(new string[] { "value1", "value2" });
        }
Example #2
0
        public PartialViewResult Vote(string value)
        {
            var redis   = new RedisVoteService <Vote>(this._fact);
            var theVote = new Vote();

            switch (value)
            {
            case "Y":
                theVote.Yes = 1;
                break;

            case "N":
                theVote.No = 1;
                break;

            case "U":
                theVote.Undecided = 1;
                break;

            default: break;
            }
            redis.Save("RedisVote", theVote);

            var model = redis.Get("RedisVote");

            return(this.PartialView("~/Views/Home/Vote.cshtml", model));
        }
Example #3
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 #4
0
        public override async Task <object> ParseAsync(CancellationToken cancellationToken)
        {
            //string contents = File.ReadAllText(@"E:\365.txt");
            //SaveOddsToRedis(contents);
            using (var scope = serviceScopeFactory.CreateScope())
            {
                var raceDB         = scope.ServiceProvider.GetService <RaceDB.Models.RaceDBContext>();
                var dateTimeFilter = DateTimeOffset.Now.AddHours(-7);
                var matches        = raceDB.Match.AsQueryable().Include(x => x.League).Include(x => x.Category).Where(x => x.Status == 2).Take(3).ToList();
                var redis          = new RedisVoteService <MatchInfo>(this._fact);

                foreach (var match in matches)
                {
                    if (redis.Get($"{match.StartDateTime.ToString("yyyyMMdd")}:{match.MatchId}") == null)
                    {
                        var matchInfo = new MatchInfo
                        {
                            MatchId            = match.MatchId,
                            CategoryName       = match.Category.CategoryName,
                            LeagueName         = match.League.LeagueName,
                            SportName          = "Soccer",
                            StartDateTime      = match.StartDateTime,
                            Status             = match.Status,
                            HomeCompetitorName = match.HomeCompetitorName,
                            AwayCompetitorName = match.AwayCompetitorName
                        };
                        redis.Save($"{match.StartDateTime.ToString("yyyyMMdd")}:{match.MatchId}", matchInfo);
                    }

                    var page = await _engine.newPage();

                    var targetPage = await GetMatchOddsAsync(page, match);

                    Task.Run(async() => {
                        do
                        {
                            await Task.Delay(3000);
                            var qq = await targetPage.GetContentAsync();
                            SaveOddsToRedis(match, qq);
                            await Task.Delay(3000);
                        } while (true);
                    });
                }
            }
            return(null);
        }
Example #5
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);
        }