Exemplo n.º 1
0
        private void GetGameUpdates()
        {
            var activeGames = allGameSummaries
                              .Where(a =>
                                     //a.Id == ""
                                     a.Status?.Status != "F" &&
                                     a.Status?.Status != "Final" &&
                                     a.DateObjUtc.AddMinutes(-15) < DateTime.UtcNow).ToList();

            var gamesToBroadcast = new List <int>();

            Logger.Log($"Total games: {allGameSummaries.Count}, Active games: {activeGames.Count}");

            foreach (var game in activeGames)
            {
                var gdc                = new GameDetailCreator(game.GameDataDirectory);
                var headers            = gdc.GetGameCenterHeaders();
                var lastModifiedHeader = headers.TryGetValueOrDefault("Last-Modified");
                if (lastModifiedHeader != null)
                {
                    var lastModified = DateTime.Parse(lastModifiedHeader).ToUniversalTime();
                    if (lastModified > this.lastCheckedDate)
                    {
                        gamesToBroadcast.Add(game.GamePk);
                    }
                }
            }

            if (gamesToBroadcast.Count > 0)
            {
                Logger.Log($"Broadcasting updates for {string.Join(",", gamesToBroadcast)}");
                this.onUpdateGames(gamesToBroadcast);
            }

            if (!activeGames.Any())
            {
                //End();
                var now      = DateTime.UtcNow;
                var tomorrow = now.AddDays(1).Date;

                this.StartCheckDelay(tomorrow - now);
            }
            else
            {
                checkGamesTimer = new Timer((a) => CheckGames(), null, 10 * 1000, 0);
            }

            this.lastCheckedDate = DateTime.UtcNow;
        }
Exemplo n.º 2
0
        public void Process()
        {
            GameSummaryCollection summary = null;

            try
            {
                summary = this.Gsc.GetSummaryCollection(this.Date);
            }
            catch (Exception e)
            {
            }

            if (summary?.GameSummaries == null || summary.GameSummaries.Length == 0)
            {
                Logger.Log("Skipping " + this.Date);
                return;
            }

            var tempList = new List <HighlightSearchResult>();

            foreach (var gameSummary in summary.GameSummaries)
            {
                var gdc = new GameDetailCreator(gameSummary.GameDataDirectory);
                HighlightsCollection highlights = null;

                try
                {
                    highlights = gdc.GetHighlights();
                }
                catch (Exception e)
                {
                }

                if (highlights?.Highlights == null || highlights.Highlights.Length == 0)
                {
                    continue;
                }

                foreach (var highlight in highlights.Highlights)
                {
                    highlight.url = highlight.url != null && highlight.url.Length > 0
                                                ? highlight.url.Where(a => a.Contains(".mp4")).ToArray()
                                                : new string[0];

                    if (highlight.url.Length == 0)
                    {
                        continue;
                    }

                    var newLocalHighlight = new HighlightSearchResult
                    {
                        GameId     = gameSummary.GamePk,
                        Highlight  = highlight,
                        Thumbnails = HighlightThumbnails.Make(highlight)
                    };

                    highlight.thumbnails = new string[0];

                    tempList.Add(newLocalHighlight);
                }
            }

            this.TempList = tempList;

            if (this.TempList.Any())
            {
                this.JsonSaveAll();
            }
        }