public static IQueryable <Album> WhereMatchFilter(this IQueryable <Album> query, AdvancedSearchFilter filter) { switch (filter.FilterType) { case AdvancedFilterType.ArtistType: { var param = EnumVal <ArtistType> .Parse(filter.Param); return(WhereArtistHasType(query, param)); } case AdvancedFilterType.NoCoverPicture: { return(query.Where(a => a.CoverPictureMime == null || a.CoverPictureMime == string.Empty)); } case AdvancedFilterType.HasStoreLink: { return(query.WhereHasLinkWithCategory(WebLinkCategory.Commercial)); } case AdvancedFilterType.WebLink: { return(query.WhereHasLink <Album, AlbumWebLink>(filter.Param)); } } return(query); }
public static IQueryable <T> WhereMatchFilter <T>(this IQueryable <T> query, AdvancedSearchFilter filter) where T : ISongLink { if (filter == null) { return(query); } switch (filter.FilterType) { case AdvancedFilterType.ArtistType: { var param = EnumVal <ArtistType> .Parse(filter.Param); return(WhereSongHasArtistWithType(query, param)); } case AdvancedFilterType.HasMultipleVoicebanks: { return(query.Where(s => s.Song.AllArtists.Count(a => !a.IsSupport && ArtistHelper.VoiceSynthesizerTypes.Contains(a.Artist.ArtistType)) > 1)); } case AdvancedFilterType.HasPublishDate: { return(query.WhereSongHasPublishDate(!filter.Negate)); } case AdvancedFilterType.Lyrics: { var any = filter.Param == AdvancedSearchFilter.Any; var languageCodes = !any ? (filter.Param ?? string.Empty).Split(',') : null; return(WhereSongHasLyrics(query, languageCodes, any)); } } return(query); }
public static IQueryable <T> WhereAlbumMatchFilter <T>(this IQueryable <T> query, AdvancedSearchFilter?filter) where T : IAlbumLink { if (filter == null) { return(query); } switch (filter.FilterType) { case AdvancedFilterType.ArtistType: { var param = EnumVal <ArtistType> .Parse(filter.Param); return(WhereAlbumHasArtistWithType(query, param)); } case AdvancedFilterType.NoCoverPicture: { return(query.Where(a => a.Album.CoverPictureMime == null || a.Album.CoverPictureMime == string.Empty)); } case AdvancedFilterType.HasStoreLink: { return(query.WhereAlbumHasLinkWithCategory(WebLinkCategory.Commercial)); } case AdvancedFilterType.HasTracks: { return(query.Where(a => filter.Negate != a.Album.AllSongs.Any(s => s.Song == null || !s.Song.Deleted))); } } return(query); }
/// <summary> /// Gets a list of individual values from bitarray. /// <see cref="ArtistTypes.Unknown"/> is skipped. /// </summary> /// <param name="flags">Bitarray of artist types.</param> /// <returns>Individual artist types.</returns> public static ArtistType[] GetArtistTypesFromFlags(ArtistTypes flags) { return(EnumVal <ArtistTypes> .GetIndividualValues(flags) .Where(v => v != ArtistTypes.Unknown) .Select(a => EnumVal <ArtistType> .Parse(a.ToString())) .ToArray()); }
public AuditLogEntryContract[] GetAuditLog(string filter, int start, int maxEntries, int timeCutoffDays, string userName, string[] excludeUsers, bool onlyNewUsers, AuditLogUserGroupFilter filterByGroup = AuditLogUserGroupFilter.Nothing) { return(HandleTransaction(session => { var q = session.Query <AuditLogEntry>(); if (timeCutoffDays > 0) { var cutoff = DateTime.Now - TimeSpan.FromDays(timeCutoffDays); q = q.Where(e => e.Time > cutoff); } if (!string.IsNullOrWhiteSpace(filter)) { q = q.Where(e => e.Action.Contains(filter)); } if (!string.IsNullOrWhiteSpace(userName)) { q = q.Where(e => e.AgentName == userName || e.User.Options.LastLoginAddress == userName); } if (excludeUsers.Any()) { var usr = session.Query <User>().Where(u => excludeUsers.Contains(u.Name)).Select(u => u.Id).Distinct().ToArray(); q = q.Where(e => !usr.Contains(e.User.Id)); } if (onlyNewUsers) { var newUserDate = DateTime.Now - TimeSpan.FromDays(7); q = q.Where(e => e.User.CreateDate >= newUserDate); } if (filterByGroup != AuditLogUserGroupFilter.Nothing && filterByGroup != AuditLogUserGroupFilter.NoFilter) { var userGroup = EnumVal <UserGroupId> .Parse(filterByGroup.ToString()); q = q.Where(e => e.User != null && e.User.GroupId == userGroup); } if (filterByGroup == AuditLogUserGroupFilter.Nothing) { q = q.Where(e => e.User == null); } var entries = q .OrderByDescending(e => e.Time) .Skip(start) .Take(maxEntries) .ToArray() .Select(e => new AuditLogEntryContract(e)) .ToArray(); return entries; }, IsolationLevel.ReadUncommitted)); }
public static string EntrySubTypeName(EntryTypeAndSubType fullEntryType) { return(fullEntryType.EntryType switch { EntryType.Album => DiscTypeName(EnumVal <DiscType> .Parse(fullEntryType.SubType)), EntryType.Artist => ArtistTypeName(EnumVal <ArtistType> .Parse(fullEntryType.SubType)), EntryType.ReleaseEvent => ReleaseEventCategoryNames[EnumVal <EventCategory> .Parse(fullEntryType.SubType)], EntryType.Song => SongTypeNames[EnumVal <SongType> .Parse(fullEntryType.SubType)], _ => string.Empty, });
public static IQueryable <Song> WhereMatchFilter(this IQueryable <Song> query, AdvancedSearchFilter filter) { if (filter == null) { return(query); } switch (filter.FilterType) { case AdvancedFilterType.ArtistType: { var param = EnumVal <ArtistType> .Parse(filter.Param); return(WhereArtistHasType(query, param)); } case AdvancedFilterType.HasAlbum: return(filter.Negate ? query.Where(s => !s.AllAlbums.Any()) : query.Where(s => s.AllAlbums.Any())); case AdvancedFilterType.HasMultipleVoicebanks: { return(query.Where(s => s.AllArtists.Count(a => !a.IsSupport && ArtistHelper.VoiceSynthesizerTypes.Contains(a.Artist.ArtistType)) > 1)); } case AdvancedFilterType.HasPublishDate: { return(query.WhereHasPublishDate(!filter.Negate)); } case AdvancedFilterType.Lyrics: { var any = filter.Param == AdvancedSearchFilter.Any; var languageCodes = !any ? (filter.Param ?? string.Empty).Split(',') : null; return(WhereHasLyrics(query, languageCodes, any)); } case AdvancedFilterType.LyricsContent: { return(query.WhereHasLyricsContent(filter.Param)); } case AdvancedFilterType.HasOriginalMedia: { return(query.Where(s => filter.Negate != s.PVs.PVs.Any(pv => !pv.Disabled && pv.PVType == PVType.Original))); } case AdvancedFilterType.HasMedia: { return(query.Where(s => filter.Negate != s.PVs.PVs.Any())); } case AdvancedFilterType.WebLink: { return(query.WhereHasLink <Song, SongWebLink>(filter.Param)); } } return(query); }
public static EntryTypeAndTagCollection <TSubType> Create( EntryType entryType, IReadOnlyCollection <TSubType> subTypes, IReadOnlyCollection <int> tagIds, IDatabaseContext ctx, bool allowAllTags = false) { TSubType[] allTypes; int[] songTypeTagIds; int[] allTagIds; if (tagIds.Any()) { var songTypesAndTagsFromTags = ctx.Query <EntryTypeToTagMapping>() .WhereEntryTypeIs(entryType) .WhereHasSubType() .Where(etm => tagIds.Contains(etm.Tag.Id)) .Select(etm => new { TagId = etm.Tag.Id, etm.SubType }) .ToArray(); songTypeTagIds = songTypesAndTagsFromTags.Select(etm => etm.TagId).ToArray(); var songTypesFromTags = songTypesAndTagsFromTags.Select(etm => EnumVal <TSubType> .Parse(etm.SubType)); allTypes = subTypes.Union(songTypesFromTags).ToArray(); } else { allTypes = subTypes.ToArray(); songTypeTagIds = new int[0]; } if (subTypes.Any()) { var tagsFromSongTypes = ctx.Query <EntryTypeToTagMapping>() .WhereEntryTypeIs(entryType, subTypes) .Select(etm => etm.Tag.Id) .ToArray(); allTagIds = songTypeTagIds.Union(tagsFromSongTypes).ToArray(); } else { allTagIds = songTypeTagIds; } if (allowAllTags) { allTagIds = allTagIds.Union(tagIds).ToArray(); } return(new EntryTypeAndTagCollection <TSubType>(allTypes, allTagIds)); }
private bool TryGetLanguagePreferenceFromCookie(ref ContentLanguagePreference languagePreference) { if (HttpContext.Current == null) { return(false); } var cookie = HttpContext.Current.Request.Cookies.Get("languagePreference"); if (cookie == null || string.IsNullOrEmpty(cookie.Value)) { return(false); } languagePreference = EnumVal <ContentLanguagePreference> .Parse(cookie.Value); return(true); }
public ViewAuditLogModel() { GroupId = AuditLogUserGroupFilter.NoFilter; UserGroups = new[] { new KeyValuePair <AuditLogUserGroupFilter, string>(AuditLogUserGroupFilter.NoFilter, "No group filter") }.Concat(Translate.UserGroups.Values.Select(u => new KeyValuePair <AuditLogUserGroupFilter, string>(EnumVal <AuditLogUserGroupFilter> .Parse(u.ToString()), Translate.UserGroups[u]))) .ToArray(); }