Ejemplo n.º 1
0
        public static void AddPeopleFromMovie(this IMDB movie)
        {
            List <string> peopleAlreadyInDB =
                (from person in Context.People select person.FirstName + " " + person.LastName).ToList();

            List <string> people = movie.Cast.ToList();

            people.AddRange(movie.Directors.ToList());
            people.AddRange(movie.Writers.ToList());

            people = people.Distinct().ToList();

            List <string> peopleToAdd =
                people.Where(person => !peopleAlreadyInDB.Contains(person.ToString(CultureInfo.InvariantCulture))).
                ToList();


            //add the people
            foreach (string person in peopleToAdd)
            {
                Tuple <string, string> personName = person.SplitNameToFirstAndRemainingAsLast();

                Context.AddToPeople(new Person
                {
                    FirstName = personName.Item1,
                    LastName  = personName.Item2
                });
            }
        }
Ejemplo n.º 2
0
        public void AddMovie(IMDB movie)
        {
            try
            {
                //progressLabel.Content = string.Format("Adding movie [ {0} ]...", Movie.Title);
                bool inserted = movie.AddMovieToCollection();
                if (inserted) _moviesInsertedSuccessfully++;
                movie.Inserted = inserted;
                //processedMovies.Add( movie );
                //Film moviePulledFromDB = movieToRetrieve.ReadMovieFromCollection();
                Dispatcher.Invoke(_updatePbDelegate,
                System.Windows.Threading.DispatcherPriority.Background, new object[]
                {
                    RangeBase.ValueProperty, (double) _movieCount
                });

            }
            catch (Exception ex)
            {
                Log.Trace("Could not complete movie insert", movie.Title);
                Log.Error(ex);
                ex.ThrowFormattedException();

            }
        }
Ejemplo n.º 3
0
        public static bool AddMovieToCollection(this IMDB movie)
        {
            try
            {
                if (AddMovieToDB(movie))
                {
                    AddGenresFromMovie(movie);
                    AddPeopleFromMovie(movie);
                    SaveAndRefreshDBConnection();

                    //retrieve for DB assigned id
                    Film = ReadMovieFromCollection(movie.Title);

                    AddGenreFilmIndexes(Film.FilmID, movie);

                    AddPersonFilmIndexesFromMovie(Film.FilmID, movie);



                    SaveAndCloseDBConnection();
                    return(true);
                }
                return(false);
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                ex.ThrowFormattedException();
            }
            return(false);
        }
Ejemplo n.º 4
0
        public static void FillNewFieldsInMovieTable(this string titleToFix)
        {
            if (!string.IsNullOrWhiteSpace(titleToFix))
            {
                IMDB movie;
                if (titleToFix.Contains(@"http://www.imdb.com/title"))
                {
                    movie = new IMDB(titleToFix, true);
                    FixMovie(movie);
                }
                else
                {
                    try
                    {
                        movie = new IMDB(titleToFix);

                        if (movie.Title.ToLower() == titleToFix.ToLower())
                        {
                            FixMovie(movie);
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Trace("Could not complete movie retrieval and insert", ex, titleToFix);
                        //Log.Error("Could not complete movie insert, exception: [ {0} ]", ex.ToString());
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public static void AddPersonFilmIndexesFromMovie(int filmId, IMDB movie)
        {
            //get person list from db
            List <Person> allPeople = GetAllPeople();

            AddPersonFilmIndexes(allPeople.Where(p => movie.Directors.Contains(string.Format("{0} {1}", p.FirstName, p.LastName))).ToList(),
                                 filmId, movie.CastCharacters, FilmRole.DirectorRole.RoleID);

            AddPersonFilmIndexes(allPeople.Where(p => movie.Cast.Contains(string.Format("{0} {1}", p.FirstName, p.LastName))).ToList(),
                                 filmId, movie.CastCharacters, FilmRole.ActorRole.RoleID);


            AddPersonFilmIndexes(allPeople.Where(p => movie.Writers.Contains(string.Format("{0} {1}", p.FirstName, p.LastName))).ToList(),
                                 filmId, movie.CastCharacters, FilmRole.WriterRole.RoleID);
        }
Ejemplo n.º 6
0
        public static void AddGenresFromMovie(this IMDB movie)
        {
            List <string> genresAlreadyInDB = (from genre in Context.Genres select genre.Name).ToList();

            List <string> genresToAdd =
                movie.Genres.Select(s => s.ToString(CultureInfo.InvariantCulture)).Where(
                    genre => !genresAlreadyInDB.Contains(genre.ToString(CultureInfo.InvariantCulture))).ToList();

            //add the genres
            foreach (string genre in genresToAdd)
            {
                Context.AddToGenres(new Genre
                {
                    Name = genre
                });
            }
        }
Ejemplo n.º 7
0
        public static void AddGenreFilmIndexes(int filmId, IMDB movie)
        {
            //get genre list from db
            List<Genre> allGenres = GetAllGenres();

            List<Genre> genreFilmIndexesToAdd = allGenres.Where(p => movie.Genres.Contains(p.Name)).ToList();

            //for each genre from the db, if it's the movie's genre => add an index for it, better way?
            //foreach (Genre genre in genreFilmIndexesToAdd)
            //{
            //	Context.AddToGenreFilmIndexes(
            //		new GenreFilmIndex
            //			{
            //				FilmID = filmId,
            //				GenreID = genre.GenreID
            //			}
            //		);
            //}
        }
Ejemplo n.º 8
0
        public static void AddGenreFilmIndexes(int filmId, IMDB movie)
        {
            //get genre list from db
            List <Genre> allGenres = GetAllGenres();

            List <Genre> genreFilmIndexesToAdd = allGenres.Where(p => movie.Genres.Contains(p.Name)).ToList();

            //for each genre from the db, if it's the movie's genre => add an index for it, better way?
            foreach (Genre genre in genreFilmIndexesToAdd)
            {
                Context.AddToGenreFilmIndexes(
                    new GenreFilmIndex
                {
                    FilmID  = filmId,
                    GenreID = genre.GenreID
                }
                    );
            }
        }
Ejemplo n.º 9
0
        public static bool AddMovieToDB(this IMDB movie)
        {
            if (!CheckDBForMovie(movie.Title))
            {
                int rating = Ratings.GetValue(movie.MpaaRating);
                if (rating == default(int))
                {
                    Context.AddToRatings(new Rating()
                    {
                        MPAARating = movie.MpaaRating
                    });
                    Context.SaveChanges();
                    _ratings = null;
                    rating   = Ratings.GetValue(movie.MpaaRating);
                }


                try
                {
                    Context.AddToFilms
                    (
                        new Film
                    {
                        Title       = movie.Title,
                        Length      = movie.Runtime.ToIntSafe(),
                        Year        = movie.Year.ToIntSafe(),
                        Plot        = movie.Plot,
                        ImdbURL     = movie.ImdbURL,
                        MovieRating = rating
                    }
                    );
                    return(true);
                }
                catch (Exception exception)
                {
                    exception.ThrowFormattedException();
                }
            }

            return(false);
        }
Ejemplo n.º 10
0
 public static void FixMovie(IMDB movie)
 {
     try
     {
         Film dbMovie = (from film in Context.Films where film.Title == movie.Title select film).SingleOrDefault();
         if (dbMovie == null || dbMovie == new Film())
         {
             movie.AddMovieToCollection();
         }
         else
         {
             dbMovie.Plot    = movie.Plot;
             dbMovie.ImdbURL = movie.ImdbURL;
             //dbMovie.Rating = movie.MpaaRating.Replace('_', '-');
         }
         Context.SaveChanges();
     }
     catch (Exception ex)
     {
         Log.Trace("Could not complete movie insert", movie.Title);
         Log.Error(ex);
         ex.ThrowFormattedException();
     }
 }
Ejemplo n.º 11
0
        public static void FixMovie(IMDB movie)
        {
            try
            {
                Film dbMovie = (from film in Context.Films where film.Title == movie.Title select film).SingleOrDefault();
                if (dbMovie == null || dbMovie == new Film())
                {
                    movie.AddMovieToCollection();
                }
                else
                {
                    dbMovie.Plot = movie.Plot;
                    dbMovie.ImdbURL = movie.ImdbURL;
                    //dbMovie.Rating = movie.MpaaRating.Replace('_', '-');
                }
                Context.SaveChanges();

            }
            catch (Exception ex)
            {
                Log.Trace("Could not complete movie insert", movie.Title);
                Log.Error(ex);
                ex.ThrowFormattedException();

            }
        }
Ejemplo n.º 12
0
        public static void FillNewFieldsInMovieTable(this string titleToFix)
        {
            if (!string.IsNullOrWhiteSpace(titleToFix))
             {
                 IMDB movie;
                    if (titleToFix.Contains(@"http://www.imdb.com/title"))
                    {
                        movie = new IMDB(titleToFix, true);
                        FixMovie(movie);
                    }
                    else
                    {
                        try
                            {
                                movie = new IMDB(titleToFix);

                                if (movie.Title.ToLower() == titleToFix.ToLower())
                                {
                                   FixMovie(movie);
                                }
                            }
                            catch (Exception ex)
                            {
                                Log.Trace("Could not complete movie retrieval and insert", ex, titleToFix);
                                //Log.Error("Could not complete movie insert, exception: [ {0} ]", ex.ToString());
                            }
                        }
                    }
        }
Ejemplo n.º 13
0
        public static void AddPersonFilmIndexesFromMovie(int filmId, IMDB movie)
        {
            //get person list from db
            List<Person> allPeople = GetAllPeople();

            AddPersonFilmIndexes( allPeople.Where(p => movie.Directors.Contains(string.Format("{0} {1}", p.FirstName, p.LastName))).ToList(),
                                                     filmId, movie.CastCharacters, FilmRole.DirectorRole.RoleID);

             AddPersonFilmIndexes(allPeople.Where(p => movie.Cast.Contains(string.Format("{0} {1}", p.FirstName, p.LastName))).ToList(),
                                                     filmId, movie.CastCharacters, FilmRole.ActorRole.RoleID);

             AddPersonFilmIndexes(allPeople.Where(p => movie.Writers.Contains(string.Format("{0} {1}", p.FirstName, p.LastName))).ToList(),
                                                     filmId, movie.CastCharacters, FilmRole.WriterRole.RoleID);
        }
Ejemplo n.º 14
0
        private void ButtonClick1(object sender, RoutedEventArgs e)
        {
            _moviesInsertedSuccessfully = 0;
            MoviesToAdd = listOfMovies.Text.Split(new[] { "\r\n", "\n", Environment.NewLine }, StringSplitOptions.None).ToList();
            progressBar.Minimum = 0;
            progressBar.Maximum = MoviesToAdd.Count;
            progressBar.Value = 0;
            progressBar.Visibility = Visibility.Visible;

            Stopwatch timer = new Stopwatch();
            timer.Start();
            foreach (string movieToRetrieve in MoviesToAdd)
            {

                _movieCount++;

                if (!string.IsNullOrWhiteSpace(movieToRetrieve))
                {
                    IMDB Movie;
                    if (movieToRetrieve.Contains(@"http://www.imdb.com/title"))
                    {
                        Movie = new IMDB(movieToRetrieve, true);
                        AddMovie(Movie);
                    }
                    else
                    {
                        if (!MovieAppHelpers.CheckDBForMovie( movieToRetrieve ))
                        {
                            try
                            {
                                Movie = new IMDB(movieToRetrieve);

                                if (Movie.Title.ToLower() != movieToRetrieve.ToLower())
                                {
                                    string message = string.Format(
                                        "Retrieved title [ {1} ] did not match entered title [ {2} ], add anyway?{0}{0}[ Title: {1}, Year: {3}, Lead: {4} ]",
                                            Environment.NewLine, Movie.Title, movieToRetrieve, Movie.Year ?? string.Empty,
                                            (Movie.Cast != null) ? Movie.Cast.ToArray().FirstOrDefault() : string.Empty);

                                    MessageBoxResult msgBoxResult = MessageBox.Show(message, "Ambiguous Match Found", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No, MessageBoxOptions.DefaultDesktopOnly);

                                    if (msgBoxResult == MessageBoxResult.Yes) AddMovie(Movie);

                                    if (msgBoxResult == MessageBoxResult.No)
                                    {
                                        Log.Trace(
                                            "Retrieved Movie: [ Title: {0}, Year: {1}, Lead: {2} ] Entered Movie: [ Title: {3} ]",
                                            new object[]
                                                {
                                                    Movie.Title, Movie.Year ?? string.Empty,
                                                    (Movie.Cast != null)
                                                        ? Movie.Cast.ToArray().FirstOrDefault()
                                                        : string.Empty, movieToRetrieve
                                                });
                                        Dispatcher.Invoke(_updatePbDelegate,
                                                          System.Windows.Threading.DispatcherPriority.Background,
                                                          new object[]
                                                              {
                                                                  RangeBase.ValueProperty, (double) _movieCount
                                                              });
                                    }

                        }
                                else // Titles Match
                                {
                                    AddMovie(Movie);
                                }
                            }
                            catch (Exception ex)
                            {
                                Log.Trace("Could not complete movie retrieval and insert", ex, movieToRetrieve);
                                //Log.Error("Could not complete movie insert, exception: [ {0} ]", ex.ToString());
                            }
                        }
                    }
                }
            }

            //Switcher.Switch(new AddResults( processedMovies));
            timer.Stop();
            "Inserted {0} of {1} movies successfully, Total run time: {2}, (see log for any failures)".ShowMessage(new object[] { _moviesInsertedSuccessfully, MoviesToAdd.Count, timer.Elapsed.ToReadableString() });
        }
        private void ButtonClick1(object sender, RoutedEventArgs e)
        {
            _moviesInsertedSuccessfully = 0;
            MoviesToAdd = listOfMovies.Text.Split(new[] { "\r\n", "\n", Environment.NewLine }, StringSplitOptions.None).ToList();
            progressBar.Minimum = 0;
            progressBar.Maximum = MoviesToAdd.Count;
            progressBar.Value = 0;
            progressBar.Visibility = Visibility.Visible;
            Stopwatch timer = new Stopwatch();
            timer.Start();
            foreach (string movieToRetrieve in MoviesToAdd)
            {

                _movieCount++;

                if (!string.IsNullOrWhiteSpace(movieToRetrieve))
                {
                    if (movieToRetrieve.Contains(@"http://www.imdb.com/title"))
                    {
                        try
                        {
                            IMDB Movie = new IMDB(movieToRetrieve, true);
                            AddMovie(Movie);
                        }
                        catch (Exception ex)
                        {

                            Log.Error( "Could not add movie to collection: [ {0} ]", new object[] { movieToRetrieve });
                        }

                    }
                }
            }

            //Switcher.Switch(new AddResults( processedMovies));
            timer.Stop();
            "Inserted {0} of {1} movies successfully, Total run time: {2}, (see log for any failures)".ShowMessage(new object[] { _moviesInsertedSuccessfully, MoviesToAdd.Count, timer.Elapsed.ToReadableString() });
        }