Ejemplo n.º 1
0
 private void Main_Load(object sender, EventArgs e)
 {
     SeenListUserControl = new SeenListUC(0, this);
     MoviesFLP.Controls.Add(SeenListUserControl);
     WishListUserControl = new WishListUC(Properties.Settings.Default.WishList.Count, this);
     MoviesFLP.Controls.Add(WishListUserControl);
 }
Ejemplo n.º 2
0
        private void ThreadBW_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            if (apiSelect == 0)
            {
                string url = string.Empty;

                if (!isSingle)
                {
                    url = OMDB.multipleAddress + SearchTb.Text.Trim() + "&apikey=" + OMDB.api;
                }
                else
                {
                    url = OMDB.singleAddress + SearchTb.Text.Trim() + "&apikey=" + OMDB.api;
                }
                using (WebClient wc = new WebClient())
                {
                    string        json   = wc.DownloadString(url);
                    List <string> imdbId = new List <string>();

                    JavaScriptSerializer oJS = new JavaScriptSerializer();

                    if (!isSingle)
                    {
                        Entity_M = oJS.Deserialize <ImdbEntity_M>(json);
                        var movies = oJS.Serialize(Entity_M);

                        if (Entity_M.Response == "True")
                        {
                            foreach (var movie in Entity_M.Search)
                            {
                                MovieUC MovieUserControl = new MovieUC(movie.imdbID, movie.Title, movie.Year, movie.Poster,
                                                                       movie.Type, TitleInWishList(movie.imdbID), TitleInSeenList(movie.imdbID), this);

                                imdbId.Add(movie.imdbID);

                                MoviesFLP.Invoke(new MethodInvoker(delegate
                                {
                                    MoviesFLP.Controls.Add(MovieUserControl);
                                }));
                            }
                        }
                        else
                        {
                            MessageBox.Show("There was an error requesting movie data", "Error");
                        }
                    }
                    else
                    {
                        Entity_S = oJS.Deserialize <ImdbEntity_S>(json);

                        if (Entity_S.Response == "True")
                        {
                            MovieUC MovieUserControl = new MovieUC(Entity_M.imdbID, Entity_S.Title, Entity_S.Year, Entity_S.Poster,
                                                                   Entity_S.Type, TitleInWishList(Entity_S.imdbID), TitleInSeenList(Entity_S.imdbID), this);

                            imdbId.Add(Entity_M.imdbID);

                            MoviesFLP.Invoke(new MethodInvoker(delegate
                            {
                                MoviesFLP.Controls.Add(MovieUserControl);
                            }));
                        }
                        else
                        {
                            MessageBox.Show("There was an error requesting movie data", "Error");
                        }
                    }
                    SeenListUserControl = new SeenListUC(NumberOfMoviesSeenInSearchCategory(imdbId), this);
                    MoviesFLP.Invoke(new MethodInvoker(delegate
                    {
                        MoviesFLP.Controls.Add(SeenListUserControl);
                    }));

                    WishListUserControl = new WishListUC(Properties.Settings.Default.WishList.Count, this);
                    MoviesFLP.Invoke(new MethodInvoker(delegate
                    {
                        MoviesFLP.Controls.Add(WishListUserControl);
                    }));
                }
            }
            else if (apiSelect == 1)
            {
                string url = string.Empty;

                if (!isSingle)
                {
                    url = TMDB.multipleAddress + "search/movie?api_key=" + TMDB.api + "&query=" + SearchTb.Text.Trim();
                }
                else
                {
                    url = TMDB.singleAddress + "search/movie?api_key=" + TMDB.api + "&query=" + SearchTb.Text.Trim();
                }
                using (WebClient wc = new WebClient())
                {
                    string        json    = wc.DownloadString(url);
                    List <string> imdb_id = new List <string>();

                    JavaScriptSerializer oJS = new JavaScriptSerializer();

                    if (!isSingle)
                    {
                        entity_Tmdb = oJS.Deserialize <TmdbEntity>(json);
                        var movies = oJS.Serialize(entity_Tmdb);

                        if (movies != null)
                        {
                            foreach (var movie in entity_Tmdb.results)
                            {
                                MovieUC MovieUserControl = new MovieUC(movie.id, movie.title, movie.release_date, TMDB.posterUrl + movie.poster_path,
                                                                       "Movie", TitleInWishList(movie.imdb_id), TitleInSeenList(movie.imdb_id), this);

                                imdb_id.Add(movie.imdb_id);

                                MoviesFLP.Invoke(new MethodInvoker(delegate
                                {
                                    MoviesFLP.Controls.Add(MovieUserControl);
                                }));
                            }
                        }
                        else
                        {
                            MessageBox.Show("There was an error requesting movie data", "Error");
                        }
                    }
                    else
                    {
                        TMDB_entity_S = oJS.Deserialize <TmdbEntity_S>(json);

                        if (TMDB_entity_S.imdb_id != null)
                        {
                            string imdbID = TMDB_entity_S.imdb_id;
                            string Title  = TMDB_entity_S.original_title;
                            string Year   = TMDB_entity_S.release_date;
                            string Poster = TMDB_entity_S.poster_path;
                            string Type   = TMDB_entity_S.genres;

                            MovieUC MovieUserControl = new MovieUC(imdbID, Title, Year, Poster,
                                                                   Type, TitleInWishList(imdbID), TitleInSeenList(imdbID), this);

                            imdb_id.Add(TMDB_entity_S.imdb_id);

                            MoviesFLP.Invoke(new MethodInvoker(delegate
                            {
                                MoviesFLP.Controls.Add(MovieUserControl);
                            }));
                        }
                        else
                        {
                            MessageBox.Show("There was an error requesting movie data", "Error");
                        }
                    }
                    SeenListUserControl = new SeenListUC(NumberOfMoviesSeenInSearchCategory(imdb_id), this);
                    MoviesFLP.Invoke(new MethodInvoker(delegate
                    {
                        MoviesFLP.Controls.Add(SeenListUserControl);
                    }));

                    WishListUserControl = new WishListUC(Properties.Settings.Default.WishList.Count, this);
                    MoviesFLP.Invoke(new MethodInvoker(delegate
                    {
                        MoviesFLP.Controls.Add(WishListUserControl);
                    }));
                }
            }
        }