Beispiel #1
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));
        }
Beispiel #2
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);
        }