private static IEnumerable <string> GetInvalidRegexes(MicrosoftClassificationEngine classificationEngine, RulePackageLoader rulePackageLoader, XDocument rulePackXDoc)
 {
     foreach (KeyValuePair <string, string> regexProcessor in XmlProcessingUtils.GetRegexesInRulePackage(rulePackXDoc))
     {
         string value = ClassificationEngineValidator.regexTestTemplate.Value;
         KeyValuePair <string, string> keyValuePair = regexProcessor;
         string rulePackage = string.Format(value, keyValuePair.Value);
         RULE_PACKAGE_DETAILS rule_PACKAGE_DETAILS = default(RULE_PACKAGE_DETAILS);
         rule_PACKAGE_DETAILS.RulePackageSetID = "not-used-here";
         KeyValuePair <string, string> keyValuePair2 = regexProcessor;
         rule_PACKAGE_DETAILS.RulePackageID = keyValuePair2.Key;
         rule_PACKAGE_DETAILS.RuleIDs       = null;
         RULE_PACKAGE_DETAILS rulePackageDetails = rule_PACKAGE_DETAILS;
         rulePackageLoader.SetRulePackage(rulePackageDetails.RulePackageID, rulePackage);
         string badRegex = null;
         try
         {
             RULE_PACKAGE_DETAILS rule_PACKAGE_DETAILS2 = rulePackageDetails;
             classificationEngine.GetClassificationDefinitions(ref rule_PACKAGE_DETAILS2);
         }
         catch (COMException ex)
         {
             if (ex.ErrorCode == -2147220978)
             {
                 KeyValuePair <string, string> keyValuePair3 = regexProcessor;
                 badRegex = keyValuePair3.Key;
             }
         }
         if (badRegex != null)
         {
             yield return(badRegex);
         }
     }
     yield break;
 }
Beispiel #2
0
 private static void ValidateRegexProcessorsPerformance(XDocument rulePackXDocument, DataClassificationConfig dataClassificationConfig)
 {
     ExAssert.RetailAssert(dataClassificationConfig != null, "Must specify DataClassificationConfig instance when calling ValidateRegexProcessorsPerformance");
     foreach (KeyValuePair <string, string> keyValuePair in XmlProcessingUtils.GetRegexesInRulePackage(rulePackXDocument))
     {
         try
         {
             if (keyValuePair.Value.Length > dataClassificationConfig.RegExLength)
             {
                 LocalizedString localizedString = Strings.ClassificationRuleCollectionPatternTooLong(dataClassificationConfig.RegExLength);
                 throw new ValidationArgumentException(localizedString, null);
             }
             if (dataClassificationConfig.RegExGrammarLimit)
             {
                 Pattern.ValidatePatternDoesNotBeginOrEndWithWildcards(keyValuePair.Value);
                 Pattern.ValidatePatternDoesNotContainGroupsOrAssertionsWithWildcards(keyValuePair.Value);
                 Pattern.ValidatePatternDoesNotContainMultiMatchOnGroupsOrAssertions(keyValuePair.Value);
                 Pattern.ValidatePatternDoesNotHaveSequentialIdenticalMultiMatches(keyValuePair.Value);
                 Pattern.ValidatePatternDoesNotContainEmptyAlternations(keyValuePair.Value);
             }
         }
         catch (ValidationArgumentException ex)
         {
             LocalizedString message = Strings.ClassificationRuleCollectionRegexPerformanceValidationFailure(keyValuePair.Key, ex.Message);
             throw new ClassificationRuleCollectionRegexValidationException(message, ex);
         }
     }
 }