示例#1
0
        public void parseNames(ConcThreadJobMaster sender)
        {
            // get parsed movie data;
            ConcurrentImdbMovieParser parser = sender as ConcurrentImdbMovieParser;
            this.movie = new Movie(parser.movieData);

            List<uint> IDsToTest = new List<uint>();

            SQLiteConnector.db.beginTransaction();

            IDsToTest.AddRange(movie.imdbMovie.directors);
            IDsToTest.AddRange(movie.imdbMovie.writers);
            foreach (Tuple<uint, string> cur in movie.imdbMovie.roles) {
                    IDsToTest.Add(cur.Item1);
            }
            foreach (Award a in movie.imdbMovie.awards) {
                IDsToTest.AddRange(a.persons);
            }
            bool[] contains =SQLiteConnector.db.testAndSetPersons(IDsToTest);
            int i = 0;
            foreach (uint id in IDsToTest) {
                if (!contains[i]) {
                    startParse(id);
                }
                i++;
            }
            SQLiteConnector.db.updateMovieData(this.movie);
            SQLiteConnector.db.endTransaction();
        }
        public void updateMovieData(Movie m)
        {
            int idMovies = getIdMoviesByImdbId(m.imdbMovie.imdbID);
            if (m.imdbMovie.poster != null)
            {
                PictureHandler.saveMoviePoster(m.imdbMovie.poster, idMovies);
                m.imdbMovie.poster.Dispose();
            }

            beginTransaction();
            updateImdbMovie(m.imdbMovie, idMovies);
            foreach (ImdbPerson person in m.persons)
            {
                int idp;
                testAndSetPerson(person.imdbID, out idp);
            }

            if (idMovies > -1)
            {
                foreach (Tuple<uint, string> t in m.imdbMovie.roles)
                {
                    insertRole(t.Item1, t.Item2, idMovies);
                }
                foreach (uint imdb in m.imdbMovie.directors)
                {
                    int idPerson = getIdPersonByImdbId(imdb);
                    insertMoviePersonRelation(PersonMovieRelations.Director, idPerson, idMovies);
                }
                foreach (uint id in m.imdbMovie.writers)
                {
                    int idPerson = getIdPersonByImdbId(id);
                    insertMoviePersonRelation(PersonMovieRelations.Writer, idPerson, idMovies);
                }
                foreach (uint id in m.imdbMovie.stars)
                {
                    int idPerson = getIdPersonByImdbId(id);
                    insertMoviePersonRelation(PersonMovieRelations.Stars, idPerson, idMovies);
                }
                updateCountriesToMovie(idMovies, m.imdbMovie.countries);
                updateGenresToMovie(idMovies, m.imdbMovie.genres);
                updateLanguageToMovie(idMovies, m.imdbMovie.languages);
                updateAwardsToMovie(idMovies, m.imdbMovie.awards);
            }

            endTransaction();
            GC.Collect();
            GC.WaitForPendingFinalizers();
            Console.WriteLine("Done inserting '{0}' into DB", m.imdbMovie.title);
        }