コード例 #1
0
        /// <summary>
        /// Assign the theater counts from MojoTheaterCount.
        /// NOTE: Reloading the FML movies will overwrite the theater count so then need to be corrected.
        /// </summary>
        /// <param name="clone"></param>
        private void AssignTheaterCounts(MinerModel clone)
        {
            var theaterCountMiner = clone.Miners[NUMBERS_THEATER_INDEX];
            var fmlMiner          = clone.Miners[FML_INDEX];

            if (theaterCountMiner.CloneCausedReload || fmlMiner.CloneCausedReload)
            {
                foreach (var movie in fmlMiner.Movies)
                {
                    var found = theaterCountMiner?.Movies?.FirstOrDefault(item => item.Equals(movie));

                    if (found != null)
                    {
                        movie.TheaterCount = found.TheaterCount;
                    }
                }

                var masterMiner = Miners[FML_INDEX];

                if (masterMiner != null)
                {
                    // There is still nothing to prevent this from happening twice (or multiple times).

                    lock (masterMiner)
                    {
                        // The MinerBase.Clone() method for explanation of cloning this list.

                        masterMiner.SetMovies(new List <IMovie>(fmlMiner.Movies));
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Clone ALL of the miners in the list.  NEW data may be loaded so adjsut for that.
        /// </summary>
        /// <returns>The MinerModel clone.</returns>
        public IMinerModel Clone()
        {
            var clone = new MinerModel(false, _mailUtility, _telemetryClient)
            {
                Miners = new List <IMiner>()
            };
            var idx = 0;
            var containsEstimates = Miners.Any() ? Miners[FML_INDEX].ContainsEstimates : false;

            // FML could change below which means ContainsEstimates might be out of date for these clones, it will be correct the NEXT time around.

            // Only download the posters once.

            clone._postersDownloaded = _postersDownloaded;

            // TODO: Why isn't this Parallel? (probably reasons)

            foreach (var miner in Miners)
            {
                miner.ContainsEstimates = containsEstimates;

                // Clone could possibly load in fresh data.
                clone.Miners.Add(miner.Clone());

                if (idx == MY_INDEX)
                {
                    // The custom/mine/my (numbers) miner needs a reference to THIS model

                    var mineMine = clone.Miners[idx] as MineMine;

                    if (mineMine != null)
                    {
                        mineMine.Model = clone;
                    }
                }

                idx++;
            }

            AssignTheaterCounts(clone);

            // If any of the miners are reloaded, then the composite movies (if any) need to be reassigned based on Todd's spread.
            // The miner's that have loaded their own composite movies will not be overwritten.

            if (clone.Miners.Any(miner => miner.CloneCausedReload))
            {
                var compoundMovies = CompoundMovies(clone.Miners[FML_INDEX].Movies);

                if (compoundMovies.Any())
                {
                    compoundMovies = CompoundMovies(clone.Miners[TODD_INDEX].Movies);

                    idx = TODD_INDEX + 1;

                    foreach (var miner in clone.Miners.Skip(TODD_INDEX + 1))
                    {
                        if (miner.CloneCausedReload && !miner.CompoundLoaded && miner.Movies.Any())
                        {
                            if (!miner.Movies.Any(movie => movie.Day.HasValue))
                            {
                                // The list has no compound movies so they need to be built

                                // Need to readjust the movies. (of the clone)
                                miner.SetMovies(SpreadCompoundMovies(compoundMovies, miner.Movies));

                                // Need to readjust the movies. (of the singleton)
                                Miners[idx].SetMovies(SpreadCompoundMovies(compoundMovies, Miners[idx].Movies));

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

                        idx++;
                    }
                }

                // Loop through all of the reloaded miners and adjust their movies.

                foreach (var miner in clone.Miners.Where(miner => miner.CloneCausedReload && miner != clone.Miners[FML_INDEX]))
                {
                    if (miner != clone.Miners[MY_INDEX])
                    {
                        _telemetryClient.TrackTrace($"Clone caused miner to reload '{miner.Name}'", SeverityLevel.Information
                                                    , new Dictionary <string, string> {
                            { "minerName", miner.Name }
                            , { "gameDays", miner.GameDays.ToString() }
                            , { "lastUpdated", miner.LastUpdated?.ToString() }
                            , { "isNewData", miner.IsNewData.ToString() }
                            , { "twitterId", miner.TwitterID }
                        });
                    }

                    foreach (var movie in clone.Miners[FML_INDEX].Movies)
                    {
                        AssignCostIdName(movie, miner.Movies);
                    }

                    FilterOutMovieIdZero(miner);

                    var masterMiner = Miners.FirstOrDefault(item => item.Name == miner.Name);

                    if (masterMiner != null)
                    {
                        // There is still nothing to prevent this from happening twice (or multiple times).

                        lock (masterMiner)
                        {
                            // The MinerBase.Clone() method for explanation of cloning this list.

                            masterMiner.SetMovies(new List <IMovie>(miner.Movies));

                            // Only need to make the picks ONCE after it's loaded.
                            // (no need to make the picks in the controller for every request).

                            if (masterMiner != Miners[MY_INDEX])
                            {
                                // Do not make picks for "my picks" because the BO values have not been set yet (from request string)

                                MakePicks(masterMiner);
                            }
                        }
                    }
                }

                if (containsEstimates && clone.Miners[FML_INDEX].CloneCausedReload)
                {
                    LoadBoxOfficeMojoEstimates(clone.Miners[FML_INDEX]);

                    var masterMiner = Miners[FML_INDEX];

                    if (masterMiner != null)
                    {
                        // There is still nothing to prevent this from happening twice (or multiple times).

                        lock (masterMiner)
                        {
                            LoadBoxOfficeMojoEstimates(masterMiner);
                        }
                    }
                }
            }

            FilterMinersMovies(clone.Miners);

            return(clone);
        }