Exemplo n.º 1
0
        public void DtoToSmartPlaylist()
        {
            var dto = new SmartPlaylistDto();

            dto.Id   = "87ccaa10-f801-4a7a-be40-46ede34adb22";
            dto.Name = "Foo";
            dto.User = "******";

            var es = new ExpressionSet();

            es.Expressions = new List <Expression>
            {
                new Expression("foo", "bar", "biz")
            };
            dto.ExpressionSets = new List <ExpressionSet>
            {
                es
            };
            dto.Order = new OrderDto
            {
                Name = "Release Date Descending"
            };
            SmartPlaylist smart_playlist = new SmartPlaylist(dto);

            Assert.Equal(1000, smart_playlist.MaxItems);
            Assert.Equal("87ccaa10-f801-4a7a-be40-46ede34adb22", smart_playlist.Id);
            Assert.Equal("Foo", smart_playlist.Name);
            Assert.Equal("Rob", smart_playlist.User);
            Assert.Equal("foo", smart_playlist.ExpressionSets[0].Expressions[0].MemberName);
            Assert.Equal("bar", smart_playlist.ExpressionSets[0].Expressions[0].Operator);
            Assert.Equal("biz", smart_playlist.ExpressionSets[0].Expressions[0].TargetValue);
            Assert.Equal("PremiereDateOrderDesc", smart_playlist.Order.GetType().Name);
        }
Exemplo n.º 2
0
        public ActionResult Index(List <int> selectedGenres     = null,
                                  List <string> selectedArtists = null,
                                  string titleSearch            = null,
                                  int minRating       = 0,
                                  string filter       = null,
                                  string save         = null,
                                  string playlistName = null)
        {
            if (selectedArtists == null)
            {
                selectedArtists = new List <string>();
            }
            if (selectedGenres == null)
            {
                selectedGenres = new List <int>();
            }

            var spec = new GlobalSongSpecification();

            spec.ArtistsToInclude.AddRange(selectedArtists);
            spec.GenreIdsToInclude.AddRange(selectedGenres);
            spec.MinRating   = minRating;
            spec.TitleFilter = titleSearch;

            var songs = _songRepository.List(spec);

            var viewModel = new HomeViewModel();

            viewModel.Artists         = _songRepository.AllArtists().ToList();
            viewModel.Genres          = _songRepository.AllGenres().ToList();
            viewModel.SelectedArtists = viewModel.Artists
                                        .Where(a => spec.ArtistsToInclude.Contains(a))
                                        .ToList();
            viewModel.SelectedGenres = viewModel.Genres
                                       .Where(g => selectedGenres.Contains(g.Id))
                                       .ToList();
            viewModel.Songs = songs.ToList();

            if (save != null)
            {
                var smartPlaylist = new SmartPlaylist();
                smartPlaylist.Name          = playlistName;
                smartPlaylist.Specification = spec;
                var playlistRepo = new SmartPlaylistRepository(_dbContext);
                playlistRepo.Add(smartPlaylist);
                return(RedirectToAction("Index", "SmartPlaylists"));
            }

            return(View(viewModel));
        }
Exemplo n.º 3
0
        public Task Execute(CancellationToken cancellationToken, IProgress <double> progress)
        {
            var dtos = _plStore.GetAllSmartPlaylistsAsync();

            dtos.Wait();
            foreach (var dto in dtos.Result)
            {
                SmartPlaylist smart_playlist = new SmartPlaylist(dto);

                var             user = _userManager.GetUserByName(smart_playlist.User);
                List <Playlist> p;
                try
                {
                    var playlists = _playlistManager.GetPlaylists(user.Id);
                    p = playlists.Where(x => x.Id.ToString().Replace("-", "") == dto.Id).ToList();
                }
                catch (NullReferenceException ex)
                {
                    _logger.LogError(ex, "No user named {0} found, please fix playlist {1}", dto.User, dto.Name);
                    continue;
                }


                if (dto.Id == null | p.Count() == 0)
                {
                    _logger.LogInformation("Playlist ID not set, creating new playlist");
                    var plid = CreateNewPlaylist(dto, user);
                    dto.Id = plid;
                    _plStore.Save(dto);
                    var playlists = _playlistManager.GetPlaylists(user.Id);
                    p = playlists.Where(x => x.Id.ToString().Replace("-", "") == dto.Id).ToList();
                }

                var new_items = smart_playlist.FilterPlaylistItems(GetAllUserMedia(user), _libraryManager, user);

                var playlist = p.First();
                var query    = new InternalItemsQuery(user)
                {
                    IncludeItemTypes = SupportedItemTypeNames,
                    Recursive        = true,
                };
                var plitems = playlist.GetChildren(user, false, query).ToList();

                var toremove = plitems.Select(x => x.Id.ToString()).ToList();
                RemoveFromPlaylist(playlist.Id.ToString(), toremove);
                _playlistManager.AddToPlaylistAsync(playlist.Id, new_items.ToArray(), user.Id);
            }
            return(Task.CompletedTask);
        }
Exemplo n.º 4
0
        public IActionResult OnPost(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            SmartPlaylist = _smartPlaylistRepository.FindById(id ?? 0);

            if (SmartPlaylist != null)
            {
                _smartPlaylistRepository.Remove(SmartPlaylist);
            }

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 5
0
        public IActionResult OnGet(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            SmartPlaylist = _smartPlaylistRepository.FindById(id ?? 0);

            if (SmartPlaylist == null)
            {
                return(NotFound());
            }

            return(Page());
        }
 public void Remove(SmartPlaylist playlist)
 {
     _dbContext.SmartPlaylists.Remove(playlist);
     _dbContext.SaveChanges();
 }
 public void Add(SmartPlaylist playlist)
 {
     _dbContext.SmartPlaylists.Add(playlist);
     _dbContext.SaveChanges();
 }