public static void DeSerialisoiIdSeach(string imdbID, ref Movie movie) { string url = "http://www.omdbapi.com/?i=" + imdbID + "&r=xml&plot=full"; try { HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url); myRequest.AllowAutoRedirect = true; myRequest.Method = "GET"; myRequest.Timeout = 6000; WebResponse myResponse = myRequest.GetResponse(); XmlTextReader reader = new XmlTextReader(myResponse.GetResponseStream()); Search.dezirialiseXML(ref reader, ref movie); reader.Close(); myResponse.Close(); } catch (Exception ex) { throw ex; } finally { } }
public static void dezirialiseXML(ref XmlTextReader reader,ref Movie movie) { XmlDocument doc = new XmlDocument(); doc.Load(reader); XmlNode node = doc.SelectSingleNode("//movie"); foreach (XmlAttribute att in node.Attributes) { string prop =Search.UppercaseFirst(att.Name); movie.Update(prop, att.Value); } }
public static Movie getMovieInfoFromDb(string Nimi) { Movie movie=new Movie(); string url = "http://www.omdbapi.com/?t=" + Nimi + "&r=xml&plot=full"; try { HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url); myRequest.AllowAutoRedirect = true; myRequest.Method = "GET"; myRequest.Timeout = 6000; WebResponse myResponse = myRequest.GetResponse(); XmlTextReader reader = new XmlTextReader(myResponse.GetResponseStream()); Search.dezirialiseXML(ref reader,ref movie); reader.Close(); myResponse.Close(); if (movie.Title == null) { Exception e = new Exception("Elokuvan tietoja ei löytynyt"); throw e; } } catch (Exception ex) { movie.Actors = "Tietoja ei löytynyt"; movie.Director = "Tietoja ei löytynyt"; movie.Genre = "Tietoja ei löytynyt"; movie.Title = "Tietoja ei löytynyt"; movie.Plot = "Tietoja ei löytynyt"; movie.ImdbID = "Tietoja ei löytynyt"; movie.ImdbRating = "Tietoja ei löytynyt"; movie.Rated = "Tietoja ei löytynyt"; } return movie; }
public Elokuva(string nimi, string ohjaaja, string genre, int tahdet) { Movie movie = new Movie(); Nimi = nimi; movie.Director = ohjaaja; movie.Genre = genre; Tahdet = tahdet; movie = Search.getMovieInfoFromDb(Nimi); // movie.Elokuva = this; DbTiedot = movie; }