コード例 #1
0
        public void GetAlbum(WebData webData, long albumID)
        {
            var result = RPCAlbum.Load(mdb, mdb.Albums.TryGetStruct(albumID));

            webData.Result.AddMessage(webData.Method, "Retrieved Album.");
            webData.Result.AddStruct(result);
        }
コード例 #2
0
        public void GetAlbumsWithErrorsList(WebData webData)
        {
            var audioFiles  = mdb.AudioFiles.GetStructs(Search.FieldNotEquals(nameof(MDBAudioFile.MetaErrors), 0));
            var albumErrors = new Dictionary <long, MDBMetaErrors>();

            foreach (var audioFile in audioFiles)
            {
                albumErrors.TryGetValue(audioFile.AlbumID, out MDBMetaErrors errors);
                errors |= audioFile.MetaErrors;
                albumErrors[audioFile.AlbumID] = errors;
            }
            var albums = mdb.Albums.GetStructs(
                Search.FieldIn(nameof(MDBAlbum.ID), albumErrors.Keys) |
                Search.FieldEquals(nameof(MDBAlbum.MusicBrainzAlbumGuid), null) |
                Search.FieldEquals(nameof(MDBAlbum.MusicBrainzReleaseGroupGuid), null)
                );

            foreach (var album in albums)
            {
                albumErrors.TryGetValue(album.ID, out MDBMetaErrors errors);
                if (album.MusicBrainzAlbumGuid == null)
                {
                    errors |= MDBMetaErrors.MusicBrainzAlbum;
                }
                if (album.MusicBrainzReleaseGroupGuid == null)
                {
                    errors |= MDBMetaErrors.MusicBrainzReleaseGroup;
                }
                albumErrors[album.ID] = errors;
            }
            var artists = mdb.Artists.GetStructs(albums.Select(a => a.ArtistID));

            webData.Result.AddMessage(webData.Method, "Retrieved albums with errors datasets...");
            webData.Result.AddStructs(albums.Select(a => RPCAlbum.Load(mdb, a)));
            webData.Result.AddStructs(artists.Select(a => RPCArtist.Load(mdb, a)));
        }
コード例 #3
0
        public void SearchAlbums(WebData webData, long artistID = 0, string filter = null, int page = 0, long categoryID = 0, long genreID = 0, long tagID = 0, string genre = null, string tag = null)
        {
            ICollection <long> albumIDs = null;

            //select audio files
            if (genreID != 0 || categoryID != 0 || tagID != 0 || genre != null || tag != null)
            {
                Search s = Search.None;
                if (genreID != 0)
                {
                    s &= Search.FieldEquals(nameof(MDBAudioFile.GenreID), genreID);
                }
                if (tagID != 0)
                {
                    s &= Search.FieldEquals(nameof(MDBAudioFile.TagID), tagID);
                }
                if (genre != null)
                {
                    s &= Search.FieldLike(nameof(MDBAudioFile.Genres), MDBSearch.Text("%" + genre + "%"));
                }
                if (tag != null)
                {
                    s &= Search.FieldLike(nameof(MDBAudioFile.Tags), MDBSearch.Text("%" + tag + "%"));
                }
                if (categoryID > 0)
                {
                    s &= GetCategorySearch(categoryID);
                }
                int fieldIndex = mdb.AudioFiles.Layout.GetFieldIndex(nameof(MDBAudioFile.AlbumID));
                albumIDs = mdb.AudioFiles.GetRows(s).Select(r => (long)r.GetValue(fieldIndex)).ToList();
            }

            //select artists
            IList <MDBAlbum> albums;
            long             rowCount;
            {
                Search search = Search.None;
                if (filter != null)
                {
                    search &= Search.FieldLike(nameof(MDBAlbum.Name), MDBSearch.Text("%" + filter + "%"));
                }
                if (albumIDs != null)
                {
                    search &= Search.FieldIn(nameof(MDBAlbum.ID), albumIDs);
                }
                if (artistID != 0)
                {
                    search &= Search.FieldEquals(nameof(MDBAlbum.ArtistID), artistID);
                }
                if (search.Mode == SearchMode.None)
                {
                    rowCount = mdb.Albums.RowCount;
                }
                else
                {
                    rowCount = mdb.Albums.Count(search);
                }
                albums = mdb.Albums.GetStructs(search, ResultOption.SortAscending(nameof(MDBAlbum.Name)) + ResultOption.Offset(page * RowsPerPage) + ResultOption.Limit(RowsPerPage));
            }

            //join
            var result = albums.Select(i => RPCAlbum.Load(mdb, i));

            //return
            webData.Result.AddMessage(webData.Method, "Retrieved Albums.");
            AddPagination(webData, page, rowCount);
            webData.Result.AddStructs(result);
        }