protected virtual void OnGetMovieInfoCompleted(MovieInfoCompletedEventArgs e) { if (GetMovieInfoCompleted != null) { GetMovieInfoCompleted(this, e); } }
private void GetMovieInfoWorker(int id, object userState, AsyncOperation asyncOp) { Exception exception = null; Movie movie = null; try { movie = GetMovieInfo(id); } catch (Exception ex) { exception = ex; } MovieInfoCompletedEventArgs args = new MovieInfoCompletedEventArgs(movie, exception, false, userState); asyncOp.PostOperationCompleted(delegate(object e) { OnGetMovieInfoCompleted((MovieInfoCompletedEventArgs)e); }, args); }
void Tmdb_GetMovieInfoCompleted(object sender, TMDB.MovieInfoCompletedEventArgs e) { threadCount -= 1; MovieTag tag; if (scanning) { if (searchPos < listViewResults.Items.Count) { while (listViewResults.Items[searchPos].ForeColor == Color.Purple || (listViewResults.Items[searchPos].ForeColor == Color.Red && listViewResults.Items[searchPos].SubItems[3].Text == "Unable to find match")) { searchPos += 1; progressBarResults.Value += 1; completedMatches += 1; } listViewResults.Items[searchPos].SubItems[3].Text = "Scanning..."; tag = (MovieTag)listViewResults.Items[searchPos].Tag; threadCount += 1; EnsureVisibleScroll(searchPos); Program.Tmdb.MovieSearchAsync(tag.Search, searchPos); searchPos += 1; } } if (e.Error == null) { if (e.Movie != null) { completedMatches += 1; MovieTag filetag = (MovieTag)listViewResults.Items[(int)e.UserState].Tag; Movie add = new Movie(); add = filetag.MovieInfo; add.Id = e.Movie.Id; add.Title = e.Movie.Name; add.AlternativeTitle = e.Movie.AlternativeName; add.ImdbId = e.Movie.ImdbId; add.Language = e.Movie.Language; add.Overview = e.Movie.Overview; add.Released = e.Movie.Released; add.Trailer = e.Movie.Trailer; add.Votes = e.Movie.Votes; add.Rating = e.Movie.Rating; add.Budget = e.Movie.Budget; add.Certification = e.Movie.Certification; add.Homepage = e.Movie.Homepage; add.Revenue = e.Movie.Revenue; foreach (TMDB.Image img in e.Movie.Images) { if (img.Size == TMDB.ImageSize.original) { add.Cover = img; break; } } addMovies.Add(add); listViewResults.Items[(int)e.UserState].ForeColor = Color.Green; listViewResults.Items[(int)e.UserState].SubItems[3].Text = "Complete"; } else { listViewResults.Items[(int)e.UserState].ForeColor = Color.Red; listViewResults.Items[(int)e.UserState].SubItems[3].Text = "Unable to find match"; } } else { listViewResults.Items[(int)e.UserState].ForeColor = Color.Red; listViewResults.Items[(int)e.UserState].SubItems[3].Text = "Remote server error"; } progressBarResults.Value += 1; int current = progressBarResults.Value; int max = progressBarResults.Maximum; double percent = ((double)current / (double)max) * 100; if (progressBarResults.Value == progressBarResults.Maximum) { scanning = false; percent = 100; threadCount = 0; } labelProgress.Text = percent.ToString("0.0") + "% (" + completedMatches + " / " + listViewResults.Items.Count + ")"; if (!scanning && threadCount == 0 && percent != 100) { labelProgress.Text = "Aborted (" + completedMatches + " / " + listViewResults.Items.Count + ")"; Program.Tmdb.GetMovieInfoCompleted -= new TMDB.Api.MovieInfoAsyncCompletedEventHandler(Tmdb_GetMovieInfoCompleted); } else if ((scanning && threadCount == 0) || percent == 100) { buttonResultsAbort.Enabled = true; Program.Tmdb.GetMovieInfoCompleted -= new TMDB.Api.MovieInfoAsyncCompletedEventHandler(Tmdb_GetMovieInfoCompleted); } if (threadCount == 0) { buttonResultsBack.Enabled = true; buttonResultsAutoId.Enabled = true; buttonResultsAbort.Text = "Close"; foreach (ListViewItem lvi in listViewResults.Items) { if (lvi.ForeColor == Color.Green) { buttonResultsAdd.Enabled = true; break; } } } }