コード例 #1
0
        public static DatabaseAlbumInfo UpdateOrCreate(DatabaseArtistInfo artist, DatabaseAlbumInfo album)
        {
            DatabaseAlbumInfo found = FindOrCreate(artist, album);

            if (found != album)
            {
                // Overwrite the found album
                album.Title          = found.Title;
                album.TitleSort      = found.TitleSort;
                album.ArtistName     = found.ArtistName;
                album.ArtistNameSort = found.ArtistNameSort;
                album.IsCompilation  = found.IsCompilation;
                album.dbid           = found.DbId;
                album.ArtistId       = found.ArtistId;
                album.Save();
            }
            return(album);
        }
コード例 #2
0
 public static DatabaseAlbumInfo UpdateOrCreate(DatabaseArtistInfo artist, DatabaseAlbumInfo album)
 {
     DatabaseAlbumInfo found = FindOrCreate (artist, album);
     if (found != album) {
         // Overwrite the found album
         album.Title = found.Title;
         album.TitleSort = found.TitleSort;
         album.ArtistName = found.ArtistName;
         album.ArtistNameSort = found.ArtistNameSort;
         album.IsCompilation = found.IsCompilation;
         album.MusicBrainzId = found.MusicBrainzId;
         album.dbid = found.DbId;
         album.ArtistId = found.ArtistId;
         album.ArtworkId = found.ArtworkId;
         album.Save ();
     }
     return album;
 }
コード例 #3
0
        public static DatabaseAlbumInfo FindOrCreate(DatabaseArtistInfo artist, DatabaseAlbumInfo album)
        {
            if (album.Title == last_title && artist.DbId == last_artist_id && last_album != null) {
                return last_album;
            }

            if (String.IsNullOrEmpty (album.Title) || album.Title.Trim () == String.Empty) {
                album.Title = null;
            }

            using (IDataReader reader = FindExistingArtists (artist.DbId, album.Title)) {
                if (reader.Read ()) {
                    bool save = false;
                    last_album = provider.Load (reader);

                    // If the artist name has changed since last time (but it's the same artist) then update our copy of the ArtistName
                    if (last_album.ArtistName != artist.Name) {
                        last_album.ArtistName = artist.Name;
                        save = true;
                    }

                    // Ditto artist sort name
                    if (last_album.ArtistNameSort != artist.NameSort) {
                        last_album.ArtistNameSort = artist.NameSort;
                        save = true;
                    }

                    // And album sort name
                    if (last_album.TitleSort != album.TitleSort) {
                        last_album.TitleSort = album.TitleSort;
                        save = true;
                    }

                    // If the album IsCompilation status has changed, update the saved album info
                    if (last_album.IsCompilation != album.IsCompilation) {
                        last_album.IsCompilation = album.IsCompilation;
                        save = true;
                    }

                    // If the album MusicBrainzId has changed, but is not null
                    if (last_album.MusicBrainzId != album.MusicBrainzId && !String.IsNullOrEmpty (album.MusicBrainzId)) {
                        last_album.MusicBrainzId = album.MusicBrainzId;
                        save = true;
                    }

                    // If the ArtworkId has changed, update the db
                    if (last_album.ArtworkId != album.ArtworkId) {
                        last_album.ArtworkId = album.ArtworkId;
                        save = true;
                    }

                    if (save) {
                        last_album.Save ();
                    }
                } else {
                    album.ArtistId = artist.DbId;
                    album.ArtistName = artist.Name;
                    album.ArtistNameSort = artist.NameSort;
                    album.Save ();
                    last_album = album;
                }
            }

            last_title = album.Title;
            last_artist_id = artist.DbId;
            return last_album;
        }
コード例 #4
0
        public static DatabaseAlbumInfo FindOrCreate(DatabaseArtistInfo artist, DatabaseAlbumInfo album)
        {
            if (album.Title == last_title && artist.DbId == last_artist_id && last_album != null)
            {
                return(last_album);
            }

            if (String.IsNullOrEmpty(album.Title) || album.Title.Trim() == String.Empty)
            {
                album.Title = null;
            }

            using (IDataReader reader = FindExistingArtists(artist.DbId, album.Title)) {
                if (reader.Read())
                {
                    bool save = false;
                    last_album = provider.Load(reader);

                    // If the artist name has changed since last time (but it's the same artist) then update our copy of the ArtistName
                    if (last_album.ArtistName != artist.Name)
                    {
                        last_album.ArtistName = artist.Name;
                        save = true;
                    }

                    // Ditto artist sort name
                    if (last_album.ArtistNameSort != artist.NameSort)
                    {
                        last_album.ArtistNameSort = artist.NameSort;
                        save = true;
                    }

                    // And album sort name
                    if (last_album.TitleSort != album.TitleSort)
                    {
                        last_album.TitleSort = album.TitleSort;
                        save = true;
                    }

                    // If the album IsCompilation status has changed, update the saved album info
                    if (last_album.IsCompilation != album.IsCompilation)
                    {
                        last_album.IsCompilation = album.IsCompilation;
                        save = true;
                    }

                    // If the album MusicBrainzId has changed, but is not null
                    if (last_album.MusicBrainzId != album.MusicBrainzId && !String.IsNullOrEmpty(album.MusicBrainzId))
                    {
                        last_album.MusicBrainzId = album.MusicBrainzId;
                        save = true;
                    }

                    // If the ArtworkId has changed, update the db
                    if (last_album.ArtworkId != album.ArtworkId)
                    {
                        last_album.ArtworkId = album.ArtworkId;
                        save = true;
                    }

                    if (save)
                    {
                        last_album.Save();
                    }
                }
                else
                {
                    album.ArtistId       = artist.DbId;
                    album.ArtistName     = artist.Name;
                    album.ArtistNameSort = artist.NameSort;
                    album.Save();
                    last_album = album;
                }
            }

            last_title     = album.Title;
            last_artist_id = artist.DbId;
            return(last_album);
        }