protected override void ProcessRecord()

in src/PSRule/Commands/InvokeRuleBlockCommand.cs [29:93]


        protected override void ProcessRecord()
        {
            var context = RunspaceContext.CurrentThread;
            try
            {
                if (Body == null)
                    return;

                // Evalute selector pre-condition
                if (!AcceptsWith())
                {
                    context.Writer.DebugMessage(PSRuleResources.DebugTargetTypeMismatch);
                    return;
                }

                // Evalute type pre-condition
                if (!AcceptsType())
                {
                    context.Writer.DebugMessage(PSRuleResources.DebugTargetTypeMismatch);
                    return;
                }

                // Evaluate script pre-condition
                if (If != null)
                {
                    try
                    {
                        context.PushScope(RunspaceScope.Precondition);
                        var ifResult = RuleConditionHelper.Create(If.Invoke());
                        if (!ifResult.AllOf())
                        {
                            context.Writer.DebugMessage(PSRuleResources.DebugTargetIfMismatch);
                            return;
                        }
                    }
                    finally
                    {
                        context.PopScope(RunspaceScope.Precondition);
                    }
                }

                try
                {
                    // Evaluate script block
                    context.PushScope(RunspaceScope.Rule);
                    var invokeResult = RuleConditionHelper.Create(Body.Invoke());
                    WriteObject(invokeResult);
                }
                finally
                {
                    context.PopScope(RunspaceScope.Rule);
                }
            }
            catch (ActionPreferenceStopException ex)
            {
                context.Error(ex);
            }
            catch (System.Management.Automation.RuntimeException ex)
            {
                if (ex.ErrorRecord.FullyQualifiedErrorId == "MethodInvocationNotSupportedInConstrainedLanguage")
                    throw;

                context.Error(ex);
            }
        }