コード例 #1
0
        static void Main(string[] args)
        {
            logger.Info("Program started");

            // create list of movies
            string    movieFilePath = Directory.GetCurrentDirectory() + "\\movies.scrubbed.csv";
            MovieFile movieFile     = new MovieFile(movieFilePath);
            string    file          = "movies.scrubbed.csv";

            // check if file exists
            if (!File.Exists(file))
            {
                logger.Info("The file " + file + " does not exist.");
            }
            else
            {
                string choice;
                do
                {
                    Console.WriteLine("Enter 1 to add movie.");
                    Console.WriteLine("Enter 2 to display all movies.");
                    Console.WriteLine("Enter anything else to quit.");
                    choice = Console.ReadLine();

                    if (choice == "1")
                    {
                        try {
                            Movie        movie        = new Movie();
                            MovieManager movieManager = new MovieManager();

                            // ask user for name of title
                            movie.title = movieManager.enterTitle();

                            // check to see if the same movie exists in library
                            Boolean isUnique = movieFile.isUniqueTitle(movie.title);

                            if (isUnique)
                            {
                                // movie.mediaId is calculated in movieFile.AddMovie(movie);
                                movie.genres      = movieManager.enterGenres();
                                movie.director    = movieManager.enterDirector();
                                movie.runningTime = movieManager.enterRunningTime();
                                movieFile.AddMovie(movie);
                            }
                        }
                        catch (Exception e) {
                            logger.Error(e.Message);
                        }
                    }
                    // display movies
                    else if (choice == "2")
                    {
                        try {
                            // Display All Movies
                            foreach (Movie m in movieFile.Movies)
                            {
                                Console.WriteLine(m.Display());
                            }
                        }
                        catch (Exception e) {
                            logger.Error(e.Message);
                        }
                    }
                } while (choice == "1" || choice == "2");
            }

            logger.Info("Program ended");
        }
コード例 #2
0
        static void Main(string[] args)
        {
            logger.Info("Program started");

            // create list of movies
            string    movieFilePath = Directory.GetCurrentDirectory() + "\\movies.scrubbed.csv";
            MovieFile movieFile     = new MovieFile(movieFilePath);
            string    file          = "movies.scrubbed.csv";

            // check if file exists
            if (!File.Exists(file))
            {
                logger.Info("The file " + file + " does not exist.");
            }
            else
            {
                string choice;
                do
                {
                    Console.WriteLine("Enter 1 to add movie.");
                    Console.WriteLine("Enter 2 to display all movies.");
                    Console.WriteLine("Enter 3 to search movie titles.");
                    Console.WriteLine("Enter anything else to quit.");
                    choice = Console.ReadLine();

                    if (choice == "1")
                    {
                        try {
                            Movie        movie        = new Movie();
                            MovieManager movieManager = new MovieManager();

                            // ask user for name of title
                            movie.title = movieManager.enterTitle();

                            // check to see if the same movie exists in library
                            Boolean isUnique = movieFile.isUniqueTitle(movie.title);

                            if (isUnique)
                            {
                                // movie.mediaId is calculated in movieFile.AddMovie(movie);
                                movie.genres      = movieManager.enterGenres();
                                movie.director    = movieManager.enterDirector();
                                movie.runningTime = movieManager.enterRunningTime();
                                movieFile.AddMovie(movie);
                            }
                        }
                        catch (Exception e) {
                            logger.Error(e.Message);
                        }
                    }
                    // display movies
                    else if (choice == "2")
                    {
                        try {
                            // Display All Movies
                            foreach (Movie m in movieFile.Movies)
                            {
                                Console.WriteLine(m.Display());
                            }
                        }
                        catch (Exception e) {
                            logger.Error(e.Message);
                        }
                    }
                    // search movie titles
                    else if (choice == "3")
                    {
                        try {
                            Console.WriteLine("Enter text to search: ");
                            string text = Console.ReadLine();

                            // display number of matches
                            var numberMovies = movieFile.Movies.Where(m => m.title.Contains(text)).Count();
                            Console.WriteLine($"There are {numberMovies} movies with \"{text}\" in the title.");

                            // change display color in terminal
                            Console.ForegroundColor = ConsoleColor.Green;

                            // display movie titles that match
                            var movieTitleMatch = movieFile.Movies.Where(m => m.title.Contains(text));
                            foreach (Movie m in movieTitleMatch)
                            {
                                Console.WriteLine($"  {m.title}");
                            }

                            // change display color back to white
                            Console.ForegroundColor = ConsoleColor.White;
                        }
                        catch (Exception e) {
                            logger.Error(e.Message);
                        }
                    }
                } while (choice == "1" || choice == "2" || choice == "3");
            }

            logger.Info("Program ended");
        }