Exemple #1
0
        internal static IMatch ParseFilterParameter(string filterParameter, out string error)
        {
            error = null;
            if (!Regex.IsMatch(filterParameter, "Description\\s+-like\\s+", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant))
            {
                error = Strings.InvalidRuleSearchFilterMissingElements;
                return(null);
            }
            Regex regex = new Regex(string.Format("Description\\s+-like\\s+(\"|')(?<{0}>.*)(\"|')", "theFilter"), RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
            Match match = regex.Match(filterParameter);

            if (match.Groups["theFilter"] != null)
            {
                string text = regex.Match(filterParameter).Groups["theFilter"].Value.Trim();
                if (string.IsNullOrEmpty(text))
                {
                    error = Strings.InvalidRuleSearchFilterEmpty;
                    return(null);
                }
                MatchFactory matchFactory = new MatchFactory();
                try
                {
                    return(matchFactory.CreateRegex(GetTransportRule.FilterStringToRegex(text), false, false));
                }
                catch (ArgumentException ex)
                {
                    error = (string.IsNullOrWhiteSpace(ex.Message) ? "Unknown Error" : ex.Message);
                    return(null);
                }
            }
            error = Strings.InvalidRuleSearchFilterEmpty;
            return(null);
        }