コード例 #1
0
        private InvokeResult ProcessTargetObject(PSObject targetObject)
        {
            Context.SetTargetObject(targetObject);
            var result      = new InvokeResult();
            var ruleCounter = 0;

            // Process rule blocks ordered by dependency graph
            foreach (var ruleBlockTarget in _RuleGraph.GetSingleTarget())
            {
                // Enter rule block scope
                var ruleRecord = Context.EnterRuleBlock(ruleBlock: ruleBlockTarget.Value);
                ruleCounter++;

                try
                {
                    if (Pipeline.ShouldFilter())
                    {
                        continue;
                    }

                    // Check if dependency failed
                    if (ruleBlockTarget.Skipped)
                    {
                        ruleRecord.OutcomeReason = RuleOutcomeReason.DependencyFail;
                    }
                    // Check for suppression
                    else if (_SuppressionFilter.Match(ruleName: ruleRecord.RuleName, targetName: ruleRecord.TargetName))
                    {
                        ruleRecord.OutcomeReason = RuleOutcomeReason.Suppressed;
                    }
                    else
                    {
                        HostHelper.InvokeRuleBlock(context: Context, ruleBlock: ruleBlockTarget.Value, ruleRecord: ruleRecord);
                        if (ruleRecord.OutcomeReason == RuleOutcomeReason.PreconditionFail)
                        {
                            ruleCounter--;
                        }
                    }

                    // Report outcome to dependency graph
                    if (ruleRecord.Outcome == RuleOutcome.Pass)
                    {
                        ruleBlockTarget.Pass();
                    }
                    else if (ruleRecord.Outcome == RuleOutcome.Fail || ruleRecord.Outcome == RuleOutcome.Error)
                    {
                        ruleBlockTarget.Fail();
                    }

                    AddToSummary(ruleBlock: ruleBlockTarget.Value, outcome: ruleRecord.Outcome);
                    if (ShouldOutput(ruleRecord.Outcome))
                    {
                        result.Add(ruleRecord);
                    }
                }
                finally
                {
                    // Exit rule block scope
                    Context.ExitRuleBlock();
                }
            }

            if (ruleCounter == 0)
            {
                Context.WarnObjectNotProcessed();
            }

            return(result);
        }
コード例 #2
0
ファイル: AssertPipeline.cs プロジェクト: Hadisalman/PSRule
 public abstract void Result(InvokeResult result);