Exemplo n.º 1
0
        public bool SearchForMovie(string movieName, int maxResults)
        {
            if (_xmlFile == null)
            {
                Initialize(PluginName, null);
            }
            if (_xmlFile == null)
            {
                return(false);
            }

            if (!File.Exists(_xmlFile))
            {
                return(false);
            }
            DataSet ds = new DataSet();

            ds.ReadXml(_xmlFile);
            movieName = movieName.ToLowerInvariant();
            List <DataRow> dvds = (from dvd in ds.Tables["DVD"].AsEnumerable()
                                   where dvd.Field <String>("Title").ToLowerInvariant().Contains(movieName)
                                   select dvd).ToList <DataRow>();

            List <OMLSDKTitle> dvdList = new List <OMLSDKTitle>();

            foreach (DataRow dr in dvds)
            {
                OMLSDKTitle t = new OMLSDKTitle();
                t.Name = (String)dr["Title"];

                t.ParentalRating  = (String)dr["Rating"];
                t.Synopsis        = (String)dr["Overview"];
                t.CountryOfOrigin = (String)dr["CountryOfOrigin"];
                t.UPC             = (String)dr["UPC"];
                t.OriginalName    = (String)dr["OriginalTitle"];
                t.SortName        = (String)dr["SortTitle"];

                int runTime;
                if (int.TryParse((String)dr["RunningTime"], out runTime))
                {
                    t.Runtime = runTime;
                }
                DateTime dtReleased;
                if (DateTime.TryParse((String)dr["Released"], out dtReleased))
                {
                    t.ReleaseDate = dtReleased;
                }
                int prodYr;
                if (int.TryParse((String)dr["ProductionYear"], out prodYr))
                {
                    t.ProductionYear = prodYr;
                }

                t.FrontCoverPath = Path.Combine(DVDProfilerImageDir, (String)dr["ID"] + @"f.jpg");
                t.BackCoverPath  = Path.Combine(DVDProfilerImageDir, (String)dr["ID"] + @"b.jpg");

                if (ds.Relations.Contains("DVD_Format"))
                {
                    DataRow Format = dr.GetChildRows("DVD_Format")[0];
                    t.VideoStandard   = (String)Format["FormatVideoStandard"];
                    t.VideoResolution = (String)Format["FormatAspectRatio"];
                }

                if (ds.Relations.Contains("DVD_Genres") && ds.Relations.Contains("Genres_Genre"))
                {
                    DataRow genres = dr.GetChildRows("DVD_Genres")[0];
                    foreach (DataRow gen in genres.GetChildRows("Genres_Genre"))
                    {
                        String genre = (String)gen[0];
                        t.Genres.Add(genre);
                    }
                }

                if (ds.Relations.Contains("DVD_Actors") && ds.Relations.Contains("Actors_Actor"))
                {
                    DataRow actors = dr.GetChildRows("DVD_Actors")[0];
                    foreach (DataRow actor in actors.GetChildRows("Actors_Actor"))
                    {
                        String fullName = String.Format(@"{0} {1}", actor["FirstName"], actor["LastName"]);
                        t.AddActingRole(fullName, (String)actor["Role"]);
                    }
                }

                if (ds.Relations.Contains("DVD_Credits") && ds.Relations.Contains("Credits_Credit"))
                {
                    DataRow credits = dr.GetChildRows("DVD_Credits")[0];
                    foreach (DataRow credit in credits.GetChildRows("Credits_Credit"))
                    {
                        String CreditType = (String)credit["CreditType"];
                        String fullName   = String.Format(@"{0} {1}", credit["FirstName"], credit["LastName"]);
                        if (CreditType == "Direction")
                        {
                            t.AddDirector(new OMLSDKPerson(fullName));
                        }
                        else if (CreditType == "Writing")
                        {
                            t.AddWriter(new OMLSDKPerson(fullName));
                        }
                        else if (CreditType == "Production")
                        {
                            t.AddProducer(new OMLSDKPerson(fullName));
                        }
                    }
                }

                List <String> _studios = new List <String>();
                if (ds.Relations.Contains("DVD_Studios") && ds.Relations.Contains("Studios_Studio"))
                {
                    DataRow studios = dr.GetChildRows("DVD_Studios")[0];
                    foreach (DataRow studio in studios.GetChildRows("Studios_Studio"))
                    {
                        _studios.Add((String)studio[0]);
                    }
                }
                t.Studio = String.Join("; ", _studios.ToArray <String>());
                dvdList.Add(t);
            }
            _searchResult = new DVDProfilerSearchResult(dvdList, dvds.Count, dvds.Count);
            bool rslt = (dvds.Count > 0);

            ds.Dispose(); ds = null;
            return(rslt);
        }
        public bool SearchForMovie(string movieName, int maxResults)
        {
            if (_xmlFile == null) Initialize(PluginName, null);
            if (_xmlFile == null) return false;

            if (!File.Exists(_xmlFile)) return false;
            DataSet ds = new DataSet();
            ds.ReadXml(_xmlFile);
            movieName = movieName.ToLowerInvariant();
            List<DataRow> dvds = (from dvd in ds.Tables["DVD"].AsEnumerable()
                                  where dvd.Field<String>("Title").ToLowerInvariant().Contains(movieName)
                                  select dvd).ToList<DataRow>();

            List<OMLSDKTitle> dvdList = new List<OMLSDKTitle>();
            foreach (DataRow dr in dvds)
            {
                OMLSDKTitle t = new OMLSDKTitle();
                t.Name = (String)dr["Title"];

                t.ParentalRating = (String)dr["Rating"];
                t.Synopsis = (String)dr["Overview"];
                t.CountryOfOrigin = (String)dr["CountryOfOrigin"];
                t.UPC = (String)dr["UPC"];
                t.OriginalName = (String)dr["OriginalTitle"];
                t.SortName = (String)dr["SortTitle"];

                int runTime;
                if (int.TryParse((String)dr["RunningTime"], out runTime))
                    t.Runtime = runTime;
                DateTime dtReleased;
                if (DateTime.TryParse((String)dr["Released"], out dtReleased))
                    t.ReleaseDate = dtReleased;
                int prodYr;
                if (int.TryParse((String)dr["ProductionYear"], out prodYr))
                    t.ProductionYear = prodYr;

                t.FrontCoverPath = Path.Combine(DVDProfilerImageDir, (String)dr["ID"] + @"f.jpg");
                t.BackCoverPath = Path.Combine(DVDProfilerImageDir, (String)dr["ID"] + @"b.jpg");

                if (ds.Relations.Contains("DVD_Format"))
                {
                    DataRow Format = dr.GetChildRows("DVD_Format")[0];
                    t.VideoStandard = (String)Format["FormatVideoStandard"];
                    t.VideoResolution = (String)Format["FormatAspectRatio"];
                }

                if (ds.Relations.Contains("DVD_Genres") && ds.Relations.Contains("Genres_Genre"))
                {
                    DataRow genres = dr.GetChildRows("DVD_Genres")[0];
                    foreach (DataRow gen in genres.GetChildRows("Genres_Genre"))
                    {
                        String genre = (String)gen[0];
                        t.Genres.Add(genre);
                    }
                }

                if (ds.Relations.Contains("DVD_Actors") && ds.Relations.Contains("Actors_Actor"))
                {
                    DataRow actors = dr.GetChildRows("DVD_Actors")[0];
                    foreach (DataRow actor in actors.GetChildRows("Actors_Actor"))
                    {
                        String fullName = String.Format(@"{0} {1}", actor["FirstName"], actor["LastName"]);
                        t.AddActingRole(fullName, (String)actor["Role"]);
                    }
                }

                if (ds.Relations.Contains("DVD_Credits") && ds.Relations.Contains("Credits_Credit"))
                {
                    DataRow credits = dr.GetChildRows("DVD_Credits")[0];
                    foreach (DataRow credit in credits.GetChildRows("Credits_Credit"))
                    {
                        String CreditType = (String)credit["CreditType"];
                        String fullName = String.Format(@"{0} {1}", credit["FirstName"], credit["LastName"]);
                        if (CreditType == "Direction")
                        {
                            t.AddDirector(new OMLSDKPerson(fullName));
                        }
                        else if (CreditType == "Writing")
                        {
                            t.AddWriter(new OMLSDKPerson(fullName));
                        }
                        else if (CreditType == "Production")
                        {
                            t.AddProducer(new OMLSDKPerson(fullName));
                        }
                    }
                }

                List<String> _studios = new List<String>();
                if (ds.Relations.Contains("DVD_Studios") && ds.Relations.Contains("Studios_Studio"))
                {
                    DataRow studios = dr.GetChildRows("DVD_Studios")[0];
                    foreach (DataRow studio in studios.GetChildRows("Studios_Studio"))
                    {
                        _studios.Add((String)studio[0]);
                    }
                }
                t.Studio = String.Join("; ", _studios.ToArray<String>());
                dvdList.Add(t);
            }
            _searchResult = new DVDProfilerSearchResult(dvdList, dvds.Count, dvds.Count);
            bool rslt = (dvds.Count > 0);
            ds.Dispose(); ds = null;
            return rslt;
        }