public void SetFilter(LogViewer.LogColumnType column, string pattern) { if (string.IsNullOrEmpty(pattern)) { m_Filters[column] = s_MatchAllFilter; return; } var isNegated = pattern.StartsWith(NegationPrefix) && pattern.Length > NegationPrefix.Length; var regexPattern = pattern; if (isNegated) { regexPattern = pattern.Substring(NegationPrefix.Length); } var access = MakeLineAccess(column); var regex = new Regex(regexPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase); var filter = new ColumnFilter(pattern, l => { var isMatch = regex.IsMatch(access(l) ?? string.Empty); return(isNegated ? !isMatch : isMatch); }); m_Filters[column] = filter; }
static Func <LogListViewItem, string> MakeLineAccess(LogViewer.LogColumnType column) { switch (column) { case LogViewer.LogColumnType.LineNr: return(l => l.LineNr.ToString()); case LogViewer.LogColumnType.Filename: return(l => l.Filename); case LogViewer.LogColumnType.ThreadId: return(l => l.ThreadId); case LogViewer.LogColumnType.Instance: return(l => l.Instance); case LogViewer.LogColumnType.Time: return(l => l.Time); case LogViewer.LogColumnType.Level: return(l => l.Level); case LogViewer.LogColumnType.Message: return(l => l.Message); default: throw new ArgumentOutOfRangeException(nameof(column), column, null); } }
public bool TrySetFilter(LogViewer.LogColumnType column, string pattern) { try { SetFilter(column, pattern); return(true); } catch (Exception) { return(false); } }
public Func <LogListViewItem, bool> GetMatcher(LogViewer.LogColumnType column) => m_Filters[column].Matches;
public string CurrentFilterString(LogViewer.LogColumnType column) => m_Filters[column].FilterString;
public void ResetColumnFilter(LogViewer.LogColumnType column) => m_Filters[column] = s_MatchAllFilter;