Пример #1
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}");
        }
Пример #2
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}");
        }
Пример #3
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}");
        }
Пример #4
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);
        }
Пример #5
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}");
        }
Пример #6
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}");
        }
Пример #7
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}");
        }
Пример #8
0
        private async Task DeleteAsync(MusicDb db, PathData pd)
        {
            db.ChangeTracker.AutoDetectChangesEnabled = false;
            taskItem = await db.TaskItems.FindAsync(taskId);

            IEnumerable <MusicFile> musicFileList = null;
            string path = "";

            if (pd.GetFullOpusPath() != null)
            {
                path          = pd.IsCollections ? pd.OpusPath : $"{pd.ArtistPath}\\{pd.OpusPath}";
                musicFileList = db.MusicFiles
                                .Where(f => (f.DiskRoot.ToLower() == pd.DiskRoot.ToLower()) &&
                                       (f.StylePath.ToLower() == pd.StylePath.ToLower()) &&
                                       (f.OpusPath.ToLower() == path.ToLower()))
                                .OrderBy(f => f.File)
                ;
            }
            else
            {
                if (pd.IsCollections)
                {
                    musicFileList = db.MusicFiles
                                    .Where(f => (f.DiskRoot.ToLower() == pd.DiskRoot.ToLower()) &&
                                           (f.StylePath.ToLower() == pd.StylePath.ToLower()) &&
                                           f.Musician.ToLower() == "collections")
                                    .OrderBy(f => f.File)
                    ;
                }
                else
                {
                    musicFileList = db.MusicFiles
                                    .Where(f => (f.DiskRoot.ToLower() == pd.DiskRoot.ToLower()) &&
                                           (f.StylePath.ToLower() == pd.StylePath.ToLower()) &&
                                           f.OpusPath.StartsWith(pd.ArtistPath))
                                    .OrderBy(f => f.File)
                    ;
                }
            }

            log.Information($"Deleting {musicFileList.Count()} music files");
            var dc = new DeleteContext(taskItem);

            foreach (var mf in musicFileList)
            {
                db.Delete(mf, dc);
            }
            taskItem.Status     = Music.Core.TaskStatus.Finished;
            taskItem.FinishedAt = DateTimeOffset.Now;
            await db.SaveChangesAsync();

            if (dc.DeletedArtistId.HasValue)
            {
                await this.playManager.SendArtistDeleted(dc.DeletedArtistId.Value);
            }
            else if (dc.ModifiedArtistId.HasValue)
            {
                var shouldSend = true;
                var artist     = await db.Artists.FindAsync(dc.ModifiedArtistId.Value);

                if (artist != null)
                {
                    shouldSend = artist.Type != ArtistType.Various;
                }
                if (shouldSend)
                {
                    await this.playManager.SendArtistNewOrModified(dc.ModifiedArtistId.Value);
                }
            }
            //if (dc.DeletedArtistId.HasValue || dc.ModifiedArtistId.HasValue)
            //{
            //    var shouldSend = true;
            //    var id = dc.ModifiedArtistId ?? 0;
            //    if (id > 0)
            //    {
            //        var artist = await db.Artists.FindAsync(id);
            //        shouldSend = artist.Type != ArtistType.Various;
            //    }
            //    if (shouldSend)
            //    {
            //        if (dc.DeletedArtistId.HasValue)
            //        {
            //            await this.playManager.SendArtistDeleted(dc.DeletedArtistId.Value);
            //        }
            //        else if (dc.ModifiedArtistId.HasValue)
            //        {
            //            await this.playManager.SendArtistNewOrModified(dc.ModifiedArtistId.Value);
            //        }
            //    }
            //}
            // send artist modified/deleted - info is in dc
        }