Esempio n. 1
0
        private void MinerBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            bool?modified = false;

            using (var context = new Context())
            {
                foreach (var miner in context.Miners)
                {
                    if (!Miners.Any(c => c.Id == miner.Id))
                    {
                        Miners.Add(miner);
                        modified = true;
                    }
                }
            }

            e.Result = modified;
        }
Esempio n. 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);
        }