예제 #1
0
        /// <summary>
        /// Event on click button "btnFolder"
        /// </summary>
        /// <param name="sender">object</param>
        /// <param name="e">event</param>
        private void btnFolder_Click(object sender, RoutedEventArgs e)
        {
            //kill the thread
            childThread.Abort();

            //open choose folder windows
            choosedirectory directoryClass = new choosedirectory();

            directoryClass.ShowDialog();
            directoryClass.Close();

            //delete all displayed movies
            List <UIElement>    delItems = new List <UIElement>();
            IEnumerable <Image> covers   = gridMovies.Children.OfType <Image>();

            foreach (Image child in covers)
            {
                delItems.Add(child);
            }
            foreach (UIElement delitem in delItems)
            {
                gridMovies.Children.Remove(delitem);
            }

            //show loading
            loading.Visibility = Visibility.Visible;
            loading.Text       = "We are finding your movies, please wait...";

            //restart thread to display movie from the new path
            childThread = new Thread(displayMovies);
            childThread.SetApartmentState(ApartmentState.STA);
            childThread.Start();
        }
예제 #2
0
        /// <summary>
        /// Launch choose folder windows it it's the first launch and initialize DB
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MetroWindow_Loaded(object sender, RoutedEventArgs e)
        {
            // get movie path in config file
            string appdataPath    = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            string folderPath     = appdataPath + "/" + MainWindow.FOLDER_NAME;
            string filePath       = folderPath + "/" + MainWindow.CONFIG_FILE_NAME;
            string moviePath      = "";
            string ogFileNamePath = folderPath + "/originalFileName.txt";

            if (!File.Exists(folderPath))
            {
                Directory.CreateDirectory(folderPath);
            }

            if (!File.Exists(ogFileNamePath))
            {
                var file = File.Create(ogFileNamePath);
                file.Close();
            }

            choosedirectory directoryClass = new choosedirectory();

            if (File.Exists(filePath))
            {
                moviePath = directoryClass.GetPathConfig(filePath, "/config/path_movies");
            }

            // open the second form if it's the first launch
            if (moviePath == "")
            {
                directoryClass.ShowDialog();
                directoryClass.Close();
            }

            dbhandler FMDb = new dbhandler();
        }
예제 #3
0
        /// <summary>
        /// Get path folder in config file and lauch directorySearch
        /// </summary>
        /// <returns>Files name</returns>
        public string[] GetAllFilename()
        {
            //get the choose directory form
            choosedirectory directoryClass = new choosedirectory();

            //get path movie in config file
            string appdataPath    = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            string folderPath     = appdataPath + "/" + MainWindow.FOLDER_NAME;
            string filePath       = folderPath + "/" + MainWindow.CONFIG_FILE_NAME;
            string moviePath      = directoryClass.GetPathConfig(filePath, "/config/path_movies");
            string ogFileNamePath = folderPath + "/originalFileName.txt";

            if (!File.Exists(ogFileNamePath))
            {
                File.Create(ogFileNamePath);
            }

            //get movie in directory and child directory
            List <string> filePaths = DirectorySearch(moviePath);

            DeleteMovies(filePaths, ogFileNamePath);

            return(filePaths.ToArray());
        }//GetAllFilename
예제 #4
0
        /// <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);
            }
        }