Beispiel #1
0
        public static void Delete(this MusicDb musicDb, MusicFile mf, DeleteContext context)
        {
            void clearRelatedEntities(MusicFile file)
            {
                musicDb.RemovePlaylistItems(file);
                var tags = file.IdTags.ToArray();

                musicDb.IdTags.RemoveRange(tags);
            }

            clearRelatedEntities(mf);
            var track = mf.Track;

            track?.MusicFiles.Remove(mf);
            if (track?.MusicFiles.All(x => x.IsGenerated) ?? false)
            {
                foreach (var f in track.MusicFiles.ToArray())
                {
                    clearRelatedEntities(f);
                    f.Track = null;
                    track.MusicFiles.Remove(f);
                    musicDb.MusicFiles.Remove(f);
                    log.Information($"{context}: Musicfile [MF-{f.Id}] deleted: {f.File}");
                }
            }
            if (track?.MusicFiles.Count() == 0)
            {
                musicDb.Delete(track, context);
            }
            musicDb.MusicFiles.Remove(mf);
            log.Information($"{context}: Musicfile [MF-{mf.Id}] deleted: {mf.File}");
        }
Beispiel #2
0
        private static void Delete(this MusicDb musicDb, Track track, DeleteContext context)
        {
            long artistId = track.Work.ArtistId;

            foreach (var musicFile in track.MusicFiles.ToArray())
            {
                musicFile.Track = null;
                musicDb.Delete(musicFile, context);
            }
            var performance = track.Performance;

            performance?.Movements.Remove(track);
            if (performance?.Movements.Count() == 0)
            {
                musicDb.Delete(performance, context);
            }
            var work = track.Work;

            work?.Tracks.Remove(track);
            if (work?.Tracks.Count() == 0)
            {
                musicDb.Delete(work, context);
            }
            musicDb.Tracks.Remove(track);
            context.SetModifiedArtistId(artistId);
            log.Information($"{context}: Track [T-{track.Id}] deleted: {track.Title}");
        }
Beispiel #3
0
        public int RemoveCurrentMusicFiles(MusicDb db)
        {
            int count     = 0;
            var filesInDb = GetMusicFilesFromDb(db);

            foreach (var mf in filesInDb.ToArray())
            {
                ++count;
                var dc = new DeleteContext(this);
                db.Delete(mf, dc);
            }
            return(count);
        }
Beispiel #4
0
        private static void Delete(this MusicDb musicDb, Artist artist, DeleteContext context)
        {
            long artistId = artist.Id;

            foreach (var composition in artist.Compositions)
            {
                composition.Artist = null;
                musicDb.Delete(composition, context);
            }
            foreach (var work in artist.Works)
            {
                work.Artist = null;
                musicDb.Delete(work, context);
            }
            var styles = artist.ArtistStyles.ToArray();

            musicDb.ArtistStyles.RemoveRange(styles);
            musicDb.Artists.Remove(artist);
            context.SetDeletedArtistId(artistId);
            log.Information($"{context}: Artist [A-{artist.Id}] deleted: {artist.Name}");
        }
Beispiel #5
0
        private static void Delete(this MusicDb musicDb, Performance performance, DeleteContext context)
        {
            long artistId = performance.Composition.ArtistId;

            foreach (var movement in performance.Movements)
            {
                movement.Performance = null;
                // we do not delete movements here because
                // a movement is a track and tracks are also in an album
            }
            performance.Movements.Clear();
            var composition = performance.Composition;

            composition?.Performances.Remove(performance);
            if (composition?.Performances.Count() == 0)
            {
                musicDb.Delete(composition, context);
            }
            musicDb.Performances.Remove(performance);
            context.SetModifiedArtistId(artistId);
            log.Information($"{context}: Performance [P-{performance.Id}] deleted: {performance.Performers}");
        }
Beispiel #6
0
        private static void Delete(this MusicDb musicDb, Work work, DeleteContext context)
        {
            long artistId = work.ArtistId;

            foreach (var track in work.Tracks)
            {
                track.Work = null;
                musicDb.Delete(track, context);
            }
            var artist = work.Artist;

            artist?.Works.Remove(work);
            if (artist != null)
            {
                if (artist.Works.Count() == 0 && artist.Compositions.Count() == 0)
                {
                    musicDb.Delete(artist, context);
                }
            }
            musicDb.Works.Remove(work);
            context.SetModifiedArtistId(artistId);
            log.Information($"{context}: Work [W-{work.Id}] deleted: {work.Name}");
        }
Beispiel #7
0
        private static void Delete(this MusicDb musicDb, Composition composition, DeleteContext context)
        {
            long artistId = composition.ArtistId;

            foreach (var performance in composition.Performances)
            {
                performance.Composition = null;
                musicDb.Delete(performance, context);
            }
            composition.Performances.Clear();
            musicDb.Compositions.Remove(composition);
            var artist = composition.Artist;

            artist?.Compositions.Remove(composition);
            if (artist != null)
            {
                if (artist.Works.Count() == 0 && artist.Compositions.Count() == 0)
                {
                    musicDb.Delete(artist, context);
                }
            }
            context.SetModifiedArtistId(artistId);
            log.Information($"{context}: Composition [C-{composition.Id}] deleted: {composition.Name}");
        }