/* * This creates a Person then creates the films * It also then makes a request for the user's image * and stores it in the cache * */ public void CreatePersonAndFilm(List <Film> refinedFilms, List <Person> actorNameID, int categorySectionID) { foreach (var actor in actorNameID) { foreach (var film in refinedFilms) { actor.awards.Add(new Award() { categoryID = categorySectionID, filmID = film.FID, filmWebToken = film.webIDToken }); if (DataRepository.allFilms.Find(q => q.webIDToken.Equals(film.webIDToken)) == null) { DataRepository.AddFilm(film); } else { Debug.WriteLine("The film exists"); } } ; actor.DOB = GetDateOfBirthForWinner(actor.nameToken); List <Person> checkIfUserExists = DataRepository.GetAllPersons(); if (checkIfUserExists.Contains(actor) == true) { Debug.WriteLine("The actor exists"); } else { DataRepository.AddPerson(actor); } //Recently Added OscarData od = new OscarData(actor.ID); string htmlPage = OscarsAwardHelper.GetActorsPage(actor.nameToken); string[] profileImageUrl = ImageHelper.GetProfileImageUrl(htmlPage, actor); if (profileImageUrl != null) { od.RequestImage(profileImageUrl); } } }
// One single function called grab winners public void GetWinners(string htmlSection, int categorySectionID, int year) { string startPoint = "<h3>WINNER</h3>"; string endPoint = "<h3>NOMINEES</h3>"; int secondSection; int startIndex = htmlSection.IndexOf(startPoint); if (startIndex == -1) { startIndex = htmlSection.IndexOf("<h3>WINNERS</h3>"); } int endIndex = htmlSection.IndexOf(endPoint, startIndex); if (endIndex == -1) { endIndex = htmlSection.IndexOf("<h3>NOMINEE</h3>", startIndex); } int length = endIndex - startIndex; // This variable contains winners actor name and film name string winnerSection = htmlSection.Substring(startIndex, length); int firstSection = winnerSection.IndexOf("<strong>"); secondSection = winnerSection.IndexOf("</strong>"); int innerLength = secondSection - firstSection; string filmName = winnerSection.Substring(firstSection, innerLength); // There could be more than one film so we need to check List <string> films = ReturnNumberOfFilms(filmName); // FILM array List <Film> refinedFilms = RefineFilmsArray(films, year); if (refinedFilms == null) { Debug.WriteLine("refinedFilms"); } // After we get the name of the Film we also get the Actor name as well int whereToCut = winnerSection.IndexOf("<a", secondSection); int whereToStopCut = winnerSection.IndexOf("</a>", secondSection); int whereToStop = whereToStopCut - whereToCut; string actorName = winnerSection.Substring(whereToCut, whereToStop); // ACTOR array use a simple model first. //Then later on add the model when it has more information to the actorNameID array actorNameID = returnActorNameID(actorName); foreach (var actor in actorNameID) { foreach (var film in refinedFilms) { actor.awards.Add(new Award() { categoryID = categorySectionID, filmID = film.FID, filmWebToken = film.webIDToken }); if (DataRepository.allFilms.Find(q => q.webIDToken.Equals(film.webIDToken)) == null) { DataRepository.AddFilm(film); } else { Debug.WriteLine("The film exists"); } } ; string htmlPage = OscarsAwardHelper.GetActorsPage(actor.nameToken); if (htmlPage.Contains("\"title=\"No photo available.\"") == true) { Debug.WriteLine("Problem"); } actor.DOB = GetDateOfBirthForWinner(htmlPage); // Create a function that gets the Actor's profile image once you have the Image // This array contains the url to the Page [0] // It also contains whether it is a profile or media image [1] // Contains Actor's id as well [2] string[] profileImageUrl = ImageHelper.GetProfileImageUrl(htmlPage, actor); if (profileImageUrl[0].Length < 20 || profileImageUrl[0].Length < 100) { Debug.WriteLine("PROBLEM"); } OscarData od = new OscarData(actor.ID); // If statement is a DEBUG test if (profileImageUrl[1].Equals("media") == true || profileImageUrl == null) { Debug.WriteLine("media items"); } if (profileImageUrl != null) { od.RequestImage(profileImageUrl); } List <Person> checkIfUserExists = DataRepository.GetAllPersons(); if (checkIfUserExists.Contains(actor) == true) { Debug.WriteLine("The actor exists"); } else { DataRepository.AddPerson(actor); } } }