Exemplo n.º 1
0
        /// <summary>
        /// Load favorites movies
        /// </summary>
        public override async Task LoadMoviesAsync()
        {
            IsLoadingMovies = true;
            var favoritesMovies = await MovieHistoryService.GetFavoritesMoviesAsync();

            var movies         = favoritesMovies.ToList();
            var moviesToAdd    = movies.Except(Movies, new MovieShortComparer()).ToList();
            var moviesToRemove = Movies.Except(movies, new MovieShortComparer()).ToList();

            foreach (var movie in moviesToAdd)
            {
                Movies.Add(movie);
            }

            foreach (var movie in moviesToRemove)
            {
                Movies.Remove(movie);
            }

            IsLoadingMovies = false;
            await MovieService.DownloadCoverImageAsync(moviesToAdd);

            IsMovieFound          = Movies.Any();
            CurrentNumberOfMovies = Movies.Count();
            MaxNumberOfMovies     = movies.Count();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Load movies asynchronously
        /// </summary>
        public override async Task LoadMoviesAsync()
        {
            var watch = Stopwatch.StartNew();

            Logger.Info(
                "Loading movies...");

            HasLoadingFailed = false;

            try
            {
                IsLoadingMovies = true;

                var movies =
                    await
                    MovieHistoryService.GetFavoritesMoviesAsync(Genre, Rating).ConfigureAwait(false);

                DispatcherHelper.CheckBeginInvokeOnUI(() =>
                {
                    var moviesList = movies.ToList();
                    Movies.Clear();
                    Movies.AddRange(moviesList);
                    IsLoadingMovies       = false;
                    IsMovieFound          = Movies.Any();
                    CurrentNumberOfMovies = Movies.Count;
                    MaxNumberOfMovies     = Movies.Count;
                });
            }
            catch (Exception exception)
            {
                Logger.Error(
                    $"Error while loading page {Page}: {exception.Message}");
                HasLoadingFailed = true;
                Messenger.Default.Send(new ManageExceptionMessage(exception));
            }
            finally
            {
                watch.Stop();
                var elapsedMs = watch.ElapsedMilliseconds;
                Logger.Info(
                    $"Loaded movies in {elapsedMs} milliseconds.");
            }
        }
        /// <summary>
        /// Load movies
        /// </summary>
        public override async Task LoadMoviesAsync()
        {
            var watch = Stopwatch.StartNew();

            Logger.Info(
                "Loading movies...");

            HasLoadingFailed = false;

            try
            {
                IsLoadingMovies = true;

                var movies =
                    await
                    MovieHistoryService.GetFavoritesMoviesAsync(Genre, Rating);

                Movies = new ObservableCollection <MovieShort>(movies);

                IsLoadingMovies       = false;
                IsMovieFound          = Movies.Any();
                CurrentNumberOfMovies = Movies.Count;
                MaxNumberOfMovies     = Movies.Count;

                await MovieService.DownloadCoverImageAsync(Movies, CancellationLoadingMovies);
            }
            catch (Exception exception)
            {
                Logger.Error(
                    $"Error while loading page {Page}: {exception.Message}");
                HasLoadingFailed = true;
                Messenger.Default.Send(new ManageExceptionMessage(exception));
            }
            finally
            {
                watch.Stop();
                var elapsedMs = watch.ElapsedMilliseconds;
                Logger.Info(
                    $"Loaded movies in {elapsedMs} milliseconds.");
            }
        }