Esempio n. 1
0
        /*++
         *
         *  Routine RegexClassifier::UseRulesAndDefinitions
         *
         * Description:
         *
         *  This routine implements the IFsrmClassifierModuleImplementation interface UseRulesAndDefinitions.
         *  It is called by the pipeline to indicate to the classifier that the following rules apply to it for this run.
         *
         * Arguments:
         *
         *  Rules - The FSRM classification rules that apply to this classifier for this run.
         *  propertyDefinitions - The property definitions affected by the above rules.
         *
         * Return value:
         *
         *  void
         *
         * Notes:
         *
         *
         * --*/

        public void UseRulesAndDefinitions(
            IFsrmCollection Rules,
            IFsrmCollection propertyDefinitions
            )
        {
            m_dictAllRules = new Dictionary <Guid, FsrmClassificationRule>();

            // loop through all rules and save them along with thier
            // parameter descriptions
            foreach (IFsrmClassificationRule fsrmClsRule in Rules)
            {
                if (fsrmClsRule.RuleType == _FsrmRuleType.FsrmRuleType_Classification)
                {
                    Guid ruleId = fsrmClsRule.id;

                    foreach (string param in fsrmClsRule.Parameters)
                    {
                        string[] splitParams = param.Split("=".ToCharArray(), 2);

                        string paramKey = splitParams[0];
                        string paramVal = splitParams[1];

                        if (paramVal != null)
                        {
                            if (paramKey.Equals(
                                    "RegularExpression",
                                    StringComparison.OrdinalIgnoreCase)
                                )
                            {
                                //Create a new internal rule object and store it
                                FsrmClassificationRule newRuleToAdd = new FsrmClassificationRule(
                                    paramVal,
                                    (RegexOptions)m_iValRegexOptions
                                    );
                                m_dictAllRules.Add(ruleId, newRuleToAdd);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        /*++
         *
         *  Routine RegexClassifier::OnBeginFile
         *
         * Description:
         *
         *  This routine implements the IFsrmClassifierModuleImplementation interface OnBeginFile.
         *  It is called by the pipeline for each file so that the classifier can process its rules for this file.
         *
         * Arguments:
         *
         *  propertyBag - The FSRM property bag object for this file.
         *  arrayRuleIds - The list of rules that are applicable for this file.
         *
         * Return value:
         *
         *  void
         *
         * Notes:
         *
         *
         * --*/

        public void OnBeginFile(
            IFsrmPropertyBag propertyBag,
            object[] arrayRuleIds
            )
        {
            //reset all rules
            foreach (KeyValuePair <Guid, FsrmClassificationRule> kvp in m_dictAllRules)
            {
                FsrmClassificationRule rule = (FsrmClassificationRule)kvp.Value;
                rule.ResetRule();
            }

            // create guid form of each id
            Guid[] ruleIdGuids = new Guid[arrayRuleIds.Length];
            for (int i = 0; i < arrayRuleIds.Length; ++i)
            {
                ruleIdGuids[i] = new Guid((string)arrayRuleIds[i]);
            }

            // wrap the istream in a stream, and use a streamreader to get each line
            // match each line against each rule's regexp
            // quit when all data has been read or all rules have been matched
            using (StreamWrapperForIStream stream = new StreamWrapperForIStream((IStream)propertyBag.GetFileStreamInterface(_FsrmFileStreamingMode.FsrmFileStreamingMode_Read, _FsrmFileStreamingInterfaceType.FsrmFileStreamingInterfaceType_IStream))) {
                StreamReader streamReader    = new StreamReader(stream, m_encoder);
                bool         matchedAllRules = false;

                do
                {
                    string line = streamReader.ReadLine();

                    matchedAllRules = true;
                    foreach (Guid ruleId in ruleIdGuids)
                    {
                        matchedAllRules &= m_dictAllRules[ruleId].DoesRegexSatisfy(line);
                    }
                } while (!streamReader.EndOfStream && !matchedAllRules);

                streamReader.Dispose();
            }
        }
        /*++

            Routine RegexClassifier::UseRulesAndDefinitions

        Description:

            This routine implements the IFsrmClassifierModuleImplementation interface UseRulesAndDefinitions.
            It is called by the pipeline to indicate to the classifier that the following rules apply to it for this run.

        Arguments:

            Rules - The FSRM classification rules that apply to this classifier for this run.
            propertyDefinitions - The property definitions affected by the above rules.

        Return value:

            void

        Notes:

        --*/
        public void UseRulesAndDefinitions(
            IFsrmCollection Rules,
            IFsrmCollection propertyDefinitions
            )
        {
            m_dictAllRules = new Dictionary<Guid, FsrmClassificationRule>();

            // loop through all rules and save them along with thier
            // parameter descriptions
            foreach (IFsrmClassificationRule fsrmClsRule in Rules) {

                if (fsrmClsRule.RuleType == _FsrmRuleType.FsrmRuleType_Classification) {
                    Guid ruleId = fsrmClsRule.id;

                    foreach (string param in fsrmClsRule.Parameters) {
                        string[] splitParams = param.Split( "=".ToCharArray(), 2 );

                        string paramKey = splitParams[0];
                        string paramVal = splitParams[1];

                        if (paramVal != null) {
                            if (paramKey.Equals(
                                "RegularExpression",
                                StringComparison.OrdinalIgnoreCase )
                                ) {

                                //Create a new internal rule object and store it
                                FsrmClassificationRule newRuleToAdd = new FsrmClassificationRule(
                                                                                paramVal,
                                                                                (RegexOptions)m_iValRegexOptions
                                                                                );
                                m_dictAllRules.Add( ruleId, newRuleToAdd );
                            }
                        }
                    }
                }
            }
        }