示例#1
0
        public async void ExecuteScrape(object gamePk)
        {
            _logger.LogDebug("Entered ExecuteScrape()");
            int gameCode = int.Parse(gamePk.ToString());

            _logger.LogInformation("Scrape time. Game code: {0}", gamePk);

            if (!_mqttHelper.IsConnected)
            {
                _logger.LogInformation("Mqtt not connected. reconnecting");

                //TODO Smart reconnect logic
                await _mqttHelper.Reconnect();
            }

            _scraper = new BluesScraper(gameCode);
            _logger.LogDebug("BluesScraper Object built");

            await _mqttHelper.SendConfigData(Constants.GameStartedCommand);

            //Begin our nifty long running task
            while (true)
            {
                _logger.LogInformation("Scraping Loop started");
                try
                {
                    var data = await _scraper.RefreshData();

                    TimeSpan delay = (BluesScraper.GetDelayTime(data.Item2));
                    string   json  = JsonConvert.SerializeObject(data.Item1);

                    await _mqttHelper.SendData(json);

                    //If critical action or less than 60seconds left, send command to show time remaining
                    await SendShowTimeConfig(data);

                    //End execution
                    if (delay == TimeSpan.Zero)
                    {
                        break;
                    }

                    _logger.LogInformation($"Sleeping for {delay}");
                    _logger.LogInformation("Game status: {0}", data.Item2.ToString());
                    Thread.Sleep(delay);
                }
                catch (Exception e)
                {
                    _logger.LogCritical("Exception during scraping loop: {0}", e.Message);
                    _logger.LogCritical("Cannot continue");
                }
            }

            //Game Over
            _logger.LogInformation("Game ended. Exiting scrape method");
            await _mqttHelper.SendConfigData(Constants.GameEndedCommand);

            _liveUpdateTimer.Dispose();
        }
示例#2
0
        public async Task <Tuple <bool, TimeSpan, string> > GameDayCheck()
        {
            _logger.LogDebug("GameDayCheck()");
            var timeToGame = TimeSpan.Zero;

            var nextGameInfo = await BluesScraper.GetNextGameTimeAndCode(Constants.NextGameURL);

            var utcGameTime = DateTime.Parse(nextGameInfo.Item1);

            _logger.LogDebug("UTC Game time: {0}", utcGameTime.ToLongTimeString());

            var  timeTil   = utcGameTime - DateTime.UtcNow;
            bool isGameDay = timeTil.TotalHours < 24;

            _logger.LogDebug("Time til game: {0} minutes. Is game day? {1}", timeTil.TotalMinutes, isGameDay);

            return(Tuple.Create(isGameDay, timeTil, nextGameInfo.Item2));
        }