Пример #1
0
        private void DeleteAudioMediaInternal(AudioMedia entity)
        {
            // delete audio media in database
            var album = entity.Album;
            base.AudioMediaDataService.Delete(entity);
            this.Songs.Remove(entity);

            // reflect changes into database and the cache
            album.Songs.Remove(entity);
            if (album.Songs.Count == 0)
            {
                var artist = album.Artist;
                base.AlbumDataService.Delete(new Album() { Id = album.Id });
                artist.Albums.Remove(album);
                this.Albums.Remove(album);
                if (artist.Albums.Count == 0)
                {
                    base.ArtistDataService.Delete(new Artist() { Id = artist.Id });
                    this.Artists.Remove(artist);
                }
            }
            foreach (var playlist in this.Playlists.Where(x => x.Songs.Any(y => y.Id == entity.Id)))
            {
                base.PlaylistAudioMediaDataService.Delete(new PlaylistAudioMedia() { PlaylistId = playlist.Id, AudioMediaId = entity.Id });
                playlist.Songs.Remove(entity);
            }
        }
Пример #2
0
        public DataAsyncResult UpdateAudioMedia(AudioMedia entity, string title, string album, string artist, bool isProtected, List<int> playlistsToAdd, List<int> playlistsToRemove, TaskParam taskParam)
        {
            return this.EnqueueRequest(taskParam, () =>
            {
                // find or create artist entity
                var artistEntity = this.Artists.FirstOrDefault(x => x.Name.Trim().ToUpper() == artist.Trim().ToUpper());
                if (artistEntity == null)
                {
                    artistEntity = new Artist() { Name = artist };
                    base.ArtistDataService.Insert(artistEntity);
                    this.Artists.Add(artistEntity);
                }

                // find or create album entity
                var albumEntity = artistEntity.Albums.FirstOrDefault(x => x.Title.Trim().ToUpper() == album.Trim().ToUpper());
                if (albumEntity == null)
                {
                    albumEntity = new Album() { ArtistId = artistEntity.Id, Title = album };
                    base.AlbumDataService.Insert(albumEntity);
                    artistEntity.Albums.Add(albumEntity);
                    this.Albums.Add(albumEntity);
                    albumEntity.Artist = artistEntity;
                }

                // update audiomedia entity
                int previousAlbumId = entity.Album.Id;
                entity.Title = title;
                entity.IsProtected = isProtected;
                entity.AlbumId = albumEntity.Id;
                entity.Album = albumEntity;
                base.AudioMediaDataService.Update(entity);

                // reflect changes into database and the cache
                if (previousAlbumId != albumEntity.Id)
                {
                    albumEntity.Songs.Add(entity);
                    var previousAlbum = this.Albums.FirstOrDefault(x => x.Id == previousAlbumId);
                    previousAlbum.Songs.Remove(entity);
                    if (previousAlbum.Songs.Count == 0)
                    {
                        var previousArtist = previousAlbum.Artist;
                        base.AlbumDataService.Delete(new Album() { Id = previousAlbum.Id });
                        previousArtist.Albums.Remove(previousAlbum);
                        this.Albums.Remove(previousAlbum);
                        if (previousArtist.Albums.Count == 0)
                        {
                            base.ArtistDataService.Delete(new Artist() { Id = previousArtist.Id });
                            this.Artists.Remove(previousArtist);
                        }
                    }
                }

                foreach (var item in playlistsToAdd)
                {
                    var playlist = this.Playlists.First(x => x.Id == item);
                    this.AddAudioMediaToPlaylist(entity, playlist);
                }

                foreach (var item in playlistsToRemove)
                {
                    var playlist = this.Playlists.First(x => x.Id == item);
                    this.RemoveAudioMediaFromPlaylist(entity, playlist);
                }

                return null;
            });
        }
Пример #3
0
        private void AddAudioMediaInternal(string title, string album, string artist, string filesystemId, bool isProtected)
        {
            // find or create artist entity
            var artistEntity = this.Artists.FirstOrDefault(x => x.Name.Trim().ToUpper() == artist.Trim().ToUpper());
            if (artistEntity == null)
            {
                artistEntity = new Artist() { Name = artist };
                base.ArtistDataService.Insert(artistEntity);
                this.Artists.Add(artistEntity);
            }

            // find or create album entity
            var albumEntity = artistEntity.Albums.FirstOrDefault(x => x.Title.Trim().ToUpper() == album.Trim().ToUpper());
            if (albumEntity == null)
            {
                albumEntity = new Album() { ArtistId = artistEntity.Id, Title = album };
                base.AlbumDataService.Insert(albumEntity);
                artistEntity.Albums.Add(albumEntity);
                this.Albums.Add(albumEntity);
                albumEntity.Artist = artistEntity;
            }

            // create audiomedia entity
            var audioMediaEntity = new AudioMedia()
            {
                AlbumId = albumEntity.Id,
                FilesystemId = filesystemId,
                Title = title,
                IsProtected = isProtected,
            };
            base.AudioMediaDataService.Insert(audioMediaEntity);
            this.Songs.Add(audioMediaEntity);
            albumEntity.Songs.Add(audioMediaEntity);
            audioMediaEntity.Album = albumEntity;
            albumEntity.Artist = artistEntity;
        }
Пример #4
0
 public DataAsyncResult SendToVideoLibrary(AudioMedia entity, TaskParam taskParam)
 {
     return this.EnqueueRequest(taskParam, () =>
     {
         var title = entity.Title;
         var fileSystemId = entity.FilesystemId;
         var isProtected = entity.IsProtected;
         this.DeleteAudioMediaInternal(entity);
         this.AddVideoMediaInternal(title, fileSystemId, isProtected);
         return null;
     });
 }
Пример #5
0
 public void RemoveAudioMediaFromPlaylist(AudioMedia audioMedia, Playlist playlist)
 {
     base.PlaylistAudioMediaDataService.Delete(new PlaylistAudioMedia() { PlaylistId = playlist.Id, AudioMediaId = audioMedia.Id });
     playlist.Songs.Remove(audioMedia);
 }
Пример #6
0
 public DataAsyncResult DeleteAudioMedia(AudioMedia entity, TaskParam taskParam)
 {
     return this.EnqueueRequest(taskParam, () =>
     {
         DeleteAudioMediaInternal(entity);
         return null;
     });
 }
Пример #7
0
 public void AddAudioMediaToPlaylist(AudioMedia audioMedia, Playlist playlist)
 {
     base.PlaylistAudioMediaDataService.Insert(new PlaylistAudioMedia() { PlaylistId = playlist.Id, AudioMediaId = audioMedia.Id });
     playlist.Songs.Add(audioMedia);
 }
Пример #8
0
 public void Play(AudioMedia audioMedia)
 {
     this.PlayInternal(new List<AudioMedia>() { audioMedia });
 }