Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// Adds Title, Art, Year, Runtime, Genres
- /// </summary>
- /// <param name="createdTitle"></param>
- public static void AddPrimaryData(Title createdTitle, XmlNode catalog_title)
- {
- //find the title node, use the short title
- var title_node = catalog_title.SelectNodes("title")[0];
- var short_title = title_node.Attributes["short"].Value;
- var regular_title = title_node.Attributes["regular"].Value;
- createdTitle.TitleString = short_title;
- //TODO: Box Art
- //find the year released
- var release_node = catalog_title.SelectSingleNode("release_year");
- var year = release_node.InnerText;
- if (year != "") {
- createdTitle.ReleaseYear = Convert.ToInt32(year);
- }
- else if (year == "") {
- createdTitle.ReleaseYear = 0;
- }
- //find the runtime
- var runtime_node = catalog_title.SelectSingleNode("link/delivery_formats/availability/runtime");
- if (runtime_node != null)
- {
- var runtime = runtime_node.InnerText;
- try {
- createdTitle.RuntimeInSeconds = Convert.ToInt32(runtime);
- }
- catch (Exception ex) {
- createdTitle.RuntimeInSeconds = 0;
- Tools.TraceLine("error, could not convert runtime from string {0}", ex);
- }
- //var msg = String.Format("\tRuntime found {0}", runtime);
- //Trace.WriteLine(msg);
- }
- //TODO Genres, need to figure out best way to sort multiple vals
- //find the genres
- //since it's so similar I've set the maturity level here instead of in the rating method
- string path = @"/catalog_title/category[@scheme]";
- var nodes = catalog_title.SelectNodes(path);
- List<String> genre_list = new List<string>();
- foreach (XmlNode node in nodes)
- {
- string label = node.Attributes["label"].Value;
- genre_list.Add(label);
- }
- //since the last one is always maturity level, use that as mat_level
- // but make sure it's a number first, otherwise it's a genre and there's no mat level
- string maturity_level = genre_list[genre_list.Count-1];
- int mat_level;
- if (int.TryParse(maturity_level, out mat_level))
- {
- //if maturity_level is a number, assign it to Title and remove it
- //waste mat_level
- genre_list.Remove(maturity_level);
- try {
- createdTitle.MaturityLevel = Convert.ToInt32(maturity_level);
- }
- catch (Exception ex) {
- createdTitle.MaturityLevel = 200;
- Tools.TraceLine("Could not convert maturity string to int {0}", ex);
- }
- }
- //now we join the genre_list with commas and assign it to Title
- string genres = string.Join(", ", genre_list);
- createdTitle.Genres = genres;
- //create all the Genres found too
- //var db = NextFlicksMVC4.Controllers.MoviesController.db;
- var db = new MovieDbContext();
- foreach (string genre_string in genre_list)
- {
- //look in Genres Table for genre_String that matches and pull that out and add it to ListGenres
- string qry = "select * from Genres where genre_string = {0}";
- var res =db.Genres.SqlQuery(qry, genre_string);
- var selected_genre = res.ToList()[0];
- createdTitle.ListGenres.Add(selected_genre);
- }
- db.Dispose();
- //Trace.WriteLine("added Primary Data to title");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement