internal static bool OptimizeRulePackXDoc(XDocument rulePackXDoc, DataClassificationConfig dataClassificationConfig)
        {
            ArgumentValidator.ThrowIfNull("rulePackXDoc", rulePackXDoc);
            bool     result   = false;
            XElement xelement = rulePackXDoc.Descendants(XmlProcessingUtils.GetMceNsQualifiedNodeName("Rules")).FirstOrDefault <XElement>();

            if (xelement == null)
            {
                throw new ClassificationRuleCollectionInvalidObjectException(Strings.ClassificationRuleCollectionInvalidObject);
            }
            List <XElement> list = (from versionElement in xelement.Descendants(XmlProcessingUtils.GetMceNsQualifiedNodeName("Version"))
                                    where versionElement.IsEmpty
                                    select versionElement).ToList <XElement>();

            foreach (XElement xelement2 in list)
            {
                xelement2.Remove();
                result = true;
            }
            List <string> list2 = (from versionedTextProcessorReference in TextProcessorUtils.GetTextProcessorReferences(rulePackXDoc.Root)
                                   select versionedTextProcessorReference.Key).Distinct(ClassificationDefinitionConstants.TextProcessorIdComparer).ToList <string>();
            List <XElement> list3 = XmlProcessingUtils.GetFingerprintProcessorsInRulePackage(rulePackXDoc).ToList <XElement>();

            foreach (XElement xelement3 in list3)
            {
                XAttribute xattribute = xelement3.Attribute("id");
                string     item       = (xattribute == null) ? string.Empty : xattribute.Value;
                if (list2.Contains(item))
                {
                    if (dataClassificationConfig != null)
                    {
                        XAttribute xattribute2 = xelement3.Attribute("threshold");
                        if (xattribute2 != null && !dataClassificationConfig.FingerprintThreshold.ToString().Equals(xattribute2.Value, StringComparison.Ordinal))
                        {
                            xattribute2.Value = dataClassificationConfig.FingerprintThreshold.ToString();
                            result            = true;
                        }
                    }
                }
                else
                {
                    xelement3.Remove();
                    result = true;
                }
            }
            return(result);
        }
Esempio n. 2
0
        internal static RuleComplexityData Create(XElement ruleElement, Dictionary <TextProcessorType, TextProcessorGrouping> customTextProcessorGroups, Dictionary <string, int> customKeywordProcessorsTermsCount, Dictionary <TextProcessorType, TextProcessorGrouping> oobTextProcessorGroups = null)
        {
            if (ruleElement == null)
            {
                throw new ArgumentNullException("ruleElement");
            }
            if (customTextProcessorGroups == null)
            {
                throw new ArgumentNullException("customTextProcessorGroups");
            }
            if (customKeywordProcessorsTermsCount == null)
            {
                throw new ArgumentNullException("customKeywordProcessorsTermsCount");
            }
            oobTextProcessorGroups = (oobTextProcessorGroups ?? TextProcessorUtils.OobProcessorsGroupedByType);
            List <string> list = (from versionedTextProcessorReference in TextProcessorUtils.GetTextProcessorReferences(ruleElement)
                                  select versionedTextProcessorReference.Key).Distinct(ClassificationDefinitionConstants.TextProcessorIdComparer).ToList <string>();
            int num  = 0;
            int num2 = 0;
            int num3 = 0;

            foreach (string textProcessorRef in list)
            {
                if (RuleComplexityData.IsRegexProcessorReference(textProcessorRef, oobTextProcessorGroups, customTextProcessorGroups))
                {
                    num++;
                }
                else if (RuleComplexityData.IsFunctionProcessorReference(textProcessorRef, oobTextProcessorGroups))
                {
                    num3++;
                }
                else
                {
                    num2 += RuleComplexityData.GetTermsFromCustomKeywordProcessorCount(textProcessorRef, customTextProcessorGroups, customKeywordProcessorsTermsCount);
                }
            }
            RuleComplexityData ruleComplexityData = new RuleComplexityData
            {
                DistinctRegexProcessorReferencesCount          = num,
                TermsFromCustomKeywordProcessorReferencesCount = num2,
                DistinctFunctionProcessorReferencesCount       = num3
            };

            ruleComplexityData.ProcessAnyBlocksComplexityData(ruleElement);
            return(ruleComplexityData);
        }
Esempio n. 3
0
        private IEnumerable <KeyValuePair <string, RuleComplexityData> > GetRulePackComplexityData(XDocument rulePackXDocument)
        {
            ExAssert.RetailAssert(rulePackXDocument != null, "The rule pack document instance passed to GetRulePackComplexityData cannot be null!");
            Dictionary <TextProcessorType, TextProcessorGrouping> customTextProcessorGroups = TextProcessorUtils.GetRulePackScopedTextProcessorsGroupedByType(rulePackXDocument).ToDictionary((TextProcessorGrouping textProcessorGroup) => textProcessorGroup.Key);
            Dictionary <string, int> customKeywordProcessorsTermsCount = ComplexityValidator.GetKeywordProcessorTermsCount(rulePackXDocument);
            IEnumerable <XElement>   source = from rulePackElement in rulePackXDocument.Descendants()
                                              where ClassificationDefinitionConstants.MceRuleElementNames.Contains(rulePackElement.Name.LocalName)
                                              select rulePackElement;

            return(from ruleElement in source.AsParallel <XElement>().AsOrdered <XElement>()
                   select new KeyValuePair <string, RuleComplexityData>(ruleElement.Attribute("id").Value, RuleComplexityData.Create(ruleElement, customTextProcessorGroups, customKeywordProcessorsTermsCount, this.cannedOobTextProcessorIdsGroupedByType)));
        }
 internal static IEnumerable <KeyValuePair <string, ExchangeBuild> > GetTextProcessorReferences(XElement rulePackElement)
 {
     return(TextProcessorUtils.GetTextProcessorReferences(rulePackElement, ClassificationDefinitionConstants.MceMatchElementNames));
 }
 internal static IEnumerable <TextProcessorGrouping> GetTextProcessorsGroupedByType(XDocument rulePackXDoc, ISet <string> textProcessorElementNames)
 {
     ExAssert.RetailAssert(rulePackXDoc != null, "The rule pack XDocument instance passed to GetTextProcessorIdsGroupedByType cannot be null!");
     ExAssert.RetailAssert(textProcessorElementNames != null, "Must specify the text processor element names when calling GetTextProcessorIdsGroupedByType");
     return(from rulePackElement in rulePackXDoc.Descendants().AsParallel <XElement>()
            let rulePackElementName = rulePackElement.Name.LocalName
                                      where textProcessorElementNames.Contains(rulePackElementName)
                                      let textProcessorType = TextProcessorUtils.MceConfigManagerBase.ParseTextProcessorType(rulePackElementName)
                                                              let versionedTextProcessor = new KeyValuePair <string, ExchangeBuild>(rulePackElement.Attribute("id").Value, TextProcessorUtils.GetTextProcessorVersion(textProcessorType, rulePackElement))
                                                                                           group versionedTextProcessor by textProcessorType into textProcessorGrouping
                                                                                           select new TextProcessorGrouping(textProcessorGrouping, null));
 }
 private static Dictionary <TextProcessorType, TextProcessorGrouping> GetDiskOobProcessorsGroupedByType()
 {
     return(TextProcessorUtils.GetOnDiskMceConfigData <Dictionary <TextProcessorType, TextProcessorGrouping> >((TextProcessorUtils.MceConfigManagerBase diskMceConfigManager) => diskMceConfigManager.OobTextProcessorGrouping));
 }
Esempio n. 7
0
        private void ValidateProcessorIdAndMatchReferences(XDocument rulePackXDocument)
        {
            ExAssert.RetailAssert(rulePackXDocument != null, "Extra rule package validation must take place after XML schema validation passed!");
            IDictionary <string, ExchangeBuild> textProcessorsFromTextProcessorGrouping = TextProcessorUtils.GetTextProcessorsFromTextProcessorGrouping(this.cannedOobTextProcessorsGroupedByType, null);
            ICollection <string> keys = textProcessorsFromTextProcessorGrouping.Keys;
            Dictionary <TextProcessorType, TextProcessorGrouping> textProcessorsGroupings = TextProcessorUtils.GetRulePackScopedTextProcessorsGroupedByType(rulePackXDocument).ToDictionary((TextProcessorGrouping textProcessorGroup) => textProcessorGroup.Key);
            IDictionary <string, ExchangeBuild> textProcessorsFromTextProcessorGrouping2  = TextProcessorUtils.GetTextProcessorsFromTextProcessorGrouping(textProcessorsGroupings, null);
            ICollection <string> keys2 = textProcessorsFromTextProcessorGrouping2.Keys;
            List <string>        list  = keys.AsParallel <string>().Union(keys2.AsParallel <string>(), ClassificationDefinitionConstants.TextProcessorIdComparer).ToList <string>();

            if (list.Count != keys.Count + keys2.Count)
            {
                List <string>   list2   = keys.AsParallel <string>().Intersect(keys2.AsParallel <string>(), ClassificationDefinitionConstants.TextProcessorIdComparer).ToList <string>();
                LocalizedString message = Strings.ClassificationRuleCollectionReservedProcessorIdViolation(string.Join(Strings.ClassificationRuleCollectionOffendingListSeparator, list2));
                throw ClassificationDefinitionUtils.PopulateExceptionSource <ClassificationRuleCollectionIdentifierValidationException, List <string> >(new ClassificationRuleCollectionIdentifierValidationException(message), list2);
            }
            HashSet <string> hashSet = new HashSet <string>(ClassificationDefinitionConstants.TextProcessorIdComparer);
            IEnumerable <KeyValuePair <string, ExchangeBuild> > textProcessorReferences = TextProcessorUtils.GetTextProcessorReferences(rulePackXDocument.Root);

            foreach (KeyValuePair <string, ExchangeBuild> keyValuePair in textProcessorReferences)
            {
                ExchangeBuild objB;
                if ((!textProcessorsFromTextProcessorGrouping2.TryGetValue(keyValuePair.Key, out objB) && !textProcessorsFromTextProcessorGrouping.TryGetValue(keyValuePair.Key, out objB)) || !(keyValuePair.Value >= objB))
                {
                    hashSet.Add(keyValuePair.Key);
                }
            }
            IDictionary <string, ExchangeBuild> textProcessorsFromTextProcessorGrouping3 = TextProcessorUtils.GetTextProcessorsFromTextProcessorGrouping(this.cannedOobTextProcessorsGroupedByType, (TextProcessorType textProcessorType) => textProcessorType == TextProcessorType.Fingerprint);
            IDictionary <string, ExchangeBuild> textProcessorsFromTextProcessorGrouping4 = TextProcessorUtils.GetTextProcessorsFromTextProcessorGrouping(textProcessorsGroupings, (TextProcessorType textProcessorType) => textProcessorType == TextProcessorType.Fingerprint);
            IEnumerable <KeyValuePair <string, ExchangeBuild> > textProcessorReferences2 = TextProcessorUtils.GetTextProcessorReferences(rulePackXDocument.Root, ClassificationDefinitionConstants.MceIdMatchElementNames);

            foreach (KeyValuePair <string, ExchangeBuild> keyValuePair2 in textProcessorReferences2)
            {
                if (textProcessorsFromTextProcessorGrouping4.ContainsKey(keyValuePair2.Key) || textProcessorsFromTextProcessorGrouping3.ContainsKey(keyValuePair2.Key))
                {
                    hashSet.Add(keyValuePair2.Key);
                }
            }
            if (hashSet.Count > 0)
            {
                LocalizedString message2 = Strings.ClassificationRuleCollectionInvalidProcessorReferenceViolation(string.Join(Strings.ClassificationRuleCollectionOffendingListSeparator, hashSet));
                throw ClassificationDefinitionUtils.PopulateExceptionSource <ClassificationRuleCollectionProcessorReferenceValidationException, HashSet <string> >(new ClassificationRuleCollectionProcessorReferenceValidationException(message2), hashSet);
            }
        }
        internal static MultiValuedProperty <Fingerprint> ReadAllReferredFingerprints(XElement ruleElement)
        {
            ArgumentValidator.ThrowIfNull("ruleElement", ruleElement);
            ArgumentValidator.ThrowIfNull("ruleElement.Document", ruleElement.Document);
            List <string> distinctTextProcessorRefs = (from versionedTextProcessorReference in TextProcessorUtils.GetTextProcessorReferences(ruleElement)
                                                       select versionedTextProcessorReference.Key).Distinct(ClassificationDefinitionConstants.TextProcessorIdComparer).ToList <string>();
            IEnumerable <Fingerprint> value = from fingerprintElement in ruleElement.Document.Descendants(XmlProcessingUtils.GetMceNsQualifiedNodeName("Fingerprint"))
                                              where distinctTextProcessorRefs.Contains(XmlProcessingUtils.GetAttributeValue(fingerprintElement, "id"))
                                              let fingerprint = Fingerprint.FromXElement(fingerprintElement)
                                                                select fingerprint;

            return(new MultiValuedProperty <Fingerprint>(value));
        }