Advertisement
TankorSmash

Untitled

Feb 11th, 2013
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.96 KB | None | 0 0
  1. /// <summary>
  2. /// Adds Title, Art, Year, Runtime, Genres
  3. /// </summary>
  4. /// <param name="createdTitle"></param>
  5. public static void AddPrimaryData(Title createdTitle, XmlNode catalog_title)
  6. {
  7. //find the title node, use the short title
  8. var title_node = catalog_title.SelectNodes("title")[0];
  9. var short_title = title_node.Attributes["short"].Value;
  10. var regular_title = title_node.Attributes["regular"].Value;
  11. createdTitle.TitleString = short_title;
  12.  
  13. //TODO: Box Art
  14.  
  15. //find the year released
  16. var release_node = catalog_title.SelectSingleNode("release_year");
  17. var year = release_node.InnerText;
  18.  
  19. if (year != "") {
  20. createdTitle.ReleaseYear = Convert.ToInt32(year);
  21. }
  22. else if (year == "") {
  23. createdTitle.ReleaseYear = 0;
  24. }
  25.  
  26. //find the runtime
  27. var runtime_node = catalog_title.SelectSingleNode("link/delivery_formats/availability/runtime");
  28. if (runtime_node != null)
  29. {
  30. var runtime = runtime_node.InnerText;
  31. try {
  32. createdTitle.RuntimeInSeconds = Convert.ToInt32(runtime);
  33. }
  34. catch (Exception ex) {
  35. createdTitle.RuntimeInSeconds = 0;
  36. Tools.TraceLine("error, could not convert runtime from string {0}", ex);
  37. }
  38. //var msg = String.Format("\tRuntime found {0}", runtime);
  39. //Trace.WriteLine(msg);
  40. }
  41.  
  42. //TODO Genres, need to figure out best way to sort multiple vals
  43. //find the genres
  44. //since it's so similar I've set the maturity level here instead of in the rating method
  45. string path = @"/catalog_title/category[@scheme]";
  46. var nodes = catalog_title.SelectNodes(path);
  47.  
  48. List<String> genre_list = new List<string>();
  49. foreach (XmlNode node in nodes)
  50. {
  51. string label = node.Attributes["label"].Value;
  52. genre_list.Add(label);
  53. }
  54.  
  55. //since the last one is always maturity level, use that as mat_level
  56. // but make sure it's a number first, otherwise it's a genre and there's no mat level
  57. string maturity_level = genre_list[genre_list.Count-1];
  58. int mat_level;
  59. if (int.TryParse(maturity_level, out mat_level))
  60. {
  61. //if maturity_level is a number, assign it to Title and remove it
  62. //waste mat_level
  63. genre_list.Remove(maturity_level);
  64. try {
  65. createdTitle.MaturityLevel = Convert.ToInt32(maturity_level);
  66. }
  67. catch (Exception ex) {
  68. createdTitle.MaturityLevel = 200;
  69. Tools.TraceLine("Could not convert maturity string to int {0}", ex);
  70. }
  71. }
  72.  
  73. //now we join the genre_list with commas and assign it to Title
  74. string genres = string.Join(", ", genre_list);
  75. createdTitle.Genres = genres;
  76.  
  77.  
  78. //create all the Genres found too
  79. //var db = NextFlicksMVC4.Controllers.MoviesController.db;
  80. var db = new MovieDbContext();
  81. foreach (string genre_string in genre_list)
  82. {
  83. //look in Genres Table for genre_String that matches and pull that out and add it to ListGenres
  84. string qry = "select * from Genres where genre_string = {0}";
  85. var res =db.Genres.SqlQuery(qry, genre_string);
  86. var selected_genre = res.ToList()[0];
  87. createdTitle.ListGenres.Add(selected_genre);
  88.  
  89. }
  90. db.Dispose();
  91.  
  92.  
  93. //Trace.WriteLine("added Primary Data to title");
  94.  
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement