public void MovieDateUtil_GameSunday_OnMonday_IsASunday()
        {
            var actual = MovieDateUtil.GameSunday(new DateTime(2018, 9, 10), true);

            Assert.AreEqual(DayOfWeek.Sunday, actual.DayOfWeek);
        }
예제 #2
0
        /// <summary>
        /// Mine all of the miner movie data.
        /// </summary>
        /// <param name="miners"></param>
        /// <returns></returns>
        private List <List <IMovie> > MineMiners(IEnumerable <IMiner> miners)
        {
            var           result         = new List <List <IMovie> >();
            int           toSkip         = 2;   // Skip FML and "My" (custom) miner
            List <IMovie> baseList       = null;
            List <IMovie> compoundMovies = null;

            // !!!!! FML Base list is first !!!!!

            _telemetryClient.TrackTrace($"Loading Miner", SeverityLevel.Information, new Dictionary <string, string> {
                { "name", miners.First().Name }
            });

            ((ICache)miners.First()).Load();
            baseList = miners.First().Movies;
            result.Add(baseList);

            // Get the contains estimates value from the FML Miner.
            var containsEstimates = miners.First().ContainsEstimates;
            var weekendEnding     = WeekendEnding;              // The actual end date of the game.
            var gameDays          = WeekendEnding.HasValue ? WeekendEnding.Value.Subtract(MovieDateUtil.GameStartTime(WeekendEnding.Value)).Days + 1 : 3;

            if (containsEstimates)
            {
                _telemetryClient.TrackTrace($"Loading Miner", SeverityLevel.Information, new Dictionary <string, string> {
                    { "name", "Box Office Mojo Estimates" }
                });

                LoadBoxOfficeMojoEstimates(miners.First());
            }

            // TODO: Fix this for the FML base list.  This will break when another compound movie (multi-day) comes into play.

            compoundMovies = CompoundMovies(baseList);

            if (compoundMovies.Any())
            {
                // Todd's list is preferred for compound movies.

                var minerTodd = miners.ToList()[TODD_INDEX];

                if (minerTodd != null)
                {
                    _telemetryClient.TrackTrace($"Loading Miner", SeverityLevel.Information, new Dictionary <string, string> {
                        { "name", minerTodd.Name }
                    });

                    ((ICache)minerTodd).Load();

                    compoundMovies = CompoundMovies(minerTodd.Movies);

                    // Assign the id, name, and cost to each movie.

                    foreach (var movie in baseList)
                    {
                        AssignCostIdName(movie, minerTodd.Movies);
                    }

                    toSkip++;                           // Now skip Todd's too.
                }
            }

            Parallel.ForEach(miners.Skip(toSkip), miner =>
                             //foreach (var miner in miners.Skip(toSkip))
            {
                try
                {
                    if (miner != baseList)
                    {
                        miner.ContainsEstimates = containsEstimates;
                        miner.GameDays          = gameDays;

                        List <IMovie> movieList = null;

                        if (miner.OkToMine)
                        {
                            _telemetryClient.TrackTrace($"Loading Miner", SeverityLevel.Information, new Dictionary <string, string> {
                                { "name", miner.Name }
                            });

                            ((ICache)miner).Load();

                            movieList = miner.Movies;
                        }

                        lock (result)
                        {
                            result.Add(movieList);
                        }

                        if (movieList != null && movieList.Any())
                        {
                            if (compoundMovies.Any())
                            {
                                if (!movieList.Any(movie => movie.Day.HasValue))
                                {
                                    // The list has no compound movies so they need to be built
                                    // Need to readjust the movies.
                                    miner.SetMovies(SpreadCompoundMovies(compoundMovies, movieList));
                                }

                                if (miner == miners.Last())
                                {
                                    LoadLastBoxOfficeMojoCompound(miner as MineBoxOfficeMojo, compoundMovies.First());
                                }
                            }

                            // Assign the id, name, and cost to each movie.

                            foreach (var movie in baseList)
                            {
                                AssignCostIdName(movie, movieList);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    lock (result)
                    {
                        result.Add(new List <IMovie>());                            // Add a placeholder.
                    }

                    miner.Error       = "Error";
                    miner.ErrorDetail = ex.Message;

                    _telemetryClient.TrackTrace($"Load Error", SeverityLevel.Error
                                                , new Dictionary <string, string> {
                        { "name", miner.Name }, { "errorDetail", miner.ErrorDetail }
                    });
                }
                //}
            });

            // Mine my/custom movies LAST because they are based on all of the other miners.

            miners.ToList()[MY_INDEX].Mine();

            _telemetryClient.TrackTrace($"Finished Loading Miners", SeverityLevel.Information);

            return(result);
        }