public void Save(SmartPlaylistDto smartPlaylist)
 {
     using (PerfLogger.Create("SaveSmartPlaylist", () => new { smartPlaylistName = smartPlaylist.Name }))
     {
         _decorated.Save(smartPlaylist);
     }
 }
        public void Post(SaveSmartPlaylist request)
        {
            var playlist = request;
            var user     = GetUser();

            playlist.UserId            = user.Id;
            playlist.LastShuffleUpdate = DateTimeOffset.UtcNow.Date;
            _smartPlaylistValidator.Validate(playlist);
            _smartPlaylistStore.Save(playlist);

            _messageBus.Publish(new UpdateSmartPlaylistCommand(Guid.Parse(playlist.Id)));
        }
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 async Task HandleAsync(UpdateSmartPlaylistCommand message)
        {
            var smartPlaylist = await _smartPlaylistProvider.GetSmartPlaylistAsync(message.SmartPlaylistId)
                                .ConfigureAwait(false);

            var playlist = _playlistRepository.GetUserPlaylist(smartPlaylist.UserId, smartPlaylist.Name);

            var items = _userItemsProvider.GetItems(playlist.User, Const.SupportedItemTypeNames).ToArray();

            BaseItem[] newItems;
            using (PerfLogger.Create("FilterPlaylistItems",
                                     () => new { playlistName = playlist.Name, itemsCount = items.Length }))
            {
                newItems = smartPlaylist.FilterPlaylistItems(playlist, items).ToArray();
            }

            await _playlistItemsUpdater.UpdateAsync(playlist, newItems).ConfigureAwait(false);

            if (smartPlaylist.IsShuffleUpdateType)
            {
                smartPlaylist.UpdateLastShuffleTime();
                _smartPlaylistStore.Save(smartPlaylist.ToDto());
            }
        }
 public void Save(SmartPlaylistDto smartPlaylist)
 {
     _decorated.Save(smartPlaylist);
     _memCache.Set(smartPlaylist.Id, smartPlaylist);
 }
Exemplo n.º 6
0
 public void Save(SmartPlaylistDto smartPlaylist)
 {
     _decorated.Save(smartPlaylist);
 }