コード例 #1
0
        /// <summary>
        /// Search shows asynchronously
        /// </summary>
        public override async Task LoadShowsAsync(bool reset = false)
        {
            await LoadingSemaphore.WaitAsync(CancellationLoadingShows.Token);

            StopLoadingShows();
            if (reset)
            {
                Shows.Clear();
                Page           = 0;
                VerticalScroll = 0d;
            }

            var watch = Stopwatch.StartNew();

            Page++;
            if (Page > 1 && Shows.Count == MaxNumberOfShows)
            {
                Page--;
                LoadingSemaphore.Release();
                return;
            }

            Logger.Info(
                $"Loading search page {Page} with criteria: {SearchFilter}");
            HasLoadingFailed = false;
            try
            {
                IsLoadingShows = true;
                var result =
                    await ShowService.SearchShowsAsync(SearchFilter,
                                                       Page,
                                                       MaxNumberOfShows,
                                                       Genre,
                                                       Rating * 10,
                                                       CancellationLoadingShows.Token);

                Shows.AddRange(result.shows.Except(Shows, new ShowLightComparer()));
                IsLoadingShows       = false;
                IsShowFound          = Shows.Any();
                CurrentNumberOfShows = Shows.Count;
                MaxNumberOfShows     = result.nbShows;
                UserService.SyncShowHistory(Shows);
            }
            catch (Exception exception)
            {
                Page--;
                Logger.Error(
                    $"Error while loading search page {Page} with criteria {SearchFilter}: {exception.Message}");
                HasLoadingFailed = true;
                Messenger.Default.Send(new ManageExceptionMessage(exception));
            }
            finally
            {
                watch.Stop();
                var elapsedMs = watch.ElapsedMilliseconds;
                Logger.Info(
                    $"Loaded search page {Page} with criteria {SearchFilter} in {elapsedMs} milliseconds.");
                LoadingSemaphore.Release();
            }
        }
コード例 #2
0
 internal bool IsPostable()
 {
     return((Movies != null && Movies.Any()) ||
            (Shows != null && Shows.Any()) ||
            (Seasons != null && Seasons.Any()) ||
            (Episodes != null && Episodes.Any()) ||
            (People != null && People.Any()));
 }
コード例 #3
0
        public static Boolean AddFavoriteShow(Area show)
        {
            if (Shows.Any(s => s.ID == show.ID))
            {
                return(false);
            }

            Shows.Add(show);
            Helpers.Settings.FavoriteShows = JsonConvert.SerializeObject(Shows);
            FavoritesDirty = true;
            return(true);
        }
コード例 #4
0
        /// <summary>
        /// Load movies asynchronously
        /// </summary>
        public override async Task LoadShowsAsync()
        {
            var watch = Stopwatch.StartNew();

            Logger.Info(
                $"Loading shows favorite page {Page}...");
            HasLoadingFailed = false;
            try
            {
                IsLoadingShows = true;
                var imdbIds =
                    await UserService.GetFavoritesShows().ConfigureAwait(false);

                var shows = new List <ShowJson>();
                await imdbIds.ParallelForEachAsync(async imdbId =>
                {
                    var show = await ShowService.GetShowAsync(imdbId);
                    if (show != null)
                    {
                        show.IsFavorite = true;
                        shows.Add(show);
                    }
                });

                DispatcherHelper.CheckBeginInvokeOnUI(async() =>
                {
                    Shows.Clear();
                    Shows.AddRange(shows.Where(a => Genre != null
                        ? a.Genres.Contains(Genre.EnglishName)
                        : a.Genres.TrueForAll(b => true) && a.Rating.Percentage >= Rating * 10));
                    IsLoadingShows       = false;
                    IsShowFound          = Shows.Any();
                    CurrentNumberOfShows = Shows.Count;
                    MaxNumberOfShows     = Shows.Count;
                    await UserService.SyncShowHistoryAsync(Shows).ConfigureAwait(false);
                });
            }
            catch (Exception exception)
            {
                Logger.Error(
                    $"Error while loading shows favorite page {Page}: {exception.Message}");
                HasLoadingFailed = true;
                Messenger.Default.Send(new ManageExceptionMessage(exception));
            }
            finally
            {
                watch.Stop();
                var elapsedMs = watch.ElapsedMilliseconds;
                Logger.Info(
                    $"Loaded shows favorite page {Page} in {elapsedMs} milliseconds.");
            }
        }
コード例 #5
0
        /// <summary>
        /// Load shows asynchronously
        /// </summary>
        public override async Task LoadShowsAsync()
        {
            var watch = Stopwatch.StartNew();

            Page++;

            if (Page > 1 && Shows.Count == MaxNumberOfShows)
            {
                return;
            }

            Logger.Info(
                $"Loading page {Page}...");

            HasLoadingFailed = false;

            try
            {
                IsLoadingShows = true;

                var shows =
                    await ShowService.GetPopularShowsAsync(Page,
                                                           MaxShowsPerPage,
                                                           Rating,
                                                           CancellationLoadingShows.Token,
                                                           Genre).ConfigureAwait(false);

                DispatcherHelper.CheckBeginInvokeOnUI(() =>
                {
                    Shows.AddRange(shows.Item1);
                    IsLoadingShows       = false;
                    IsShowFound          = Shows.Any();
                    CurrentNumberOfShows = Shows.Count;
                    MaxNumberOfShows     = shows.Item2;
                });
            }
            catch (Exception exception)
            {
                Page--;
                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 page {Page} in {elapsedMs} milliseconds.");
            }
        }
コード例 #6
0
        private void LoadTrendingShows(int page)
        {
            IsLoading = true;

            _tvshowtimeApiService.GetTrendingShows(page, _pageSize)
            .Subscribe(async(exploreResponse) =>
            {
                await DispatcherHelper.ExecuteOnUIThreadAsync(() =>
                {
                    foreach (var show in exploreResponse.Shows)
                    {
                        // Do not add the same show twice
                        if (Shows.Any(s => s.Id == show.Id))
                        {
                            continue;
                        }

                        var exploreShowViewModel = new ExploreShowViewModel
                        {
                            Id        = show.Id,
                            Name      = show.Name,
                            Overview  = show.Overview,
                            AllImages = show.AllImages,
                            Followed  = show.Followed,
                            Original  = show
                        };
                        Shows.Add(exploreShowViewModel);
                    }

                    IsLoading = false;
                });
            },
                       async(error) =>
            {
                await DispatcherHelper.ExecuteOnUIThreadAsync(() =>
                {
                    IsLoading = false;
                });

                _toastNotificationService.ShowErrorNotification("An error happened. Please retry later.");
            });
        }
コード例 #7
0
        private void LoadTrendingShows(int page)
        {
            _isLoadingShows = true;

            _tvshowtimeApiService.GetTrendingShows(page, _pageSize)
            .Subscribe(async(exploreResponse) =>
            {
                await DispatcherHelper.ExecuteOnUIThreadAsync(() =>
                {
                    foreach (var show in exploreResponse.Shows)
                    {
                        // Do not add the same show twice
                        if (Shows.Any(s => s.Id == show.Id))
                        {
                            continue;
                        }

                        var exploreShowViewModel = new ExploreShowViewModel
                        {
                            Id        = show.Id,
                            Name      = show.Name,
                            Overview  = show.Overview,
                            AllImages = show.AllImages,
                            Followed  = show.Followed,
                            Original  = show
                        };
                        Shows.Add(exploreShowViewModel);
                    }

                    _isLoadingShows = false;
                });
            },
                       (error) =>
            {
                throw new Exception();
            });
        }
コード例 #8
0
        /// <summary>
        /// Load movies asynchronously
        /// </summary>
        public override async Task LoadShowsAsync(bool reset = false)
        {
            await LoadingSemaphore.WaitAsync();

            StopLoadingShows();
            if (reset)
            {
                Shows.Clear();
                Page = 0;
            }

            var watch = Stopwatch.StartNew();

            Page++;
            if (Page > 1 && Shows.Count == MaxNumberOfShows)
            {
                Page--;
                LoadingSemaphore.Release();
                return;
            }

            Logger.Info(
                $"Loading shows favorite page {Page}...");
            HasLoadingFailed = false;
            try
            {
                IsLoadingShows = true;
                var imdbIds =
                    await UserService.GetFavoritesShows(Page);

                if (!NeedSync)
                {
                    var shows = new List <ShowLightJson>();
                    await imdbIds.shows.ParallelForEachAsync(async imdbId =>
                    {
                        try
                        {
                            var show = await ShowService.GetShowLightAsync(imdbId);
                            if (show != null)
                            {
                                show.IsFavorite = true;
                                shows.Add(show);
                            }
                        }
                        catch (Exception ex)
                        {
                            Logger.Error(ex);
                        }
                    });

                    var updatedShows = shows.OrderBy(a => a.Title)
                                       .Where(a => (Genre == null || a.Genres.Contains(Genre.EnglishName)) &&
                                              a.Rating.Percentage >= Rating * 10);
                    foreach (var show in updatedShows.Except(Shows.ToList(), new ShowLightComparer()))
                    {
                        var pair = Shows
                                   .Select((value, index) => new { value, index })
                                   .FirstOrDefault(x => string.CompareOrdinal(x.value.Title, show.Title) > 0);


                        if (pair == null)
                        {
                            Shows.Add(show);
                        }
                        else
                        {
                            Shows.Insert(pair.index, show);
                        }
                    }
                }
                else
                {
                    var showsToDelete = Shows.Select(a => a.ImdbId).Except(imdbIds.allShows);
                    var showsToAdd    = imdbIds.allShows.Except(Shows.Select(a => a.ImdbId));
                    foreach (var movie in showsToDelete.ToList())
                    {
                        Shows.Remove(Shows.FirstOrDefault(a => a.ImdbId == movie));
                    }

                    var shows = showsToAdd.ToList();
                    var showsToAddAndToOrder = new List <ShowLightJson>();
                    await shows.ParallelForEachAsync(async imdbId =>
                    {
                        try
                        {
                            var show = await ShowService.GetShowLightAsync(imdbId);
                            if ((Genre == null || show.Genres.Contains(Genre.EnglishName)) && show.Rating.Percentage >= Rating * 10)
                            {
                                showsToAddAndToOrder.Add(show);
                            }
                        }
                        catch (Exception ex)
                        {
                            Logger.Error(ex);
                        }
                    });

                    foreach (var show in showsToAddAndToOrder.Except(Shows.ToList(), new ShowLightComparer()))
                    {
                        var pair = Shows
                                   .Select((value, index) => new { value, index })
                                   .FirstOrDefault(x => string.CompareOrdinal(x.value.Title, show.Title) > 0);
                        if (pair == null)
                        {
                            Shows.Add(show);
                        }
                        else
                        {
                            Shows.Insert(pair.index, show);
                        }
                    }
                }
                IsLoadingShows       = false;
                IsShowFound          = Shows.Any();
                CurrentNumberOfShows = Shows.Count;
                MaxNumberOfShows     = imdbIds.nbShows;
                await UserService.SyncShowHistoryAsync(Shows).ConfigureAwait(false);
            }
            catch (Exception exception)
            {
                Page--;
                Logger.Error(
                    $"Error while loading shows favorite page {Page}: {exception.Message}");
                HasLoadingFailed = true;
                Messenger.Default.Send(new ManageExceptionMessage(exception));
            }
            finally
            {
                NeedSync = false;
                watch.Stop();
                var elapsedMs = watch.ElapsedMilliseconds;
                Logger.Info(
                    $"Loaded shows favorite page {Page} in {elapsedMs} milliseconds.");
                LoadingSemaphore.Release();
            }
        }
コード例 #9
0
        private Show FindShow()
        {
            if (shows.Any())
            {
                Console.WriteLine("Tryb wyszukiwania seansu: ");
                Console.WriteLine("1 - Po ID");
                Console.WriteLine("2 - Po tytule filmu");
                Console.WriteLine("3 - Po dacie");
                var key = Console.ReadKey();
                Console.WriteLine(Environment.NewLine);
                switch (key.KeyChar)
                {
                default:
                {
                    Console.WriteLine("Niepoprawna liczba. Zwracam null.");
                    break;
                }

                case '1':
                {
                    Console.WriteLine("Podaj ID: ");
                    var input = Console.ReadLine();
                    if (input.All(Char.IsNumber) && input != "")
                    {
                        var show = shows.Search(Convert.ToInt32(input));
                        if (show != null)
                        {
                            return(show);
                        }
                    }
                    else
                    {
                        Console.WriteLine("ID musi być liczbą(większą od 0)!");
                        return(null);
                    }

                    break;
                }

                case '2':
                {
                    uint showID;

                    Console.WriteLine("Podaj tytuł filmu: ");
                    var input      = Console.ReadLine();
                    var foundShows = shows.Search(input);

                    if (foundShows.Count > 0)
                    {
                        for (int i = 0; i < foundShows.Count; i++)
                        {
                            Console.WriteLine("L.p.: " + (i + 1) + " - ID: " + foundShows[i].ID + "; data: " + foundShows[i].Date);
                        }

                        Console.WriteLine("Wybierz seans(podaj L.p.): ");
                        try
                        {
                            showID = Convert.ToUInt32(Console.ReadLine()) /*(int) char.GetNumericValue(Console.ReadKey().KeyChar)*/;
                        }
                        catch
                        {
                            Console.WriteLine("Błędne ID.");
                            return(null);
                        }
                        Console.WriteLine(Environment.NewLine);

                        if (showID <= foundShows.Count && showID > 0)
                        {
                            return(foundShows[(int)showID - 1]);
                        }
                    }
                    break;
                }

                case '3':
                {
                    Console.WriteLine("Podaj datę [yyyy-MM-dd HH:mm]: ");
                    var input = Console.ReadLine();
                    try
                    {
                        var show = shows.Search(Convert.ToDateTime(input));
                        if (show != null)
                        {
                            return(show);
                        }
                    }
                    catch
                    {
                        Console.WriteLine("Błędny format daty");
                        return(null);
                    }

                    break;
                }
                }
                Console.WriteLine("Nie znaleziono takiego seansu.");
                return(null);
            }
            Console.WriteLine("Baza seansów jest pusta!");
            return(null);
        }
コード例 #10
0
 internal bool IsPostable()
 {
     return((Movies != null && Movies.Any()) || (Shows != null && Shows.Any()) || (Episodes != null && Episodes.Any()));
 }
コード例 #11
0
        /// <summary>
        /// Load movies asynchronously
        /// </summary>
        public override async Task LoadShowsAsync(bool reset = false)
        {
            await LoadingSemaphore.WaitAsync();

            StopLoadingShows();
            if (reset)
            {
                Shows.Clear();
                Page = 0;
            }

            var watch = Stopwatch.StartNew();

            Page++;
            if (Page > 1 && Shows.Count == MaxNumberOfShows)
            {
                Page--;
                LoadingSemaphore.Release();
                return;
            }

            Logger.Info(
                $"Loading shows favorite page {Page}...");
            HasLoadingFailed = false;
            try
            {
                IsLoadingShows = true;
                var imdbIds =
                    await UserService.GetFavoritesShows(Page);

                if (!_needSync)
                {
                    var shows = new List <ShowJson>();
                    await imdbIds.shows.ParallelForEachAsync(async imdbId =>
                    {
                        var show = await ShowService.GetShowAsync(imdbId);
                        if (show != null)
                        {
                            show.IsFavorite = true;
                            shows.Add(show);
                        }
                    });

                    var updatedShows = shows.OrderBy(a => a.Title)
                                       .Where(a => (Genre != null
                                        ? a.Genres.Any(
                                                        genre => genre.ToLowerInvariant() ==
                                                        Genre.EnglishName.ToLowerInvariant())
                                        : a.Genres.TrueForAll(b => true)) && a.Rating.Percentage >= Rating * 10);
                    Shows.AddRange(updatedShows.Except(Shows.ToList(), new ShowComparer()));
                }
                else
                {
                    var showsToDelete = Shows.Select(a => a.ImdbId).Except(imdbIds.allShows);
                    var showsToAdd    = imdbIds.allShows.Except(Shows.Select(a => a.ImdbId));
                    foreach (var movie in showsToDelete.ToList())
                    {
                        Shows.Remove(Shows.FirstOrDefault(a => a.ImdbId == movie));
                    }

                    var shows = showsToAdd.ToList();
                    await shows.ParallelForEachAsync(async imdbId =>
                    {
                        var show = await ShowService.GetShowAsync(imdbId);
                        if ((Genre != null
                                    ? show.Genres.Any(
                                 genre => genre.ToLowerInvariant() ==
                                 Genre.EnglishName.ToLowerInvariant())
                                    : show.Genres.TrueForAll(b => true)) && show.Rating.Percentage >= Rating * 10)
                        {
                            DispatcherHelper.CheckBeginInvokeOnUI(() =>
                            {
                                Shows.Add(show);
                            });
                        }
                    });
                }

                IsLoadingShows       = false;
                IsShowFound          = Shows.Any();
                CurrentNumberOfShows = Shows.Count;
                MaxNumberOfShows     = imdbIds.nbShows;
                await UserService.SyncShowHistoryAsync(Shows);
            }
            catch (Exception exception)
            {
                Page--;
                Logger.Error(
                    $"Error while loading shows favorite page {Page}: {exception.Message}");
                HasLoadingFailed = true;
                Messenger.Default.Send(new ManageExceptionMessage(exception));
            }
            finally
            {
                Shows.Sort((a, b) => String.Compare(a.Title, b.Title, StringComparison.Ordinal));
                _needSync = false;
                watch.Stop();
                var elapsedMs = watch.ElapsedMilliseconds;
                Logger.Info(
                    $"Loaded shows favorite page {Page} in {elapsedMs} milliseconds.");
                LoadingSemaphore.Release();
            }
        }
コード例 #12
0
        /// <summary>
        /// Search shows asynchronously
        /// </summary>
        /// <param name="searchFilter">The parameter of the search</param>
        public async Task SearchShowsAsync(string searchFilter)
        {
            var watch = Stopwatch.StartNew();

            if (SearchFilter != searchFilter)
            {
                // We start an other search
                StopLoadingShows();
                Shows.Clear();
                Page = 0;
                CurrentNumberOfShows = 0;
                MaxNumberOfShows     = 0;
                IsLoadingShows       = false;
            }

            Page++;
            if (Page > 1 && Shows.Count == MaxNumberOfShows)
            {
                return;
            }
            Logger.Info(
                $"Loading shows search page {Page} with criteria: {searchFilter}");
            HasLoadingFailed = false;
            try
            {
                SearchFilter   = searchFilter;
                IsLoadingShows = true;
                var result =
                    await ShowService.SearchShowsAsync(searchFilter,
                                                       Page,
                                                       MaxNumberOfShows,
                                                       Genre,
                                                       Rating * 10,
                                                       CancellationLoadingShows.Token)
                    .ConfigureAwait(false);

                DispatcherHelper.CheckBeginInvokeOnUI(async() =>
                {
                    Shows.AddRange(result.shows);
                    IsLoadingShows       = false;
                    IsShowFound          = Shows.Any();
                    CurrentNumberOfShows = Shows.Count;
                    MaxNumberOfShows     = result.nbShows;
                    await UserService.SyncShowHistoryAsync(Shows).ConfigureAwait(false);
                });
            }
            catch (Exception exception)
            {
                Page--;
                Logger.Error(
                    $"Error while loading shows search page {Page} with criteria {searchFilter}: {exception.Message}");
                HasLoadingFailed = true;
                Messenger.Default.Send(new ManageExceptionMessage(exception));
            }
            finally
            {
                watch.Stop();
                var elapsedMs = watch.ElapsedMilliseconds;
                Logger.Info(
                    $"Loaded shows search page {Page} with criteria {searchFilter} in {elapsedMs} milliseconds.");
            }
        }
コード例 #13
0
        /// <summary>
        /// Load shows asynchronously
        /// </summary>
        public override async Task LoadShowsAsync(bool reset = false)
        {
            await LoadingSemaphore.WaitAsync();

            if (reset)
            {
                Shows.Clear();
                Page           = 0;
                VerticalScroll = 0d;
            }

            var watch = Stopwatch.StartNew();

            Page++;
            if (Page > 1 && Shows.Count == MaxNumberOfShows)
            {
                Page--;
                LoadingSemaphore.Release();
                return;
            }

            StopLoadingShows();
            Logger.Info(
                $"Loading page {Page}...");
            HasLoadingFailed = false;
            try
            {
                IsLoadingShows = true;
                await Task.Run(async() =>
                {
                    var getMoviesWatcher = new Stopwatch();
                    getMoviesWatcher.Start();
                    var result =
                        await ShowService.Discover(Page).ConfigureAwait(false);
                    getMoviesWatcher.Stop();
                    var getMoviesEllapsedTime = getMoviesWatcher.ElapsedMilliseconds;
                    if (reset && getMoviesEllapsedTime < 500)
                    {
                        // Wait for VerticalOffset to reach 0 (animation lasts 500ms)
                        await Task.Delay(500 - (int)getMoviesEllapsedTime).ConfigureAwait(false);
                    }

                    DispatcherHelper.CheckBeginInvokeOnUI(() =>
                    {
                        Shows.AddRange(result.Item1.Except(Shows, new ShowLightComparer()));
                        IsLoadingShows       = false;
                        IsShowFound          = Shows.Any();
                        CurrentNumberOfShows = Shows.Count;
                        MaxNumberOfShows     = result.nbMovies;
                        UserService.SyncShowHistory(Shows);
                    });
                }).ConfigureAwait(false);
            }
            catch (Exception exception)
            {
                Page--;
                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 page {Page} in {elapsedMs} milliseconds.");
                LoadingSemaphore.Release();
            }
        }
コード例 #14
0
 private bool HasAlreadyShow(Show show)
 {
     return(Shows?.Any(x => x.Id == show?.Id) == true);
 }