public Movie DeserializeTreeView(string fileName) { var root = new Movie(); Movie parentMovie = null; XmlTextReader reader = null; try { reader = new XmlTextReader(fileName); while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { if (reader.Name == XmlMovieTag) { var newMovie = new Movie(); newMovie.IsVirtual = true; bool isEmptyElement = reader.IsEmptyElement; // loading node attributes int attributeCount = reader.AttributeCount; if (attributeCount > 0) { for (int i = 0; i < attributeCount; i++) { reader.MoveToAttribute(i); SetAttributeValue(newMovie, reader.Name, reader.Value); } } if (parentMovie != null) { newMovie.Parent = parentMovie; parentMovie.Children.Add(newMovie); } else { newMovie.Parent = root; root.Children.Add(newMovie); } // making current node 'ParentNode' if its not empty); if (!isEmptyElement) { parentMovie = newMovie; } } } // moving up to in TreeView if end tag is encountered else if (reader.NodeType == XmlNodeType.EndElement) { if (reader.Name == XmlMovieTag) { parentMovie = parentMovie.Parent; } } else if (reader.NodeType == XmlNodeType.XmlDeclaration) { //Ignore Xml Declaration } else if (reader.NodeType == XmlNodeType.None) { return null; } } } finally { reader.Close(); } return root; }
private static void SaveNodes(Movie dirMovie, XmlTextWriter textWriter) { textWriter.WriteStartElement(XmlMovieTag); textWriter.WriteAttributeString(XmlMovieFilename, dirMovie.FilePath); textWriter.WriteAttributeString(XmlMovieImageIndex, dirMovie.ImageIndex.ToString()); textWriter.WriteAttributeString(XmlMovieImdb, dirMovie.ImdbId); textWriter.WriteAttributeString(XmlMovieIsValid, dirMovie.IsValidMovie.ToString()); textWriter.WriteAttributeString(XmlMovieIsFolder, dirMovie.IsFolder.ToString()); textWriter.WriteAttributeString(XmlMovieRating, dirMovie.Rating.ToString()); textWriter.WriteAttributeString(XmlMovieTitle, dirMovie.Title); textWriter.WriteAttributeString(XmlMovieYear, dirMovie.Year.ToString()); foreach (var node in dirMovie.Children) { // add other node properties to serialize here SaveNodes(node, textWriter); } textWriter.WriteEndElement(); }
private static void SetAttributeValue(Movie node, string propertyName, string value) { if (propertyName == XmlMovieTitle) { node.Title = value; } else if (propertyName == XmlMovieFilename) { node.FilePath = value; } else if (propertyName == XmlMovieImdb) { node.ImdbId = value; } else if (propertyName == XmlMovieRating) { node.Rating = double.Parse(value); } else if (propertyName == XmlMovieYear) { node.Year = int.Parse(value); } else if (propertyName == XmlMovieIsValid) { node.IsValidMovie = bool.Parse(value); } else if (propertyName == XmlMovieIsFolder) { node.IsFolder = bool.Parse(value); } }
public static string ChangeFolderName(Movie original) { var newdir = original.FilePath.Substring(0, original.FilePath.LastIndexOf("\\") + 1); newdir += original.FolderName.CleanFileName(); if (original.FilePath != newdir && Directory.Exists(original.FilePath)) Directory.Move(original.FilePath, newdir); return newdir; }
private static MoviePersonalNote GetNote(MovieDbEntities db, User loggedInUser, Movie rowMovie) { try { var user = db.Users.Where(o => o.Username == loggedInUser.Username).FirstOrDefault(); var movie = db.Movies.Where(o => o.ImdbId == rowMovie.ImdbId).FirstOrDefault(); if (movie == null) { rowMovie.IsUpdated = false; db.AddToMovies(rowMovie); movie = rowMovie; } var personalNote = db.MoviePersonalNotes.Where(o => o.User.Id == loggedInUser.Id && o.Movie.Id == movie.Id). FirstOrDefault(); if (personalNote == null) { personalNote = new MoviePersonalNote { Comment = "", Movie = movie, User = user }; db.AddToMoviePersonalNotes(personalNote); } return personalNote; } catch (Exception exp) { Logger.Exception(exp, 550); return null; } }
private void LoadDbInfo(Movie pmovie) { lblImdbId.Text = pmovie.ImdbId; var movie = _controller.Db.Movies.Where(a => a.ImdbId == pmovie.ImdbId).FirstOrDefault(); if (movie != null) { var note = _controller.Db.MoviePersonalNotes.Where(o => o.User.Id == _loggedInUser.Id && o.Movie.ImdbId == movie.ImdbId).FirstOrDefault(); if (!IsAuthorized || note == null) { txtUserRating.Text = ""; tbDislikeIt.Image = Properties.Resources.hate_it_dis; tbHaveIt.Image = Properties.Resources.have_it_dis; tbLikeIt.Image = Properties.Resources.like_it_dis; tbSeenIt.Image = Properties.Resources.seen_it_dis; tbWantToWatch.Image = Properties.Resources.check_list_dis; tbDislikeIt.Checked = false; tbHaveIt.Checked = false; tbLikeIt.Checked = false; tbSeenIt.Checked = false; tbWantToWatch.Checked = false; } else { _controller_OnDebugTextFired(this, new TextEventArgs("note=" + note.Movie.Title + "\r\n")); txtUserRating.Text = note.Rating + ""; tbDislikeIt.Image = note.Favourite < 0 ? Properties.Resources.hate_it : Properties.Resources.hate_it_dis; tbLikeIt.Image = note.Favourite > 0 ? Properties.Resources.like_it : Properties.Resources.like_it_dis; tbHaveIt.Image = note.Have ? Properties.Resources.have_it : Properties.Resources.have_it_dis; tbSeenIt.Image = note.Seen ? Properties.Resources.seen_it : Properties.Resources.seen_it_dis; tbWantToWatch.Image = note.Wishlist ? Properties.Resources.check_list : Properties.Resources.check_list_dis; tbDislikeIt.Checked = note.Favourite == -1; tbHaveIt.Checked = note.Have; tbLikeIt.Checked = note.Favourite == 1; tbSeenIt.Checked = note.Seen; tbWantToWatch.Checked = note.Wishlist; } } else { } }
private void button2_Click(object sender, EventArgs e) { _update = new List<Movie>(); foreach (ListViewItem item in listView1.Items) { if (item.Checked) { var movie = new Movie(); movie.Title = item.SubItems[1].Text; movie.ImdbId = item.SubItems[2].Text; int year = 0; int.TryParse(item.SubItems[3].Text, out year); movie.Year = year; movie.ImdbId = item.SubItems[2].Text; movie.FilePath = item.SubItems[4].Text; if (!string.IsNullOrEmpty(movie.ImdbId)) _update.Add(movie); } } backgroundWorker2.RunWorkerAsync(); }
public MoviePersonalNote SetFavourite(User loggedInUser, Movie rowMovie, bool val) { var note = GetNote(_entities, loggedInUser, rowMovie); if (val) { if (note.Favourite > 0) note.Favourite = 0; else note.Favourite = 1; } else { if (note.Favourite < 0) note.Favourite = 0; else note.Favourite = -1; } _entities.SaveChanges(); return note; }
public MoviePersonalNote ToggleSeenIt(User loggedInUser, Movie rowMovie, bool? val = null) { var note = GetNote(_entities, loggedInUser, rowMovie); note.Seen = val ?? !note.Seen; _entities.SaveChanges(); return note; }
public Movie ParseMovieInfo(string html) { try { var movie = new Movie(); //var src = Browser.DocumentText; var rating = ImdbParser.ParseRating(html); var title = ImdbParser.ParseTitle(html); var year = ImdbParser.ParseYear(html); var imdbId = ImdbParser.ParseId(html); InvokeOnDebugTextFired("Title: " + title + "\r\n"); InvokeOnDebugTextFired("Year: " + year + "\r\n"); InvokeOnDebugTextFired("Rating: " + rating + "\r\n"); movie.Rating = Convert.ToDouble(rating); movie.Title = HttpHelper.HtmlDecode(HttpHelper.UrlDecode(ImdbParser.ParseTitle(html))); movie.Year = Convert.ToInt32(year); movie.ImdbId = imdbId; movie.FilePath = ""; movie.Runtime = ImdbParser.ParseRuntime(html); movie.MPAA = ImdbParser.ParseMpaa(html); movie.MPAAReason = ImdbParser.ParseMpaaReason(html); movie.Highlight = ImdbParser.ParseHighlight(html); movie.Genres = ImdbParser.ParseGenres(html); movie.Countries = ImdbParser.ParseCountries(html); movie.Languages = ImdbParser.ParseLanguages(html); movie.PersonStars = ImdbParser.ParseStars(html); movie.PersonWriters = ImdbParser.ParseWriters(html); movie.PersonDirectors = ImdbParser.ParseDirectors(html); movie.IsValidMovie = true; return movie; } catch (Exception exception) { Logger.Exception(exception, 418); return null; } }
public void SearchMovie(string address, Movie movie) { try { RecentSearch = true; if (address.Equals(ImdbSearch) && movie != null && !string.IsNullOrEmpty(movie.ImdbId)) { Navigate(ImdbTitle + movie.ImdbId); } else { if (movie != null) Navigate(address + IgnoreWords(movie.Title)); } } catch (Exception exception) { Logger.Exception(exception, 116); } }
public void InvokeOnMovieInformationCollected(Movie movie, string message) { var handler = OnMovieInformationCollected; if (handler != null) handler(this, new MovieEventArgs(movie, message)); }
public Movie CollectAndAddMovieToDb(Movie movie2, string moviePage = null, bool collectKeyword = true) { if (string.IsNullOrEmpty(moviePage)) { InvokeOnNotificationFired("Started collecting movie: " + movie2.Title); moviePage = HttpHelper.FetchWebPage(ImdbTitle + movie2.ImdbId); } var parseMovieInfo = ParseMovieInfo(moviePage); if (parseMovieInfo == null) return null; var movie = _entities.Movies.Where(o => o.ImdbId == parseMovieInfo.ImdbId).FirstOrDefault(); if (movie == null) { movie = parseMovieInfo; movie.IsUpdated = false; _entities.AddToMovies(movie); _entities.SaveChanges(); } else { movie.CopyFromMovie(parseMovieInfo); _entities.SaveChanges(); } foreach (var g in parseMovieInfo.Genres) { var genre = GetGenre(g); var movieGenre = _entities.MovieGenres.Where(o => o.Movie.Id == movie.Id && o.Genre.Id == genre.Id).FirstOrDefault(); if (movieGenre != null) continue; movieGenre = new MovieGenre { Movie = movie, Genre = genre }; _entities.AddToMovieGenres(movieGenre); _entities.SaveChanges(); } foreach (var g in parseMovieInfo.Languages) { var language = GetLanguage(g); var movieLanguage = _entities.MovieLanguages.Where(o => o.Movie.Id == movie.Id && o.Language.Id == language.Id).FirstOrDefault(); if (movieLanguage != null) continue; movieLanguage = new MovieLanguage { Movie = movie, Language = language }; _entities.AddToMovieLanguages(movieLanguage); _entities.SaveChanges(); } foreach (var g in parseMovieInfo.Countries) { var country = GetCountry(g); var movieCountry = _entities.MovieCountries.Where(o => o.Movie.Id == movie.Id && o.Country.Id == country.Id).FirstOrDefault(); if (movieCountry != null) continue; movieCountry = new MovieCountry { Movie = movie, Country = country }; _entities.AddToMovieCountries(movieCountry); _entities.SaveChanges(); } foreach (var g in parseMovieInfo.PersonDirectors) { var person = GetPerson(g); var director = _entities.Directors.Where(o => o.Movie.Id == movie.Id && o.Person.Id == person.Id).FirstOrDefault(); if (director != null) continue; director = new Director { Movie = movie, Person = person }; _entities.AddToDirectors(director); _entities.SaveChanges(); } foreach (var g in parseMovieInfo.PersonStars) { var person = GetPerson(g); var star = _entities.Stars.Where(o => o.Movie.Id == movie.Id && o.Person.Id == person.Id).FirstOrDefault(); if (star != null) continue; star = new Star { Movie = movie, Person = person }; _entities.AddToStars(star); _entities.SaveChanges(); } foreach (var g in parseMovieInfo.PersonWriters) { var person = GetPerson(g); var writer = _entities.Writers.Where(o => o.Movie.Id == movie.Id && o.Person.Id == person.Id).FirstOrDefault(); if (writer != null) continue; writer = new Writer { Movie = movie, Person = person }; _entities.AddToWriters(writer); _entities.SaveChanges(); } if (collectKeyword) { var keywordPage = HttpHelper.FetchWebPage(string.Format(ImdbKeywordUrl, parseMovieInfo.ImdbId)); parseMovieInfo.Keywords = ImdbParser.ParseKeywords(keywordPage); foreach (var g in parseMovieInfo.Keywords) { var keyword = GetKeyword(g); var movieKeyword = _entities.MovieKeywords.Where(o => o.Movie.Id == movie.Id && o.Keyword.Id == keyword.Id). FirstOrDefault(); if (movieKeyword != null) continue; movieKeyword = new MovieKeyword { Movie = movie, Keyword = keyword }; _entities.AddToMovieKeywords(movieKeyword); _entities.SaveChanges(); } } InvokeOnNotificationFired("Fiished collecting movie: " + movie.Title); movie.IsUpdated = true; _entities.SaveChanges(); return movie; }
public void AddToUserList(Movie movie, string selectedText) { var list = _entities.UserLists.Where(o => o.ListName == selectedText).FirstOrDefault(); if (list == null) return; var a = new MovieUserList { UserList = list, Movie = movie }; _entities.AddToMovieUserLists(a); _entities.SaveChanges(); }
private static void CollectAndUpdate(OLVListItem selectedItem, string html = null, Movie movie = null, bool fetchKeywords = true) { var information = new CollectInformation { MovieController = new MovieBrowserController(), MovieNode = selectedItem, Html = html, ParsedMovie = movie, FetchKeyword = fetchKeywords }; var thread = new Thread(information.Collect); thread.Start(); }
public MoviePersonalNote ToggleWanted(User loggedInUser, Movie rowMovie, bool? value = null) { var note = GetNote(_entities, loggedInUser, rowMovie); if (value != null) note.Wishlist = value.Value; else note.Wishlist = !note.Wishlist; _entities.SaveChanges(); return note; }
public void Collect() { try { if (MovieNode != null) { ParsedMovie = (Movie)MovieNode.RowObject; } var movie = MovieController.CollectAndAddMovieToDb(ParsedMovie, Html, FetchKeyword); if (MovieNode != null && movie != null) { MovieController.UpdateMovieNode(MovieNode, movie); } } catch (Exception exception) { MessageBox.Show(@"Problem Collecting Information.", exception.Message); } }
public void UpdateMovieNode(OLVListItem nodeMovie, Movie movie) { try { var rowMovie = ((Movie)nodeMovie.RowObject); //var movie = CollectAndAddMovieToDb(rowMovie, Browser.DocumentText, false); if (movie == null) return; if (!movie.IsVirtual) { movie.FilePath = rowMovie.FilePath; movie.FilePath = ChangeFolderName(movie); } rowMovie.CopyFromMovie(movie); InvokeOnNotificationFired("Movie: " + rowMovie.Title + " is updated."); } catch (Exception exception) { Logger.Exception(exception, 2); } }
void LoadImdbInfo(Movie rowMovie) { _movie = rowMovie; lblImdbId.Text = rowMovie.ImdbId; var movie = _controller.Db.Movies.Where(a => a.ImdbId == rowMovie.ImdbId).FirstOrDefault(); if (movie == null) { listCountries.Items.Clear(); listKeywords.Items.Clear(); listGenres.Items.Clear(); listLanguages.Items.Clear(); // listActors.Items.Clear(); listStars.Items.Clear(); listDirectors.Items.Clear(); listWriters.Items.Clear(); if (rowMovie.IsValidMovie) { lblTitle.Text = rowMovie.Title; lblRating.Text = rowMovie.Rating + ""; lblYear.Text = rowMovie.Year + ""; } else { lblTitle.Text = ""; lblRating.Text = ""; lblYear.Text = ""; } lblRuntime.Text = ""; lblMPAA.Text = ""; textMpaaReason.Text = ""; textHighlight.Text = ""; tbUpdated.Checked = false; } else { lblTitle.Text = movie.Title; lblRating.Text = movie.Rating + ""; lblYear.Text = movie.Year + ""; lblRuntime.Text = movie.Runtime; lblMPAA.Text = movie.MPAA; textMpaaReason.Text = movie.MPAAReason; textHighlight.Text = movie.Highlight; tbUpdated.Checked = movie.IsUpdated; var listC = _controller.Db.MovieCountries.Where(a => a.Movie.Id == movie.Id).Select(o => o.Country).ToList(); listCountries.Items.Clear(); foreach (var country in listC) { var item = new ListViewItem(country.Name); item.SubItems.Add(country.Code); listCountries.Items.Add(item); } listKeywords.DataSource = _controller.Db.MovieKeywords.Where(a => a.Movie.Id == movie.Id).Select(o => o.Keyword); var listG = _controller.Db.MovieGenres.Where(a => a.Movie.Id == movie.Id).Select(o => o.Genre).ToList(); listGenres.Items.Clear(); foreach (var country in listG) { var item = new ListViewItem(country.Name); item.SubItems.Add(country.Code); listGenres.Items.Add(item); } listLanguages.DataSource = _controller.Db.MovieLanguages.Where(a => a.Movie.Id == movie.Id).Select(o => o.Language); listDirectors.DataSource = _controller.Db.Directors.Where(a => a.Movie.Id == movie.Id).Select(o => o.Person); listWriters.DataSource = _controller.Db.Writers.Where(a => a.Movie.Id == movie.Id).Select(o => o.Person); listActors.DataSource = _controller.Db.Actors.Where(a => a.Movie.Id == movie.Id).Select(o => o.Person); listStars.DataSource = _controller.Db.Stars.Where(a => a.Movie.Id == movie.Id).Select(o => o.Person); } if (IsAuthorized) { var personalNote = _controller.Db.MoviePersonalNotes.Where(o => o.User.Id == _loggedInUser.Id && o.Movie.ImdbId == rowMovie.ImdbId).FirstOrDefault(); comboUserList.SelectedIndex = -1; var mul = _controller.Db.MovieUserLists.Where(o => o.UserList.User.Id == _loggedInUser.Id && o.Movie.ImdbId == rowMovie.ImdbId).FirstOrDefault(); if (mul != null) { for (int i = 0; i < comboUserList.Items.Count; i++) { var item = comboUserList.Items[i]; if (item.ToString() == mul.UserList.ListName) comboUserList.SelectedIndex = i; } } LoadPersonalNote(personalNote); } else { LoadPersonalNote(null); } }
public MoviePersonalNote UpdateUserRating(User loggedInUser, Movie rowMovie, double rating) { var note = GetNote(_entities, loggedInUser, rowMovie); note.Rating = rating; _entities.SaveChanges(); return note; }
public MovieEventArgs(Movie movie, string message) { this.Movie = movie; this.Message = message; }
public Movie CopyFromMovie(Movie movie) { this.ImdbId = movie.ImdbId; this.Rating = movie.Rating; this.Title = movie.Title; this.Year = movie.Year; this.ImdbId = movie.ImdbId; this.FilePath = movie.FilePath; this.Runtime = movie.Runtime; this.MPAA = movie.MPAA; this.MPAAReason = movie.MPAAReason; this.Highlight = movie.Highlight; // this.Genres = movie.Genres; this.Countries = movie.Countries; this.Languages = movie.Languages; this.Keywords = movie.Keywords; // this.IsValidMovie = movie.IsValidMovie; // this.Children = movie.Children; this.Parent = movie.Parent; // return this; }