Ejemplo n.º 1
0
        public static void InitialiseOld(MusicDb db)
        {
            var log      = db.Database.GetService <ILogger <MusicDbInitialiser> >() as ILogger;
            var creator  = db.Database.GetService <IDatabaseCreator>() as RelationalDatabaseCreator;
            var dbExists = creator.Exists();

            if (dbExists)
            {
                log.Information("MusicDb exists");
                db.Database.Migrate();
                log.Trace("The following migrations have been applied:");
                var migrations = db.Database.GetAppliedMigrations();
                foreach (var migration in migrations)
                {
                    log.Trace($"\t{migration}");
                }
            }
            else
            {
                log.Warning("No MusicDb found");
                creator.EnsureCreated();
                log.Information("new MusicDb created");
            }

            db.UpgradeContent();
        }
Ejemplo n.º 2
0
        public static string GetDisplayName(this MusicDb db, Performance performance)
        {
            //await db.Entry(performance).Reference(x => x.Composition).LoadAsync();
            //await db.Entry(performance.Composition).Reference(x => x.Artist).LoadAsync();
            var parts = performance.Composition.Artist.Name.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            return($"{parts.Last()}, {performance.Composition.Name}");
        }
Ejemplo n.º 3
0
        public static IEnumerable <(Track track, long musicFileId)> GetTracks(this MusicDb db, IPlayable playable)
        {
            var list = new List <(Track track, long musicFileId)>();

            //await db.LoadRelatedEntities(playable);
            foreach (var track in playable.Tracks.OrderBy(t => t.Number))
            {
                //await db.LoadRelatedEntities(track);
                list.Add((track, track.MusicFiles.OrderByDescending(mf => mf.Rank()).First().Id));
            }
            return(list);
        }
Ejemplo n.º 4
0
        private static async Task LoadRelatedEntities <T>(this MusicDb db, T playable) where T : class, IPlayable
        {
            switch (playable)
            {
            case Work work:
                await db.LoadRelatedEntities(work);

                break;

            case Performance performance:
                await db.LoadRelatedEntities(performance);

                break;
            }
        }
Ejemplo n.º 5
0
        //public static void Delete(this MusicDb musicDb, MusicFile mf)
        //{
        //    musicDb.RemovePlaylistItems(mf);
        //    var tags = mf.IdTags.ToArray();
        //    musicDb.IdTags.RemoveRange(tags);
        //    musicDb.MusicFiles.Remove(mf);
        //}
        public static void RemovePlaylistItems <T>(this MusicDb musicDb, T entity)
        {
            PlaylistItemType itemType = PlaylistItemType.MusicFile;
            long             itemId   = 0;

            switch (entity)
            {
            case Performance p:
                itemType = PlaylistItemType.Performance;
                itemId   = p.Id;
                break;

            case Work w:
                itemType = PlaylistItemType.Work;
                itemId   = w.Id;
                break;

            case Track t:
                itemType = PlaylistItemType.Track;
                itemId   = t.Id;
                break;

            case MusicFile mf:
                itemType = PlaylistItemType.MusicFile;
                itemId   = mf.Id;
                break;
            }
            var items = musicDb.PlaylistItems.Where(x => x.Type == itemType && x.ItemId == itemId).ToArray();

            foreach (var item in items)
            {
                var playlist = item.Playlist;
                item.Playlist = null;
                playlist.Items.Remove(item);
                musicDb.PlaylistItems.Remove(item);
                //log.Information($"playlist item {item.Title} removed from {playlist.Name}");
                if (playlist.Items.Count() == 0)
                {
                    musicDb.Playlists.Remove(playlist);
                    //log.Information($"playlist {playlist.Name} removed");
                }
            }
        }
Ejemplo n.º 6
0
 private static async Task LoadRelatedEntities(this MusicDb db, Track track)
 {
     await db.Entry(track).Collection(x => x.MusicFiles).LoadAsync();
 }
Ejemplo n.º 7
0
 private static async Task LoadRelatedEntities(this MusicDb db, Work work)
 {
     await db.Entry(work).Collection(x => x.Tracks).LoadAsync();
 }
Ejemplo n.º 8
0
 private static async Task LoadRelatedEntities(this MusicDb db, Performance performance)
 {
     await db.Entry(performance).Collection(x => x.Movements).LoadAsync();
 }
Ejemplo n.º 9
0
        public static CatalogueSearcher GetSearcher(MusicOptions options, MusicStyles style, MusicDb musicDb, ILogger log = null)
        {
            CatalogueSearcher cs = null;

            switch (style)
            {
            case MusicStyles.Popular:
                cs = new PopularSearcher();
                break;

            case MusicStyles.WesternClassical:
                cs = new WesternClassicalSearcher();
                break;
            }
            cs.Options    = options;
            cs.MusicStyle = style;
            cs.MusicDb    = musicDb;
            cs.log        = log;
            return(cs);
        }