Exemplo n.º 1
0
        protected override void ProcessRecord()
        {
            if (!IsScriptScope())
            {
                throw new RuleRuntimeException(string.Format(PSRuleResources.KeywordScriptScope, LanguageKeywords.Rule));
            }

            var context  = PipelineContext.CurrentThread;
            var metadata = GetMetadata(MyInvocation.ScriptName, MyInvocation.ScriptLineNumber, MyInvocation.OffsetInLine);
            var tag      = GetTag(Tag);
            var source   = context.Source.File;

            context.VerboseFoundRule(ruleName: Name, scriptName: MyInvocation.ScriptName);

            CheckDependsOn();

            var ps = PowerShell.Create();

            ps.Runspace = context.GetRunspace();
            ps.AddCommand(new CmdletInfo(InvokeBlockCmdletName, typeof(InvokeRuleBlockCommand)));
            ps.AddParameter(InvokeBlockCmdlet_TypeParameter, Type);
            ps.AddParameter(InvokeBlockCmdlet_IfParameter, If);
            ps.AddParameter(InvokeBlockCmdlet_BodyParameter, Body);

            PipelineContext.EnableLogging(ps);

            var helpInfo = GetHelpInfo(context: context, name: Name) ?? new RuleHelpInfo(name: Name, displayName: Name, moduleName: source.ModuleName);

            if (helpInfo.Synopsis == null)
            {
                helpInfo.Synopsis = metadata.Synopsis;
            }

            var block = new RuleBlock(
                source: source,
                ruleName: Name,
                info: helpInfo,
                condition: ps,
                tag: tag,
                dependsOn: RuleHelper.ExpandRuleName(DependsOn, MyInvocation.ScriptName, source.ModuleName),
                configuration: Configure
                );

            WriteObject(block);
        }
        protected override void ProcessRecord()
        {
            if (!IsScriptScope())
            {
                throw new RuleRuntimeException(string.Format(PSRuleResources.KeywordScriptScope, LanguageKeywords.Rule));
            }

            var context  = RunspaceContext.CurrentThread;
            var metadata = GetMetadata(MyInvocation.ScriptName, MyInvocation.ScriptLineNumber, MyInvocation.OffsetInLine);
            var tag      = GetTag(Tag);
            var source   = context.Source.File;
            var extent   = new RuleExtent(
                file: source.Path,
                startLineNumber: Body.Ast.Extent.StartLineNumber
                );

            context.VerboseFoundRule(ruleName: Name, scriptName: MyInvocation.ScriptName);

            CheckDependsOn();
            var ps       = GetCondition(context);
            var helpInfo = GetHelpInfo(context: context, name: Name) ?? new RuleHelpInfo(
                name: Name,
                displayName: Name,
                moduleName: source.ModuleName
                );

            if (helpInfo.Synopsis == null)
            {
                helpInfo.Synopsis = metadata.Synopsis;
            }

            var block = new RuleBlock(
                source: source,
                ruleName: Name,
                info: helpInfo,
                condition: ps,
                tag: tag,
                dependsOn: RuleHelper.ExpandRuleName(DependsOn, MyInvocation.ScriptName, source.ModuleName),
                configuration: Configure,
                extent: extent
                );

            WriteObject(block);
        }