Exemplo n.º 1
0
        private void UpdateClassifiers()
        {
            var settings = Settings.Load();
            var patterns = settings.Patterns ?? new RegExClassification[0];

            var classifiers = patterns.Select(
                pattern => new
            {
                classificationType = pattern.ClassificationType.ToString(),
                test = RegExClassification.RegExFactory(pattern)
            })
                              .Select(temp => new Classifier
            {
                Type = temp.classificationType,
                Test = text => temp.test.IsMatch(text)
            })
                              .ToList();

            classifiers.Add(new Classifier
            {
                Type = ClassificationTypeDefinitions.BuildText,
                Test = t => true
            });

            _classifiers = classifiers;
        }
 public static Regex RegExFactory(RegExClassification pattern)
 {
     return(new Regex(
                pattern.RegExPattern,
                pattern.IgnoreCase ? RegexOptions.IgnoreCase : RegexOptions.None,
                TimeSpan.FromMilliseconds(250)));
 }
Exemplo n.º 3
0
 public static Regex RegExFactory(RegExClassification pattern)
 {
     return new Regex(
         pattern.RegExPattern, 
         pattern.IgnoreCase ? RegexOptions.IgnoreCase : RegexOptions.None, 
         TimeSpan.FromMilliseconds(250));
 }
 public void ToStringFormat()
 {
     var rc = new RegExClassification
     {
         RegExPattern = "/d",
         ClassificationType = ClassificationTypes.BuildText,
         IgnoreCase = true
     };
     rc.ToString().Should().Be("\"/d\",BuildText,True");
 }
Exemplo n.º 5
0
        private void UpdateClassifiers()
        {
            var settings = Settings.Load();
            var patterns = settings.Patterns ?? Array.Empty <RegExClassification>();

            _classifiers = patterns.Select(
                pattern => new Classifier
            {
                Type = pattern.ClassificationType.ToString(),
                Test = RegExClassification.RegExFactory(pattern).IsMatch
            })
                           .Append(new Classifier
            {
                Type = ClassificationTypeDefinitions.BuildText,
                Test = t => true
            })
                           .ToList();
        }