Пример #1
0
 public void RemoveShow(ShowTileViewModel show)
 {
     if (Shows.Contains(show))
     {
         show.Show.PropertyChanged -= Show_PropertyChanged;
         Shows.Remove(show);
     }
 }
Пример #2
0
        public static Boolean RemoveFavoriteShow(Area show)
        {
            var toDelete = Shows.FirstOrDefault(s => s.ID == show.ID);

            if (toDelete == null)
            {
                return(false);
            }

            Shows.Remove(toDelete);
            Helpers.Settings.FavoriteShows = JsonConvert.SerializeObject(Shows);
            FavoritesDirty = true;
            return(true);
        }
Пример #3
0
        public bool DeleteShow(int id)
        {
            if (!ShowsId.Any(s => s == id))
            {
                return(false);
            }
            Show show = Shows.First(s => s.Id == id);

            ShowsId.Remove(id);
            Shows.Remove(show);
            SaveData();
            ChangedShow?.Invoke();
            return(true);
        }
Пример #4
0
        public void RemoveByTitleFromEmptyTest()
        {
            // Arrange.
            var movies = PopulateMovies();
            var shows  = new Shows();

            // Act.
            var actual = shows.Remove(movies.Items[1].Title);

            // Assert.
            var expected = false;

            Assert.AreEqual(expected, actual);
        }
Пример #5
0
        public void RemoveShow(Show show)
        {
            var foundShow = Shows?.FirstOrDefault(x => x.Id == show?.Id);

            if (foundShow is null)
            {
                return;
            }
            if (!HasAlreadyShow(foundShow))
            {
                ;
            }
            Shows.Remove(foundShow);
        }
Пример #6
0
        private void RemoveMovie()
        {
            Console.WriteLine("Wybierz film do usunięcia");
            var movie = FindMovie();

            if (movie != null)
            {
                Console.Write(movie);
                Console.WriteLine("Czy chcesz usunąć ten film? T/N");
                var key = Console.ReadKey();
                Console.WriteLine(Environment.NewLine);
                switch (key.KeyChar)
                {
                default:
                {
                    Console.WriteLine("Niepoprawny znak.");
                    break;
                }

                case 't':
                {
                    // Usuwa wszystkie seanse danego filmu.
                    shows.Remove(movie.Title);
                    // Usuwa film.
                    movies.Remove(movie.ID);
                    Console.WriteLine("Film oraz seanse usunięte.");
                    break;
                }

                case 'n':
                {
                    Console.WriteLine("Operacja przerwana.");
                    break;
                }
                }
            }
        }
Пример #7
0
        public void DeleteShow(ShowVM showVM)
        {
            CinemaMovieShowBooking deleteShow = new CinemaMovieShowBooking {
                ShowDateTime = showVM.ShowDateTime
            };

            try
            {
                repo.Delete(deleteShow);
                Shows.Remove(showVM);
                RefreshVMs();
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #8
0
        public void RemoveByWrongIdTest()
        {
            // Arrange.
            var movies = PopulateMovies();
            var shows  = new Shows();
            var show1  = new Show(1, Convert.ToDateTime("2017-12-12 12:00"), 120, 15, movies.Items[1]);

            shows.Items.Add(1, show1);

            // Act.
            var actual = shows.Remove(2);

            // Assert.
            var expected = false;

            Assert.AreEqual(expected, actual);
        }
Пример #9
0
        public void RemoveByTitleTest()
        {
            // Arrange.
            var movies        = PopulateMovies();
            var shows         = new Shows();
            var showsExpected = new Shows();
            var show1         = new Show(1, Convert.ToDateTime("2017-12-12 12:00"), 120, 15, movies.Items[1]);

            shows.Items.Add(1, show1);
            showsExpected.Items.Add(1, show1);

            // Act.
            shows.Remove(movies.Items[1].Title);
            showsExpected.Items.Remove(1);

            // Assert.
            var expected = true;
            var actual   = showsExpected.Equals(shows);

            Assert.AreEqual(expected, actual);
        }
Пример #10
0
        public void RemoveByTitleMultipleTest()
        {
            // Arrange.
            var movies = PopulateMovies();
            var shows  = new Shows();
            var show1  = new Show(1, Convert.ToDateTime("2017-12-12 12:00"), 120, 15, movies.Items[1]);
            var show2  = new Show(2, Convert.ToDateTime("2017-12-13 13:00"), 120, 15, movies.Items[1]);
            var show3  = new Show(3, Convert.ToDateTime("2017-12-14 14:00"), 120, 15, movies.Items[1]);

            shows.Items.Add(1, show1);
            shows.Items.Add(2, show2);
            shows.Items.Add(3, show3);

            // Act.
            shows.Remove(movies.Items[1].Title);

            // Assert.
            var expected = false;
            var actual   = shows.Items.Any();

            Assert.AreEqual(expected, actual);
        }
Пример #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 <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();
            }
        }
Пример #12
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();
            }
        }