Esempio n. 1
0
        /// <summary>
        /// returns a merged entry from imdb and tomatoes entries to create a new OmdbEntry
        /// </summary>
        /// <param name="imdb_entry"></param>
        /// <param name="tomato_entry"></param>
        /// <returns>a completely new OmdbEntry</returns>
        public static OmdbEntry MergeImdbWithTomatoesOmdbEntry(
            OmdbEntry imdb_entry, OmdbEntry tomato_entry)
        {
            OmdbEntry created_entry = new OmdbEntry
            {
                ombd_ID = imdb_entry.ombd_ID,
                title   = imdb_entry.title,
                year    = imdb_entry.year,

                i_ID     = imdb_entry.i_ID,
                i_Rating = imdb_entry.i_Rating,
                i_Votes  = imdb_entry.i_Votes,

                t_Image       = imdb_entry.t_Image,
                t_Consensus   = tomato_entry.t_Consensus,
                t_Fresh       = tomato_entry.t_Fresh,
                t_Meter       = tomato_entry.t_Meter,
                t_Rating      = tomato_entry.t_Rating,
                t_Reviews     = tomato_entry.t_Reviews,
                t_Rotten      = tomato_entry.t_Rotten,
                t_UserMeter   = tomato_entry.t_UserMeter,
                t_UserRating  = tomato_entry.t_UserRating,
                t_UserReviews = tomato_entry.t_UserReviews
            };

            return(created_entry);
        }
Esempio n. 2
0
        public bool Equals(OmdbEntry omdb)
        {
            // If parameter is null return false:
            if ((object)omdb == null)
            {
                return(false);
            }

            //return (this.title == omdb.title &&
            //    this.year == omdb.year &&
            //    this.i_ID == omdb.i_ID);
            return(
                //ignore because I'm not sure when a movie_id will or wont be set
                //this.movie_ID == omdb.movie_ID &&
                this.title == omdb.title &&
                this.year == omdb.year &&
                this.i_Rating == omdb.i_Rating &&
                this.i_Votes == omdb.i_Votes &&
                this.i_ID == omdb.i_ID &&
                this.t_Meter == omdb.t_Meter &&
                this.t_Image == omdb.t_Image &&
                //ignore cause of float
                //this.t_Rating == omdb.t_Rating &&
                this.t_Reviews == omdb.t_Reviews &&
                this.t_Fresh == omdb.t_Fresh &&
                this.t_Rotten == omdb.t_Rotten &&
                this.t_Consensus == omdb.t_Consensus &&
                this.t_UserMeter == omdb.t_UserMeter &&
                //ignore cause of float
                //this.t_UserRating == omdb.t_UserRating &&
                this.t_UserReviews == omdb.t_UserReviews);
        }
Esempio n. 3
0
        //return all below
        public static OmdbEntry GetOmdbEntryForMovie(string title,
                                                     string year          = null,
                                                     string response_type = "xml",
                                                     string tomatoes      = "true")
        {
            Trace.WriteLine("creating Omdb entry");
            var       xml       = GetOmbdbTitleInfoFromApi(title, year, response_type, tomatoes);
            var       xDoc      = GetXmlDocumentFromOmdbResponse(xml);
            OmdbEntry omdbEntry = CreateOmdbEntryFromXmlDocument(xDoc);

            Trace.WriteLine(" done creating Omdb entry");

            return(omdbEntry);
        }
        public void TestMergeTwoOmdbEntryLists()
        {
            //create a imdb OE
            OmdbEntry imdb_omdbentry = new OmdbEntry
                                           {
                                               i_ID = "asd",
                                               i_Rating = "asd",
                                               i_Votes = "123"
                                           };
            List<OmdbEntry> imdb_list = new List<OmdbEntry> {imdb_omdbentry};

            //create a RT OE
            OmdbEntry rt_omdbentry = new OmdbEntry
                                         {
                                             t_Consensus = "rotten",
                                             t_Fresh = 123,
                                             t_Image = "asddd",
                                             t_Meter = 123,
                                             t_Reviews = 12355,
                                             t_Rotten = 333,
                                             t_UserMeter = 233,
                                             t_UserReviews = 3
                                         };
            List<OmdbEntry> rt_list = new List<OmdbEntry> {rt_omdbentry};

            //expected OE result
            OmdbEntry expected_omdbentry = new OmdbEntry
                                               {

                                                   i_ID = "asd",
                                                   i_Rating = "asd",
                                                   i_Votes = "123",
                                                   t_Consensus = "rotten",
                                                   t_Fresh = 123,
                                                   t_Image = "asddd",
                                                   t_Meter = 123,
                                                   t_Reviews = 12355,
                                                   t_Rotten = 333,
                                                   t_UserMeter = 233,
                                                   t_UserReviews = 3
                                               };

            List<OmdbEntry> res = TSVParse.MergeTwoOmdbEntryLists(imdb_list,
                                                                  rt_list);
            OmdbEntry resulting_omdbentry = res[0];
            Assert.AreEqual(expected_omdbentry, resulting_omdbentry);
            Assert.AreNotEqual(new OmdbEntry(), resulting_omdbentry);
        }
Esempio n. 5
0
 /// <summary>
 /// Takes two partial OmdbEntrys and updates the Imdb one
 /// </summary>
 /// <param name="matchedExistingImdbOmdbentry">The OmdbEntry to merge on</param>
 /// <param name="matching_RT_data">The OmdbEntry that'll be fed to the imdb one</param>
 public static void UpdateImdbEntryWithRtEntry(
     OmdbEntry matchedExistingImdbOmdbentry, OmdbEntry matching_RT_data)
 {
     //update the imdb entry
     matchedExistingImdbOmdbentry.t_Image       = matching_RT_data.t_Image;
     matchedExistingImdbOmdbentry.t_Meter       = matching_RT_data.t_Meter;
     matchedExistingImdbOmdbentry.t_Image       = matching_RT_data.t_Image;
     matchedExistingImdbOmdbentry.t_Rating      = matching_RT_data.t_Rating;
     matchedExistingImdbOmdbentry.t_Reviews     = matching_RT_data.t_Reviews;
     matchedExistingImdbOmdbentry.t_Fresh       = matching_RT_data.t_Fresh;
     matchedExistingImdbOmdbentry.t_Rotten      = matching_RT_data.t_Rotten;
     matchedExistingImdbOmdbentry.t_Consensus   = matching_RT_data.t_Consensus;
     matchedExistingImdbOmdbentry.t_UserMeter   = matching_RT_data.t_UserMeter;
     matchedExistingImdbOmdbentry.t_UserRating  = matching_RT_data.t_UserRating;
     matchedExistingImdbOmdbentry.t_UserReviews = matching_RT_data.t_UserReviews;
 }
        public static OmdbEntry Omdb(int movieID)
        {
            MovieDbContext db = new MovieDbContext();
            OmdbEntry omdb = new OmdbEntry();

            omdb = Tools.MatchMovieIdToOmdbEntry(movieID);
            return omdb;
            /* for posterity in case Tools.Cs changes
             *  public static OmdbEntry MatchMovieIdToOmdbEntry(int movie_ID)
                {
                    MovieDbContext db = new MovieDbContext();
                    var omdbEntry = db.Omdb.FirstOrDefault(omdb => omdb.movie_ID == movie_ID);

                   return omdbEntry;
                }*/
        }
Esempio n. 7
0
        public override bool Equals(object obj)
        {
            // If parameter is null return false.
            if (obj == null)
            {
                return(false);
            }
            // If parameter cannot be cast to Point return false.
            OmdbEntry omdb = obj as OmdbEntry;

            if ((System.Object)omdb == null)
            {
                return(false);
            }

            //return (this.title == omdb.title &&
            //    this.year == omdb.year &&
            //    this.i_ID == omdb.i_ID &&);

            return(
                //ignore because I'm not sure when a movie_id will or wont be set
                //this.movie_ID == omdb.movie_ID &&
                this.title == omdb.title &&
                this.year == omdb.year &&
                this.i_Rating == omdb.i_Rating &&
                this.i_Votes == omdb.i_Votes &&
                this.i_ID == omdb.i_ID &&
                this.t_Meter == omdb.t_Meter &&
                this.t_Image == omdb.t_Image &&
                //ignore cause of float
                //this.t_Rating == omdb.t_Rating &&
                this.t_Reviews == omdb.t_Reviews &&
                this.t_Fresh == omdb.t_Fresh &&
                this.t_Rotten == omdb.t_Rotten &&
                this.t_Consensus == omdb.t_Consensus &&
                this.t_UserMeter == omdb.t_UserMeter &&
                //ignore cause of float
                //this.t_UserRating == omdb.t_UserRating &&
                this.t_UserReviews == omdb.t_UserReviews);
        }
        public void TestUpdateImdbEntryWithRtEntry()
        {
            var imdb_param = new OmdbEntry();
            var rt_param = new OmdbEntry
                               {
                                   t_Consensus = "asd",
                                   t_Fresh = 123,
                                   t_Image = "asd",
                                   t_Meter = 123,
                                   t_Rating = 1.2f,
                                   t_Reviews = 123,
                                   t_Rotten = 123,
                                   t_UserMeter = 1234,
                                   t_UserRating = 12.4f,
                                   t_UserReviews = 12345
                               };

            TSVParse.UpdateImdbEntryWithRtEntry(imdb_param, rt_param);

            OmdbEntry expected = new OmdbEntry
                                     {
                                         t_Consensus = "asd",
                                         t_Fresh = 123,
                                         t_Image = "asd",
                                         t_Meter = 123,
                                         t_Rating = 1.2f,
                                         t_Reviews = 123,
                                         t_Rotten = 123,
                                         t_UserMeter = 1234,
                                         t_UserRating = 12.4f,
                                         t_UserReviews = 12345
                                     };

            Assert.AreEqual(imdb_param, expected);
            Assert.AreNotEqual(imdb_param, new OmdbEntry());
        }
        public static IQueryable<FullViewModel> CreateFullView(IQueryable<Movie> movies, MovieDbContext db)
        {
            // var db = new MovieDbContext();

            var movieID_genreString_grouping = from mtg in db.MovieToGenres
                                               join genre in db.Genres on
                                                   mtg.genre_ID equals
                                                   genre.genre_ID
                                               group genre.genre_string by
                                                   mtg.movie_ID;

            //a default empty element
            OmdbEntry defaultOmdbEntry = new OmdbEntry
            {
            };

            var nitvmQuery =
                //left outer join so that all movies get selected even if there's no omdb match
                from movie in movies
                join omdb in db.Omdb on
                    movie.movie_ID equals omdb.movie_ID into mov_omdb_matches
                from mov_omdb_match in mov_omdb_matches.DefaultIfEmpty()
                //match the boxarts
                from boxart in db.BoxArts
                where movie.movie_ID == boxart.movie_ID
                //match the genres string
                from grp in movieID_genreString_grouping
                where grp.Key == movie.movie_ID
                //match the genre id

                //create the NITVM
                select new FullViewModel
                {
                    Movie = movie,
                    Boxarts = boxart,
                    Genres = grp,
                    Genre_IDs = (List<int>)(from mtg in db.MovieToGenres
                                            where mtg.movie_ID == movie.movie_ID
                                            select mtg.genre_ID),
                    //OmdbEntry = (mov_omdb_match == null) ? mov_omdb_match.movie_ID= movie.movie_ID: mov_omdb_match
                    OmdbEntry = mov_omdb_match
                };

            return nitvmQuery;
        }
        public void TestOmdbEquals()
        {
            OmdbEntry first_movie = new OmdbEntry
                                    {
                                        //ignore because I'm not sure when a movie_id will or wont be set
                                        //movie_ID = ,
                                        title = "movie called",
                                        year = 1999,
                                        i_Rating = "asd",
                                        i_Votes = "400",
                                        i_ID = "asd",
                                        t_Meter = 2,
                                        t_Image = "asd",
                                        //ignore cause of float
                                        //t_Rating = 22,
                                        t_Reviews = 123,
                                        t_Fresh = 23,
                                        t_Rotten = 23,
                                        t_Consensus = "rotten",
                                        t_UserMeter = 233,
                                        //ignore cause of float
                                        //t_UserRating = 2.4f,
                                        t_UserReviews = 232,
                                    };

            OmdbEntry second_movie = new OmdbEntry
                                    {
                                        //ignore because I'm not sure when a movie_id will or wont be set
                                        //movie_ID = ,
                                        title = "movie called",
                                        year = 1999,
                                        i_Rating = "asd",
                                        i_Votes = "400",
                                        i_ID = "asd",
                                        t_Meter = 2,
                                        t_Image = "asd",
                                        //ignore cause of float
                                        //t_Rating = 22,
                                        t_Reviews = 123,
                                        t_Fresh = 23,
                                        t_Rotten = 23,
                                        t_Consensus = "rotten",
                                        t_UserMeter = 233,
                                        //ignore cause of float
                                        //t_UserRating = 2.4f,
                                        t_UserReviews = 232,
                                    };
                                    //{
                                    //    year = 1999,
                                    //    i_ID = "200",
                                    //    i_Votes = "12345"
                                    //};
            Assert.AreEqual(first_movie, second_movie);

            OmdbEntry bogus_movie = new OmdbEntry
                                        {
                                            t_Consensus = "asd",
                                        };

            Assert.AreNotEqual(first_movie, bogus_movie);
            Assert.AreNotEqual(second_movie, bogus_movie);
        }
Esempio n. 11
0
        /// <summary>
        /// Creates a OmdbEntry either from a imdb or tomatoes TSV.
        ///  Send either one or both reader, and a premade entry
        ///  if you want to fill it out
        /// </summary>
        /// <param name="imdbReader"></param>
        /// <param name="tomReader"></param>
        /// <param name="premadeEntry"></param>
        /// <returns></returns>
        public static OmdbEntry CreateOmdbEntryFromTsvRecord(
            CsvReader imdbReader = null, CsvReader tomReader = null, OmdbEntry premadeEntry = null)
        {
            //if there's a imdbReader, use its contents to fill the first half of a OE
            OmdbEntry omdbEntry;
            if (imdbReader != null) {
                omdbEntry = new OmdbEntry
                                {
                                    ombd_ID = Convert.ToInt32( imdbReader["ID"]),

                                    title = imdbReader["title"],
                                    year = Convert.ToInt32(imdbReader["year"]),

                                    i_Votes = imdbReader["imdbVotes"],
                                    i_Rating = imdbReader["imdbRating"],
                                    i_ID = imdbReader["imdbID"],
                                };
            }

            //if there's a premade entry, we want to fill that with tom data, or create a new one to fill
            else {
                if (premadeEntry != null) {
                    omdbEntry = premadeEntry;
                }
                else {
                    omdbEntry = new OmdbEntry();
                }
            }
            //so long as there's a tom reader, fill the OEntry with relevant data
            if (tomReader != null)
            {
                omdbEntry.ombd_ID = Convert.ToInt32(tomReader["ID"]);
                omdbEntry.t_Image = tomReader["Image"];

                float t_rating;
                float.TryParse(tomReader["Rating"], out t_rating);
                omdbEntry.t_Rating = t_rating;

                int t_meter;
                int.TryParse(tomReader["Meter"], out t_meter);
                omdbEntry.t_Meter = t_meter;

                int t_reviews;
                int.TryParse(tomReader["Reviews"], out t_reviews);
                omdbEntry.t_Reviews = t_reviews;

                //might be "n/a" or ""  so I've got to account for that
                int t_fresh;
                int.TryParse(tomReader["Fresh"],out t_fresh);
                omdbEntry.t_Fresh = t_fresh;

                int t_rotten;
                int.TryParse(tomReader["Rotten"], out t_rotten);
                omdbEntry.t_Rotten = t_rotten;

                omdbEntry.t_Consensus = tomReader["Consensus"];

                int t_usermeter;
                int.TryParse(tomReader["userMeter"], out t_usermeter);
                omdbEntry.t_UserMeter = t_usermeter;

                float t_userrating;
                float.TryParse(tomReader["userRating"], out t_userrating);
                omdbEntry.t_UserRating = t_userrating;
                //same as above, need to deal with "n/a"
                int t_userreviews;
                int.TryParse(tomReader["userReviews"], out t_userreviews);
                omdbEntry.t_UserReviews = t_userreviews;
            }

            return omdbEntry;
        }
Esempio n. 12
0
        public bool Equals(OmdbEntry omdb)
        {
            // If parameter is null return false:
            if ((object)omdb == null)
            {
                return false;
            }

            //return (this.title == omdb.title &&
            //    this.year == omdb.year &&
            //    this.i_ID == omdb.i_ID);
            return (
                //ignore because I'm not sure when a movie_id will or wont be set
                //this.movie_ID == omdb.movie_ID &&
                this.title == omdb.title &&
                this.year == omdb.year &&
                this.i_Rating == omdb.i_Rating &&
                this.i_Votes == omdb.i_Votes &&
                this.i_ID == omdb.i_ID &&
                this.t_Meter == omdb.t_Meter &&
                this.t_Image == omdb.t_Image &&
                //ignore cause of float
                //this.t_Rating == omdb.t_Rating &&
                this.t_Reviews == omdb.t_Reviews &&
                this.t_Fresh == omdb.t_Fresh &&
                this.t_Rotten == omdb.t_Rotten &&
                this.t_Consensus == omdb.t_Consensus &&
                this.t_UserMeter == omdb.t_UserMeter &&
                //ignore cause of float
                //this.t_UserRating == omdb.t_UserRating &&
                this.t_UserReviews == omdb.t_UserReviews);
        }
Esempio n. 13
0
        //serve create object from xmlDoc
        private static OmdbEntry CreateOmdbEntryFromXmlDocument(
            XmlDocument xmlDocument)
        {
            if (xmlDocument.SelectSingleNode(@"/root/@response").InnerText ==
                "False") {
                return new OmdbEntry();
            }
            else {

                OmdbEntry omdbEntry;
                omdbEntry = new OmdbEntry
                                {
                                    title =
                                        xmlDocument.SelectSingleNode(
                                            "/root/movie/@title")
                                                   .InnerText,
                                    year =
                                        Convert.ToInt32(xmlDocument.SelectSingleNode(
                                            "/root/movie/@year").InnerText),
                                    i_Votes =
                                        xmlDocument.SelectSingleNode(
                                            "/root/movie/@imdbVotes").InnerText,
                                    i_Rating =
                                        xmlDocument.SelectSingleNode(
                                            "/root/movie/@imdbRating").InnerText,
                                    i_ID =
                                        xmlDocument.SelectSingleNode(
                                            "/root/movie/@imdbID").InnerText,
                                    t_Meter =
                                        Convert.ToInt32(xmlDocument.SelectSingleNode(
                                            "/root/movie/@tomatoMeter")
                                                                   .InnerText),
                                    t_Image =
                                        xmlDocument.SelectSingleNode(
                                            "/root/movie/@tomatoImage")
                                                   .InnerText,
                                    t_Rating =
                                        Convert.ToSingle(xmlDocument.SelectSingleNode(
                                            "/root/movie/@tomatoRating")
                                                                    .InnerText),
                                    t_Reviews =
                                        Convert.ToInt32(xmlDocument.SelectSingleNode(
                                            "/root/movie/@tomatoReviews")
                                                                   .InnerText),
                                    t_Fresh =
                                        Convert.ToInt32(xmlDocument.SelectSingleNode(
                                            "/root/movie/@tomatoFresh")
                                                                   .InnerText),
                                    t_Rotten =
                                        Convert.ToInt32(xmlDocument.SelectSingleNode(
                                            "/root/movie/@tomatoRotten")
                                                                   .InnerText),
                                    t_Consensus =
                                        xmlDocument.SelectSingleNode(
                                            "/root/movie/@tomatoConsensus")
                                                   .InnerText,
                                    t_UserMeter =
                                        Convert.ToInt32(xmlDocument.SelectSingleNode(
                                            "/root/movie/@tomatoUserMeter")
                                                                   .InnerText),
                                    t_UserRating =
                                        Convert.ToSingle(xmlDocument.SelectSingleNode(
                                            "/root/movie/@tomatoUserRating")
                                                                    .InnerText),
                                    t_UserReviews =
                                        Convert.ToInt32(xmlDocument.SelectSingleNode(
                                            "/root/movie/@tomatoUserReviews")
                                                                   .InnerText),
                                };

                return omdbEntry;
            }
        }
Esempio n. 14
0
        /// <summary>
        /// returns a merged entry from imdb and tomatoes entries to create a new OmdbEntry
        /// </summary>
        /// <param name="imdb_entry"></param>
        /// <param name="tomato_entry"></param>
        /// <returns>a completely new OmdbEntry</returns>
        public static OmdbEntry MergeImdbWithTomatoesOmdbEntry(
            OmdbEntry imdb_entry, OmdbEntry tomato_entry)
        {
            OmdbEntry created_entry = new OmdbEntry
                                          {
                                              ombd_ID = imdb_entry.ombd_ID,
                                              title = imdb_entry.title,
                                              year = imdb_entry.year,

                                              i_ID = imdb_entry.i_ID,
                                              i_Rating = imdb_entry.i_Rating,
                                              i_Votes =  imdb_entry.i_Votes,

                                              t_Image = imdb_entry.t_Image,
                                              t_Consensus = tomato_entry.t_Consensus,
                                              t_Fresh = tomato_entry.t_Fresh,
                                              t_Meter = tomato_entry.t_Meter,
                                              t_Rating = tomato_entry.t_Rating,
                                              t_Reviews = tomato_entry.t_Reviews,
                                              t_Rotten = tomato_entry.t_Rotten,
                                              t_UserMeter = tomato_entry.t_UserMeter,
                                              t_UserRating = tomato_entry.t_UserRating,
                                              t_UserReviews = tomato_entry.t_UserReviews

                                          };

            return created_entry;
        }
Esempio n. 15
0
 /// <summary>
 /// Takes two partial OmdbEntrys and updates the Imdb one
 /// </summary>
 /// <param name="matchedExistingImdbOmdbentry">The OmdbEntry to merge on</param>
 /// <param name="matching_RT_data">The OmdbEntry that'll be fed to the imdb one</param>
 public static void UpdateImdbEntryWithRtEntry(
     OmdbEntry matchedExistingImdbOmdbentry, OmdbEntry matching_RT_data)
 {
     //update the imdb entry
     matchedExistingImdbOmdbentry.t_Image = matching_RT_data.t_Image;
     matchedExistingImdbOmdbentry.t_Meter = matching_RT_data.t_Meter;
     matchedExistingImdbOmdbentry.t_Image = matching_RT_data.t_Image;
     matchedExistingImdbOmdbentry.t_Rating = matching_RT_data.t_Rating;
     matchedExistingImdbOmdbentry.t_Reviews = matching_RT_data.t_Reviews;
     matchedExistingImdbOmdbentry.t_Fresh = matching_RT_data.t_Fresh;
     matchedExistingImdbOmdbentry.t_Rotten = matching_RT_data.t_Rotten;
     matchedExistingImdbOmdbentry.t_Consensus = matching_RT_data.t_Consensus;
     matchedExistingImdbOmdbentry.t_UserMeter = matching_RT_data.t_UserMeter;
     matchedExistingImdbOmdbentry.t_UserRating = matching_RT_data.t_UserRating;
     matchedExistingImdbOmdbentry.t_UserReviews = matching_RT_data.t_UserReviews;
 }
Esempio n. 16
0
        //serve create object from xmlDoc
        private static OmdbEntry CreateOmdbEntryFromXmlDocument(
            XmlDocument xmlDocument)
        {
            if (xmlDocument.SelectSingleNode(@"/root/@response").InnerText ==
                "False")
            {
                return(new OmdbEntry());
            }
            else
            {
                OmdbEntry omdbEntry;
                omdbEntry = new OmdbEntry
                {
                    title =
                        xmlDocument.SelectSingleNode(
                            "/root/movie/@title")
                        .InnerText,
                    year =
                        Convert.ToInt32(xmlDocument.SelectSingleNode(
                                            "/root/movie/@year").InnerText),
                    i_Votes =
                        xmlDocument.SelectSingleNode(
                            "/root/movie/@imdbVotes").InnerText,
                    i_Rating =
                        xmlDocument.SelectSingleNode(
                            "/root/movie/@imdbRating").InnerText,
                    i_ID =
                        xmlDocument.SelectSingleNode(
                            "/root/movie/@imdbID").InnerText,
                    t_Meter =
                        Convert.ToInt32(xmlDocument.SelectSingleNode(
                                            "/root/movie/@tomatoMeter")
                                        .InnerText),
                    t_Image =
                        xmlDocument.SelectSingleNode(
                            "/root/movie/@tomatoImage")
                        .InnerText,
                    t_Rating =
                        Convert.ToSingle(xmlDocument.SelectSingleNode(
                                             "/root/movie/@tomatoRating")
                                         .InnerText),
                    t_Reviews =
                        Convert.ToInt32(xmlDocument.SelectSingleNode(
                                            "/root/movie/@tomatoReviews")
                                        .InnerText),
                    t_Fresh =
                        Convert.ToInt32(xmlDocument.SelectSingleNode(
                                            "/root/movie/@tomatoFresh")
                                        .InnerText),
                    t_Rotten =
                        Convert.ToInt32(xmlDocument.SelectSingleNode(
                                            "/root/movie/@tomatoRotten")
                                        .InnerText),
                    t_Consensus =
                        xmlDocument.SelectSingleNode(
                            "/root/movie/@tomatoConsensus")
                        .InnerText,
                    t_UserMeter =
                        Convert.ToInt32(xmlDocument.SelectSingleNode(
                                            "/root/movie/@tomatoUserMeter")
                                        .InnerText),
                    t_UserRating =
                        Convert.ToSingle(xmlDocument.SelectSingleNode(
                                             "/root/movie/@tomatoUserRating")
                                         .InnerText),
                    t_UserReviews =
                        Convert.ToInt32(xmlDocument.SelectSingleNode(
                                            "/root/movie/@tomatoUserReviews")
                                        .InnerText),
                };

                return(omdbEntry);
            }
        }
Esempio n. 17
0
        /// <summary>
        /// Creates a OmdbEntry either from a imdb or tomatoes TSV.
        ///  Send either one or both reader, and a premade entry
        ///  if you want to fill it out
        /// </summary>
        /// <param name="imdbReader"></param>
        /// <param name="tomReader"></param>
        /// <param name="premadeEntry"></param>
        /// <returns></returns>
        public static OmdbEntry CreateOmdbEntryFromTsvRecord(
            CsvReader imdbReader = null, CsvReader tomReader = null, OmdbEntry premadeEntry = null)
        {
            //if there's a imdbReader, use its contents to fill the first half of a OE
            OmdbEntry omdbEntry;

            if (imdbReader != null)
            {
                omdbEntry = new OmdbEntry
                {
                    ombd_ID = Convert.ToInt32(imdbReader["ID"]),

                    title = imdbReader["title"],
                    year  = Convert.ToInt32(imdbReader["year"]),

                    i_Votes  = imdbReader["imdbVotes"],
                    i_Rating = imdbReader["imdbRating"],
                    i_ID     = imdbReader["imdbID"],
                };
            }

            //if there's a premade entry, we want to fill that with tom data, or create a new one to fill
            else
            {
                if (premadeEntry != null)
                {
                    omdbEntry = premadeEntry;
                }
                else
                {
                    omdbEntry = new OmdbEntry();
                }
            }
            //so long as there's a tom reader, fill the OEntry with relevant data
            if (tomReader != null)
            {
                omdbEntry.ombd_ID = Convert.ToInt32(tomReader["ID"]);
                omdbEntry.t_Image = tomReader["Image"];

                float t_rating;
                float.TryParse(tomReader["Rating"], out t_rating);
                omdbEntry.t_Rating = t_rating;

                int t_meter;
                int.TryParse(tomReader["Meter"], out t_meter);
                omdbEntry.t_Meter = t_meter;

                int t_reviews;
                int.TryParse(tomReader["Reviews"], out t_reviews);
                omdbEntry.t_Reviews = t_reviews;

                //might be "n/a" or ""  so I've got to account for that
                int t_fresh;
                int.TryParse(tomReader["Fresh"], out t_fresh);
                omdbEntry.t_Fresh = t_fresh;

                int t_rotten;
                int.TryParse(tomReader["Rotten"], out t_rotten);
                omdbEntry.t_Rotten = t_rotten;

                omdbEntry.t_Consensus = tomReader["Consensus"];

                int t_usermeter;
                int.TryParse(tomReader["userMeter"], out t_usermeter);
                omdbEntry.t_UserMeter = t_usermeter;

                float t_userrating;
                float.TryParse(tomReader["userRating"], out t_userrating);
                omdbEntry.t_UserRating = t_userrating;
                //same as above, need to deal with "n/a"
                int t_userreviews;
                int.TryParse(tomReader["userReviews"], out t_userreviews);
                omdbEntry.t_UserReviews = t_userreviews;
            }


            return(omdbEntry);
        }