Esempio n. 1
0
 private void readCollectionFromFile()
 {
     using (FileStream fs = new FileStream("data\\my collection.bin", FileMode.Open))
     {
         using (BinaryReader br = new BinaryReader(fs))
         {
             while (br.BaseStream.Position != br.BaseStream.Length)
             {
                 string        movieName        = br.ReadString();
                 string        moviePlot        = br.ReadString();
                 int           movieReleaseYear = br.ReadInt32();
                 List <string> movieGenre       = new List <string>();
                 int           numOfGenres      = br.ReadInt32();
                 while (numOfGenres > 0)
                 {
                     movieGenre.Add(br.ReadString());
                     numOfGenres--;
                 }
                 List <ActorRole> movieCast = new List <ActorRole>();
                 int numOfActors            = br.ReadInt32();
                 while (numOfActors > 0)
                 {
                     string    actorName = br.ReadString();
                     string    actorUrl  = br.ReadString();
                     string    role      = br.ReadString();
                     ActorRole actorRole = new ActorRole(new Actor(actorName, actorUrl), role);
                     movieCast.Add(actorRole);
                     numOfActors--;
                 }
                 Movie movie = new Movie(movieName, moviePlot, movieReleaseYear, movieGenre, movieCast);
                 myCollection.Add(movie);
             }
         }
     }
 }
Esempio n. 2
0
        private void extractMovieDetails(HtmlDocument doc)
        {
            //get the plot
            HtmlNode[] nodes = doc.DocumentNode.SelectNodes("//div[@class=\"summary_text\"]").ToArray();
            moviePlot = nodes[0].InnerText.Trim();
            //get the genres
            movieGenre = new List <string>();
            HtmlNode[] genreNodes = doc.DocumentNode.SelectNodes("//div[@id=\"title-overview-widget\"]/div[2]/div[2]/div/div[2]/div[2]/div/a//span").ToArray();
            foreach (HtmlNode genreNode in genreNodes)
            {
                movieGenre.Add(genreNode.InnerText);
            }
            //get the cast
            HtmlNode[] castTableNodes = doc.DocumentNode.SelectNodes("//*[@id=\"titleCast\"]/table//tr").ToArray();
            bool       firstRow       = true;

            foreach (HtmlNode row in castTableNodes)
            {
                if (firstRow)
                {
                    firstRow = false;
                    continue;
                }
                int    i = 0;
                string actorName = "", actorUrl = "", role = "", picUrl = "";
                foreach (HtmlNode column in row.SelectNodes(".//td[1]|td[2]|td[4]"))
                {
                    if (i % 3 == 1)
                    {
                        //extract actor data
                        actorName = column.InnerText.Trim();
                        actorUrl  = DOMAIN + column.SelectNodes(".//a")[0].GetAttributeValue("href", "");
                    }
                    else if (i % 3 == 2)
                    { //extract actor's role in the movie
                        role = column.InnerText.Trim();
                        ActorRole actorRole = new ActorRole(new Actor(actorName, actorUrl, picUrl), role);
                        movieCast.Add(actorRole);
                    }
                    else
                    {
                        //get actor pic
                        HtmlNode actorPicNode = column.SelectNodes(".//a/img").First();
                        picUrl = actorPicNode.GetAttributeValue("loadlate", "");
                    }
                    i++;
                }
            }
        }