Exemplo n.º 1
0
        /// <summary>Gets the subset audio file IDs.</summary>
        /// <param name="subsetID">The subset identifier.</param>
        /// <param name="minDuration">The minimum duration.</param>
        /// <param name="maxDuration">The maximum duration.</param>
        /// <returns></returns>
        public IList <long> GetSubsetAudioFileIDs(long subsetID, TimeSpan minDuration, TimeSpan maxDuration)
        {
            Search search = Search.None;

            #region whitelist
            {
                var whitelist = SubsetFilters.GetStructs(Search.FieldEquals(nameof(MDBSubsetFilter.SubsetID), subsetID) & Search.FieldEquals(nameof(MDBSubsetFilter.Mode), MDBSubsetFilterMode.Whitelist));
                foreach (MDBSubsetFilter filter in whitelist)
                {
                    switch (filter.Type)
                    {
                    case MDBSubsetFilterType.Album:
                        foreach (long albumID in Albums.FindRows(Search.FieldLike(nameof(MDBAlbum.Name), MDBSearch.Text(filter.Text))))
                        {
                            search |= Search.FieldEquals(nameof(MDBAudioFile.AlbumID), albumID);
                        }
                        break;

                    case MDBSubsetFilterType.Artist:
                        foreach (long artistID in Artists.FindRows(Search.FieldLike(nameof(MDBArtist.Name), MDBSearch.Text(filter.Text))))
                        {
                            search |= Search.FieldEquals(nameof(MDBAudioFile.SongArtistID), artistID);
                        }
                        break;

                    case MDBSubsetFilterType.Category:
                    {
                        var ids = Categories.FindRows(nameof(MDBCategory.Name), MDBSearch.Text(filter.Text));
                        if (ids.Count != 1)
                        {
                            this.LogError(string.Format("Error at SubsetFilter {0}", filter));
                        }
                        foreach (long id in ids)
                        {
                            search |= Search.FieldEquals(nameof(MDBAudioFile.CategoryID), id);
                        }
                        break;
                    }

                    case MDBSubsetFilterType.Tag:
                    {
                        search |= Search.FieldLike(nameof(MDBAudioFile.Tags), MDBSearch.Text(filter.Text));
                        break;
                    }

                    case MDBSubsetFilterType.Genre:
                    {
                        search |= Search.FieldLike(nameof(MDBAudioFile.Genres), MDBSearch.Text(filter.Text));
                        break;
                    }

                    case MDBSubsetFilterType.Title:
                    {
                        search |= Search.FieldLike("Title", MDBSearch.Text(filter.Text));
                        break;
                    }

                    default: this.LogError(string.Format("Unknown SubsetType at SubsetFilter {0}", filter)); break;
                    }
                }
            }
            #endregion
            #region blacklist
            {
                var blacklist = SubsetFilters.GetStructs(Search.FieldEquals(nameof(MDBSubsetFilter.SubsetID), subsetID) & Search.FieldEquals(nameof(MDBSubsetFilter.Mode), MDBSubsetFilterMode.Blacklist));
                foreach (MDBSubsetFilter filter in blacklist)
                {
                    switch (filter.Type)
                    {
                    case MDBSubsetFilterType.Album:
                        foreach (long albumID in Albums.FindRows(Search.FieldLike(nameof(MDBAlbum.Name), MDBSearch.Text(filter.Text))))
                        {
                            search &= !Search.FieldEquals(nameof(MDBAudioFile.AlbumID), albumID);
                        }
                        break;

                    case MDBSubsetFilterType.Artist:
                        foreach (long artistID in Artists.FindRows(Search.FieldLike(nameof(MDBArtist.Name), MDBSearch.Text(filter.Text))))
                        {
                            search &= !Search.FieldEquals(nameof(MDBAudioFile.SongArtistID), artistID);
                        }
                        break;

                    case MDBSubsetFilterType.Category:
                    {
                        var ids = Categories.FindRows(nameof(MDBCategory.Name), MDBSearch.Text(filter.Text));
                        if (ids.Count != 1)
                        {
                            this.LogError(string.Format("Error at SubsetFilter {0}", filter));
                        }
                        foreach (long id in ids)
                        {
                            search &= !Search.FieldEquals(nameof(MDBAudioFile.CategoryID), id);
                        }
                        break;
                    }

                    case MDBSubsetFilterType.Tag:
                    {
                        search &= !Search.FieldLike(nameof(MDBAudioFile.Tags), MDBSearch.Text(filter.Text));
                        break;
                    }

                    case MDBSubsetFilterType.Genre:
                    {
                        search &= !Search.FieldLike(nameof(MDBAudioFile.Genres), MDBSearch.Text(filter.Text));
                        break;
                    }

                    case MDBSubsetFilterType.Title:
                    {
                        search &= !Search.FieldLike("Title", MDBSearch.Text(filter.Text));
                        break;
                    }

                    default: this.LogError(string.Format("Unknown SubsetType at SubsetFilter {0}", filter)); break;
                    }
                }
            }
            #endregion
            if (minDuration > TimeSpan.Zero)
            {
                search &= Search.FieldGreaterOrEqual(nameof(MDBAudioFile.Duration), minDuration);
            }

            if (maxDuration > minDuration)
            {
                search &= Search.FieldSmallerOrEqual(nameof(MDBAudioFile.Duration), maxDuration);
            }

            return(AudioFiles.FindRows(search));
        }