Inheritance: MovingPicturesDBTable
コード例 #1
0
        // Associates the given file(s) to the given movie object. Also creates all
        // relevent user related data.
        private void AssignFileToMovie(IList<DBLocalMedia> localMedia, DBMovieInfo movie, bool update)
        {
            if (localMedia == null || movie == null || localMedia.Count == 0)
                return;

            // loop through the local media files and clear out any movie assignments
            foreach (DBLocalMedia currFile in localMedia) {
                RemoveCommitedRelations(currFile);
            }

            // write the file(s) to the DB
            int count = 1;
            foreach (DBLocalMedia currFile in localMedia) {
                currFile.Part = count;
                currFile.Commit();

                count++;
            }

            movie.LocalMedia.Clear();
            movie.LocalMedia.AddRange(localMedia);

            // update, associate, and commit the movie
            if (update) {
                MovingPicturesCore.DataProviderManager.Update(movie);
                MovingPicturesCore.DataProviderManager.GetArtwork(movie);
                MovingPicturesCore.DataProviderManager.GetBackdrop(movie);
            }

            foreach (DBLocalMedia currFile in localMedia)
                currFile.CommitNeeded = false;

            // create user related data object for each user
            movie.UserSettings.Clear();
            foreach (DBUser currUser in DBUser.GetAll()) {
                DBUserMovieSettings userSettings = new DBUserMovieSettings();
                userSettings.User = currUser;
                userSettings.Commit();
                movie.UserSettings.Add(userSettings);
                userSettings.CommitNeeded = false;
            }

            movie.PopulateDateAdded();

            movie.Commit();
        }
コード例 #2
0
        // Loops through all movie in the system to verify them
        public static void VerifyMovieInformation()
        {
            logger.Info("Updating Movie Information...");

            float count = 0;
            List<DBMovieInfo> movies = DBMovieInfo.GetAll();
            List<DBUser> users = DBUser.GetAll();
            float total = movies.Count;

            int removed = 0;
            int settings = 0;
            foreach (DBMovieInfo movie in movies) {
                if (MaintenanceProgress != null) MaintenanceProgress("", (int)(count * 100 / total));
                count++;

                // Skip uncommited files
                if (movie.ID == null)
                    continue;

                #region Remove movie without attached local media

                // Remove movie with no files
                if (movie.LocalMedia.Count == 0) {
                    logger.Info("'{0}' was removed from the system because it had no local media.", movie.Title);
                    movie.Delete();
                    removed++;
                    continue;
                }

                #endregion

                #region Add missing user settings

                if (movie.UserSettings.Count == 0) {
                    logger.Info("'{0}' was missing UserMovingSettings, adding now.", movie.Title);
                    foreach (DBUser currUser in users) {
                        DBUserMovieSettings userSettings = new DBUserMovieSettings();
                        userSettings.User = currUser;
                        userSettings.Commit();
                        movie.UserSettings.Add(userSettings);
                        userSettings.CommitNeeded = false;
                    }
                    movie.Commit();
                    settings++;
                }

                #endregion

            }

            logger.Info("Removed {0} movie entries.", removed.ToString());
            logger.Info("Updated {0} movie entries with default user setting.", settings.ToString());
            if (MaintenanceProgress != null) MaintenanceProgress("", 100);
        }