/// <summary>
        /// Initialize all values, as well as start the pipeline and await for data
        /// </summary>
        /// <param name="moduleDefinition">The module definition for the classifier</param>
        /// <param name="rule">The rule definition for the rule that this represents</param>
        /// <param name="propertyDefinition">The property definition for the property that this rule modifies</param>
        public PowerShellRuleHoster(
            IFsrmPipelineModuleDefinition moduleDefinition,
            IFsrmClassificationRule rule,
            IFsrmPropertyDefinition propertyDefinition
            )
        {
            m_propertyBagWriter = new BlockablePropertyBagEnumerator();
            m_ruleName          = rule.Name;

            // create the waitHandles and initialize them
            // *note the pipeline waitHandle is created in CreateAndBeginPipeline
            m_powershellPaused = new WaitHandle[(int)m_waitHandleIndex.Count];
            m_powershellPaused[(int)m_waitHandleIndex.Enumerator] = m_propertyBagWriter.RequestedDataWaitHandle;

            // cache the method info for adding the GetStream to PropertyBag
            Type extensionClassForPropertyBag = typeof(ExtensionClassForPropertyBag);

            m_getStreamMethodInfo = extensionClassForPropertyBag.GetMethod("GetStream");


            string fileText = GetScriptText(rule);

            // this enables users to create a scriptblock rather then enumerate over the PropertyBagList
            m_scriptText = "$PropertyBagList | &{" + fileText + "}\n";

            // construct the runspace and set global proxy values for powershell script to use
            m_runSpace = RunspaceFactory.CreateRunspace();
            m_runSpace.Open();
            m_runSpace.SessionStateProxy.SetVariable("ModuleDefinition", moduleDefinition);
            m_runSpace.SessionStateProxy.SetVariable("PropertyBagList", m_propertyBagWriter);
            m_runSpace.SessionStateProxy.SetVariable("Rule", rule);
            m_runSpace.SessionStateProxy.SetVariable("PropertyDefinition", propertyDefinition);

            //launch the pipeline creation
            CreateAndBeginPipeline();
        }
        /// <summary>
        /// Gets the text of the powershell script
        /// </summary>
        /// <param name="rule">The rule definition (contains the script to get)</param>
        /// <returns>The text of the powershell script</returns>
        public static string GetScriptText(
            IFsrmClassificationRule rule
            )
        {
            // parse the rule strParameters to determine what type of encoding there is
            // otherwise use default encoding to get the text of the file
            Dictionary <string, string> ruleParameters = ParseParameters(rule.Parameters);

            string scriptFileName;

            try
            {
                scriptFileName = ruleParameters[ScriptFileNameString];
            }
            catch (KeyNotFoundException e)
            {
                string message = String.Format(
                    "PowerShellHostClassifier failed processing parameters for rule {0}. Make sure the rule parameter name is ScriptFileName.",
                    rule.Name);

                EventLog eventLog = new EventLog("Application", ".", "SRM_PS_CLS");
                eventLog.WriteEntry(message, EventLogEntryType.Error);

                throw new COMException(message, e);
            }

            // read the text of the file and return it
            string fileText;

            using (StreamReader fs = new StreamReader(scriptFileName))
            {
                fileText = fs.ReadToEnd();
            }

            return(fileText);
        }
        /// <summary>
        /// Initialize all values, as well as start the pipeline and await for data
        /// </summary>
        /// <param name="moduleDefinition">The module definition for the classifier</param>
        /// <param name="rule">The rule definition for the rule that this represents</param>
        /// <param name="propertyDefinition">The property definition for the property that this rule modifies</param>
        public PowerShellRuleHoster(
            IFsrmPipelineModuleDefinition moduleDefinition,
            IFsrmClassificationRule rule,
            IFsrmPropertyDefinition propertyDefinition
            )
        {
            m_propertyBagWriter = new BlockablePropertyBagEnumerator();
            m_ruleName = rule.Name;

            // create the waitHandles and initialize them
            // *note the pipeline waitHandle is created in CreateAndBeginPipeline
            m_powershellPaused = new WaitHandle[(int)m_waitHandleIndex.Count];
            m_powershellPaused[(int)m_waitHandleIndex.Enumerator] = m_propertyBagWriter.RequestedDataWaitHandle;

            // cache the method info for adding the GetStream to PropertyBag
            Type extensionClassForPropertyBag = typeof(ExtensionClassForPropertyBag);
            m_getStreamMethodInfo = extensionClassForPropertyBag.GetMethod("GetStream");

            string fileText = GetScriptText(rule);

            // this enables users to create a scriptblock rather then enumerate over the PropertyBagList
            m_scriptText = "$PropertyBagList | &{" + fileText + "}\n";

            // construct the runspace and set global proxy values for powershell script to use
            m_runSpace = RunspaceFactory.CreateRunspace();
            m_runSpace.Open();
            m_runSpace.SessionStateProxy.SetVariable("ModuleDefinition", moduleDefinition);
            m_runSpace.SessionStateProxy.SetVariable("PropertyBagList", m_propertyBagWriter);
            m_runSpace.SessionStateProxy.SetVariable("Rule", rule);
            m_runSpace.SessionStateProxy.SetVariable("PropertyDefinition", propertyDefinition);

            //launch the pipeline creation
            CreateAndBeginPipeline();
        }
        /// <summary>
        /// Gets the text of the powershell script
        /// </summary>
        /// <param name="rule">The rule definition (contains the script to get)</param>
        /// <returns>The text of the powershell script</returns>
        public static string GetScriptText(
            IFsrmClassificationRule rule
            )
        {
            // parse the rule strParameters to determine what type of encoding there is
            // otherwise use default encoding to get the text of the file
            Dictionary<string, string> ruleParameters = ParseParameters(rule.Parameters);

            string scriptFileName;

            try
            {
                scriptFileName = ruleParameters[ScriptFileNameString];
            }
            catch (KeyNotFoundException e)
            {
                string message = String.Format(
                    "PowerShellHostClassifier failed processing parameters for rule {0}. Make sure the rule parameter name is ScriptFileName.",
                    rule.Name);

                EventLog eventLog = new EventLog("Application", ".", "SRM_PS_CLS");
                eventLog.WriteEntry(message, EventLogEntryType.Error);

                throw new COMException(message, e);
            }

            // read the text of the file and return it
            string fileText;
            using (StreamReader fs = new StreamReader(scriptFileName))
            {
                fileText = fs.ReadToEnd();
            }

            return fileText;
        }