/// <exception cref = "MovieDataServiceException" > If we can't connect to the internet.</exception> public List<MovieDetails> GetMovieData(MovieName movieName) { String URLString = URLStringFirst + movieName.Name + URLStringSecond; // make the URL XDocument ob; try { ob = XDocument.Load(URLString); // Loads the xml document var movies = ob.Root.Descendants("review") //Saves the data into list .Where(x => x.Element("display_title").Value.Contains(movieName.Name)) .Select(x => new { Title = x.Element("display_title").Value, Author = x.Element("byline").Value, Date = x.Element("publication_date").Value, Review = x.Element("headline").Value, Description = x.Element("capsule_review").Value, Summary = x.Element("summary_short").Value }).ToList(); foreach (var movie in movies) //Saves the movies data into MovieDetails list movieDetail.Add(new MovieDetails(movie.Title, movie.Author, movie.Date, movie.Review,movie.Description, movie.Summary)); } catch (WebException) { throw new MovieDataServiceException("Internet connection error."); } return movieDetail; }
public MovieDetails(string _title, string _author, string _date, string _review,string _description, string _summary) { title = new MovieName(_title); author = _author; date = _date; review = _review; description = _description; summary = _summary; }
static void Main(string[] args) { string nameString; char select; bool goOn = true; IMovieDataService service = MovieDataServiceFactory.getMovieDataService(MovieDataServiceFactory.NEW_YORK_TIMES); Console.WriteLine("~~~~~~~Movies Reviews~~~~~~~"); while (goOn) { MovieName keyWord = new MovieName(); List<MovieDetails> result = new List<MovieDetails>(); try { Console.WriteLine("\nPlease enter the movie's name:"); nameString = Console.ReadLine(); keyWord.Name = nameString; result = service.GetMovieData(keyWord); if (result.Count == 0) Console.WriteLine("We didn't find the movie you searched"); foreach (MovieDetails movie in result) //prints the movies it found movie.PrintDetails(); } catch (MovieDataServiceException e) { Console.WriteLine(e.ToString()); } finally { service.DeleteMovieData(); //Deletes the movies we searched before Console.WriteLine(@"Do you want to have another search?[Y/N]:"); select = char.Parse(Console.ReadLine()); if (select == 'N') goOn = false; } } Console.WriteLine(@"Do you want to compare between your searching?[Y/N]:"); select = char.Parse(Console.ReadLine()); if (select == 'Y') { List<MovieDetails> compare = service.GetCompareList(); if (compare.Count == 0) { Console.WriteLine("Your search list is empty."); } else { foreach (MovieDetails movie in compare) movie.PrintDetails(); } } Console.WriteLine("Have a great day!"); Console.ReadLine(); }