/// <summary> /// A function which returns a Stream object which encapsulates an IStream interface /// This makes it much easier to get the file contents in managed code / powershell /// </summary> /// <param name="parentObject">This will be the PSObject that encapsulates a IFsrmPropertyBag</param> /// <returns>A stream which wraps the parentObject's IStream</returns> public static StreamWrapperForIStream GetStream(PSObject parentObject) { IFsrmPropertyBag propertyBag = (IFsrmPropertyBag)parentObject.BaseObject; IStream istream = (IStream)propertyBag.GetFileStreamInterface(_FsrmFileStreamingMode.FsrmFileStreamingMode_Read, _FsrmFileStreamingInterfaceType.FsrmFileStreamingInterfaceType_IStream); return(new StreamWrapperForIStream(istream)); }
/*++ 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::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(); } }