public bool IsMatch(string title, string classname) { if (TitlePattern != null && !TitlePattern.IsMatch(title)) { return(false); } if (ClassPattern != null && !ClassPattern.IsMatch(classname)) { return(false); } return(true); }
/// <summary> /// Wendet die Fiterbedingung an. /// </summary> /// <param name="entries">Eine Liste von Einträgen.</param> /// <returns>Die gefilterte Liste.</returns> public IEnumerable <ProgramGuideEntry> Filter(IEnumerable <ProgramGuideEntry> entries) { // Only use sources available to the target profile var entrySet = entries .Select(entry => new { e = entry, s = VCRProfiles.FindSource(ProfileName, entry.Source) }) .Where(entry => entry.s != null) .Select(entry => new { e = entry.e, s = (Station)entry.s.Source }); // Name of the station - best filter first if (Source != null) { // One source - no more filters entrySet = entrySet.Where(entry => Source.Equals(entry.e.Source)); } else { // Apply source type filter if (SourceType == GuideSourceFilter.Television) { entrySet = entrySet.Where(entry => entry.s.SourceType == SourceTypes.TV); } else if (SourceType == GuideSourceFilter.Radio) { entrySet = entrySet.Where(entry => entry.s.SourceType == SourceTypes.Radio); } // Apply encryption filter if (SourceEncryption == GuideEncryptionFilter.Free) { entrySet = entrySet.Where(entry => !entry.s.IsEncrypted); } else if (SourceEncryption == GuideEncryptionFilter.Encrypted) { entrySet = entrySet.Where(entry => entry.s.IsEncrypted); } } // Start time if (Start.HasValue) { // Later entrySet = entrySet.Where(entry => entry.e.StartTime >= Start.Value); } else { // Current var now = DateTime.UtcNow; // Still active entrySet = entrySet.Where(entry => entry.e.EndTime > now); } // Matcher on content Func <ProgramGuideEntry, bool> matchTitle = null; Func <ProgramGuideEntry, bool> matchContent = null; // Title if (!string.IsNullOrEmpty(TitlePattern)) { var title = TitlePattern.Substring(1); switch (TitlePattern[0]) { case '=': matchTitle = entry => (entry.Name ?? string.Empty).Equals(title, StringComparison.InvariantCultureIgnoreCase); break; case '*': matchTitle = entry => (entry.Name ?? string.Empty).IndexOf(title, StringComparison.InvariantCultureIgnoreCase) >= 0; break; } } // Both descriptions if (!string.IsNullOrEmpty(ContentPattern)) { var content = ContentPattern.Substring(1); switch (ContentPattern[0]) { case '=': matchContent = entry => (entry.Description ?? string.Empty).Equals(content, StringComparison.InvariantCultureIgnoreCase) || (entry.ShortDescription ?? string.Empty).Equals(content, StringComparison.InvariantCultureIgnoreCase); break; case '*': matchContent = entry => ((entry.Description ?? string.Empty).IndexOf(content, StringComparison.InvariantCultureIgnoreCase) >= 0) || ((entry.ShortDescription ?? string.Empty).IndexOf(content, StringComparison.InvariantCultureIgnoreCase) >= 0); break; } } // Apply content filter if (matchTitle != null) { if (matchContent != null) { entrySet = entrySet.Where(entry => matchTitle(entry.e) || matchContent(entry.e)); } else { entrySet = entrySet.Where(entry => matchTitle(entry.e)); } } else if (matchContent != null) { entrySet = entrySet.Where(entry => matchContent(entry.e)); } // Back mapping entries = entrySet.Select(entry => entry.e); // Caller will get it all if (PageSize < 1) { return(entries); } // Copy local var matches = entries.ToList(); // Sort in list to improve overall performance matches.Sort(Comparer); // Adjust extract - report one more if possible to indicate that there is more available return(matches.Skip(PageIndex * PageSize).Take(PageSize + 1)); }