/// <summary> /// Class constructor /// </summary> /// <param name="fileName">name of the file to get info</param> public api(string fileName) { extractfileinfo extract = new extractfileinfo(fileName); this.movieName = extract.GetMovieName(); this.client = new TMDbClient(this.key); this.movieId = this.GetMovieID(); }
/// <summary> /// Test if movie is in db or not and display it from DB or API /// </summary> private void displayMovies() { choosedirectory directoryClass = new choosedirectory(); MovieRepository movieRepository = new MovieRepository(); //test internet connected if (!CheckConnection()) { internetConected = false; MessageBox.Show("No internet connexion, new movie won't be added to the database and images won't be loaded !", "Find My Movie", MessageBoxButton.OK, MessageBoxImage.Warning ); } var allMovies = interfaceClass.GetAllFilename(); bool zeroMovieFound = true; List <int> alreadyDisplay = new List <int>(); //to avoid doublon foreach (var movie in allMovies) { bool displayMovie = false; //get movie name extractfileinfo extract = new extractfileinfo(Path.GetFileName(movie)); string movieName = extract.GetMovieName().Trim(); //check if in db int idMovie = movieRepository.MovieExists("ogtitle", movieName); string urlImg = ""; //if in DB if (idMovie != 0) { //get data from db fmmMovie infos = movieRepository.GetMovie(idMovie); //get cover if (infos.poster != null && internetConected) { urlImg = "https://image.tmdb.org/t/p/w500" + infos.poster; } displayMovie = true; }//if else if (internetConected) { //Thread.Sleep(200) are here for avoid the maximum request impose per The movie database (40 requets per second) Thread.Sleep(200); // init new api object api api = new api(Path.GetFileName(movie)); // check if request to api worked if (api.DidItWork()) { //get data from api Thread.Sleep(200); Movie infos = api.GetMovieInfo(); if (infos.PosterPath != null) { urlImg = "https://image.tmdb.org/t/p/w500" + infos.PosterPath; } Thread.Sleep(200); Credits credit = api.GetMovieCredits(); idMovie = infos.Id; //add in DB PopulateDB(infos, credit, movieName, movie); displayMovie = true; } }//else //display cover if (displayMovie && !alreadyDisplay.Contains(idMovie)) { this.Dispatcher.BeginInvoke(new Action(() => addMovieGrid(urlImg, idMovie)), System.Windows.Threading.DispatcherPriority.Background, null); alreadyDisplay.Add(idMovie); zeroMovieFound = false; } }//foreach if (zeroMovieFound) { this.Dispatcher.BeginInvoke(new Action(() => AppendTextBox()), System.Windows.Threading.DispatcherPriority.Background, null); } }