Inheritance: System.Management.Automation.CommandProcessorBase
コード例 #1
0
ファイル: CommandWrapper.cs プロジェクト: nickchal/pash
 private void DelayedInternalInitialize()
 {
     this.pp = new PipelineProcessor();
     CmdletInfo cmdletInfo = new CmdletInfo(this.commandName, this.commandType, null, null, this.context);
     CommandProcessor commandProcessor = new CommandProcessor(cmdletInfo, this.context);
     foreach (CommandParameterInternal internal2 in this.commandParameterList)
     {
         commandProcessor.AddParameter(internal2);
     }
     this.pp.Add(commandProcessor);
 }
コード例 #2
0
ファイル: BindingTests.cs プロジェクト: JayBazuzi/Pash
        public void BindingField()
        {
            CommandProcessor cmdProc = new CommandProcessor(info);
            TestParameterCommand cmdlet = new TestParameterCommand();
            cmdProc.Command = cmdlet;

            cmdProc.AddParameter("Name", "John");

            cmdProc.BindArguments(null);

            Assert.AreEqual("John", cmdlet.Name);
        }
コード例 #3
0
ファイル: BindingTests.cs プロジェクト: b333z/Pash
        public void BindingAmbiguous()
        {
            CommandProcessor cmdProc = new CommandProcessor(info);
            TestParameterCommand cmdlet = new TestParameterCommand();
            cmdProc.Command = cmdlet;

            cmdProc.AddParameter("i", 10);

            Assert.Throws(typeof(ArgumentException), delegate() {
                cmdProc.BindArguments(null);
            });
        }
コード例 #4
0
ファイル: BindingTests.cs プロジェクト: JayBazuzi/Pash
        public void BindingNonSwitch()
        {
            CommandProcessor cmdProc = new CommandProcessor(info);
            TestParameterCommand cmdlet = new TestParameterCommand();
            cmdProc.Command = cmdlet;

            cmdProc.AddParameter("Name", null);
            cmdProc.AddParameter(null, "John");

            cmdProc.BindArguments(null);

            Assert.AreEqual("John", cmdlet.Name);
            Assert.IsFalse(cmdlet.Recurse.ToBool());
        }
コード例 #5
0
ファイル: BindingTests.cs プロジェクト: b333z/Pash
        public void BindingCombinationNonDefaultSet()
        {
            CommandProcessor cmdProc = new CommandProcessor(info);
            TestParameterCommand cmdlet = new TestParameterCommand();
            cmdProc.Command = cmdlet;

            cmdProc.AddParameter("Variable", "a");
            cmdProc.AddParameter("Recurse", null);

            cmdProc.BindArguments(null);

            Assert.AreEqual("John", cmdlet.Name);
            Assert.AreEqual("a path", cmdlet.FilePath);
            Assert.IsTrue(cmdlet.Recurse.ToBool());
        }
コード例 #6
0
ファイル: LocalPipeline.cs プロジェクト: nickchal/pash
 private PipelineProcessor CreatePipelineProcessor()
 {
     PipelineProcessor processor2;
     CommandCollection commands = base.Commands;
     if ((commands == null) || (commands.Count == 0))
     {
         throw PSTraceSource.NewInvalidOperationException("RunspaceStrings", "NoCommandInPipeline", new object[0]);
     }
     PipelineProcessor processor = new PipelineProcessor {
         TopLevel = true
     };
     bool flag = false;
     try
     {
         foreach (Command command in commands)
         {
             CommandProcessorBase base2;
             if (command.CommandInfo == null)
             {
                 base2 = command.CreateCommandProcessor(this.LocalRunspace.ExecutionContext, this.LocalRunspace.CommandFactory, base.AddToHistory, this.IsNested ? CommandOrigin.Internal : CommandOrigin.Runspace);
             }
             else
             {
                 CmdletInfo commandInfo = (CmdletInfo) command.CommandInfo;
                 base2 = new CommandProcessor(commandInfo, this.LocalRunspace.ExecutionContext);
                 PSSQMAPI.IncrementData(commandInfo.CommandType);
                 base2.Command.CommandOriginInternal = CommandOrigin.Internal;
                 base2.Command.MyInvocation.InvocationName = commandInfo.Name;
                 if (command.Parameters != null)
                 {
                     foreach (CommandParameter parameter in command.Parameters)
                     {
                         CommandParameterInternal internal2 = CommandParameter.ToCommandParameterInternal(parameter, false);
                         base2.AddParameter(internal2);
                     }
                 }
             }
             base2.RedirectShellErrorOutputPipe = base.RedirectShellErrorOutputPipe;
             processor.Add(base2);
         }
         processor2 = processor;
     }
     catch (RuntimeException)
     {
         flag = true;
         throw;
     }
     catch (Exception exception)
     {
         flag = true;
         CommandProcessorBase.CheckForSevereException(exception);
         throw new RuntimeException(PipelineStrings.CannotCreatePipeline, exception);
     }
     finally
     {
         if (flag)
         {
             base.SetHadErrors(true);
             processor.Dispose();
         }
     }
     return processor2;
 }
コード例 #7
0
ファイル: CommandDiscovery.cs プロジェクト: nickchal/pash
        internal CommandProcessorBase LookupCommandProcessor(CommandInfo commandInfo, CommandOrigin commandOrigin, bool? useLocalScope, SessionStateInternal sessionState)
        {
            CommandProcessorBase base2 = null;
            FunctionInfo info3;
            CommandNotFoundException exception6;
            HashSet<string> set = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
            while (((commandInfo.CommandType == CommandTypes.Alias) && !set.Contains(commandInfo.Name)) && ((commandOrigin == CommandOrigin.Internal) || (commandInfo.Visibility == SessionStateEntryVisibility.Public)))
            {
                set.Add(commandInfo.Name);
                AliasInfo info = (AliasInfo) commandInfo;
                commandInfo = info.ResolvedCommand;
                if (commandInfo == null)
                {
                    commandInfo = LookupCommandInfo(info.Definition, commandOrigin, this._context);
                }
                if (commandInfo == null)
                {
                    CommandNotFoundException exception = new CommandNotFoundException(info.Name, null, "AliasNotResolvedException", DiscoveryExceptions.AliasNotResolvedException, new object[] { info.UnresolvedCommandName });
                    throw exception;
                }
                PSSQMAPI.IncrementData(CommandTypes.Alias);
            }
            ShouldRun(this._context, this._context.EngineHostInterface, commandInfo, commandOrigin);
            CommandTypes commandType = commandInfo.CommandType;
            if (commandType <= CommandTypes.ExternalScript)
            {
                switch (commandType)
                {
                    case CommandTypes.Function:
                    case CommandTypes.Filter:
                        goto Label_01E3;

                    case CommandTypes.Cmdlet:
                        base2 = new CommandProcessor((CmdletInfo) commandInfo, this._context);
                        goto Label_0260;

                    case CommandTypes.ExternalScript:
                    {
                        ExternalScriptInfo scriptInfo = (ExternalScriptInfo) commandInfo;
                        scriptInfo.SignatureChecked = true;
                        try
                        {
                            if (!this._context.IsSingleShell)
                            {
                                bool? nullable = useLocalScope;
                                base2 = this.CreateScriptProcessorForMiniShell(scriptInfo, nullable.HasValue ? nullable.GetValueOrDefault() : true, sessionState);
                            }
                            else
                            {
                                bool? nullable2 = useLocalScope;
                                base2 = this.CreateScriptProcessorForSingleShell(scriptInfo, this._context, nullable2.HasValue ? nullable2.GetValueOrDefault() : true, sessionState);
                            }
                            goto Label_0260;
                        }
                        catch (ScriptRequiresSyntaxException exception2)
                        {
                            CommandNotFoundException exception3 = new CommandNotFoundException(exception2.Message, exception2);
                            throw exception3;
                        }
                        catch (PSArgumentException exception4)
                        {
                            CommandNotFoundException exception5 = new CommandNotFoundException(commandInfo.Name, exception4, "ScriptRequiresInvalidFormat", DiscoveryExceptions.ScriptRequiresInvalidFormat, new object[0]);
                            throw exception5;
                        }
                        goto Label_01E3;
                    }
                }
                goto Label_023F;
            }
            if (commandType != CommandTypes.Application)
            {
                if (commandType == CommandTypes.Script)
                {
                    bool? nullable4 = useLocalScope;
                    base2 = CreateCommandProcessorForScript((ScriptInfo) commandInfo, this._context, nullable4.HasValue ? nullable4.GetValueOrDefault() : true, sessionState);
                    goto Label_0260;
                }
                if (commandType == CommandTypes.Workflow)
                {
                    goto Label_01E3;
                }
                goto Label_023F;
            }
            base2 = new NativeCommandProcessor((ApplicationInfo) commandInfo, this._context);
            goto Label_0260;
        Label_01E3:
            info3 = (FunctionInfo) commandInfo;
            bool? nullable3 = useLocalScope;
            base2 = CreateCommandProcessorForScript(info3, this._context, nullable3.HasValue ? nullable3.GetValueOrDefault() : true, sessionState);
            goto Label_0260;
        Label_023F:
            exception6 = new CommandNotFoundException(commandInfo.Name, null, "CommandNotFoundException", DiscoveryExceptions.CommandNotFoundException, new object[0]);
            throw exception6;
        Label_0260:
            PSSQMAPI.IncrementData(commandInfo.CommandType);
            base2.Command.CommandOriginInternal = commandOrigin;
            base2.Command.MyInvocation.InvocationName = commandInfo.Name;
            return base2;
        }
コード例 #8
0
ファイル: Command.cs プロジェクト: nickchal/pash
        internal CommandProcessorBase CreateCommandProcessor(ExecutionContext executionContext, CommandFactory commandFactory, bool addToHistory, CommandOrigin origin)
        {
            CommandProcessorBase base2;
            string str2;
            HelpCategory category;
            if (!this.IsScript)
            {
                if (this._useLocalScope.HasValue && !this._useLocalScope.Value)
                {
                    switch (executionContext.LanguageMode)
                    {
                        case PSLanguageMode.RestrictedLanguage:
                        case PSLanguageMode.NoLanguage:
                            throw new RuntimeException(StringUtil.Format(RunspaceStrings.UseLocalScopeNotAllowed, new object[] { "UseLocalScope", PSLanguageMode.RestrictedLanguage.ToString(), PSLanguageMode.NoLanguage.ToString() }));
                    }
                }
                base2 = commandFactory.CreateCommand(this.CommandText, origin, this._useLocalScope);
            }
            else
            {
                if (executionContext.LanguageMode == PSLanguageMode.NoLanguage)
                {
                    throw InterpreterError.NewInterpreterException(this.CommandText, typeof(ParseException), null, "ScriptsNotAllowed", ParserStrings.ScriptsNotAllowed, new object[0]);
                }
                ScriptBlock function = executionContext.Engine.ParseScriptBlock(this.CommandText, addToHistory);
                switch (executionContext.LanguageMode)
                {
                    case PSLanguageMode.FullLanguage:
                    case PSLanguageMode.ConstrainedLanguage:
                        break;

                    case PSLanguageMode.RestrictedLanguage:
                        function.CheckRestrictedLanguage(null, null, false);
                        break;

                    default:
                        throw new InvalidOperationException("Invalid langage mode was set when building a ScriptCommandProcessor");
                }
                if (function.UsesCmdletBinding)
                {
                    FunctionInfo scriptCommandInfo = new FunctionInfo("", function, executionContext);
                    bool? nullable = this._useLocalScope;
                    base2 = new CommandProcessor(scriptCommandInfo, executionContext, nullable.HasValue ? nullable.GetValueOrDefault() : false, false, executionContext.EngineSessionState);
                }
                else
                {
                    bool? nullable2 = this._useLocalScope;
                    base2 = new DlrScriptCommandProcessor(function, executionContext, nullable2.HasValue ? nullable2.GetValueOrDefault() : false, CommandOrigin.Runspace, executionContext.EngineSessionState);
                }
            }
            CommandParameterCollection parameters = this.Parameters;
            if (parameters != null)
            {
                bool forNativeCommand = base2 is NativeCommandProcessor;
                foreach (CommandParameter parameter in parameters)
                {
                    CommandParameterInternal internal2 = CommandParameter.ToCommandParameterInternal(parameter, forNativeCommand);
                    base2.AddParameter(internal2);
                }
            }
            if (base2.IsHelpRequested(out str2, out category))
            {
                base2 = CommandProcessorBase.CreateGetHelpCommandProcessor(executionContext, str2, category);
            }
            this.SetMergeSettingsOnCommandProcessor(base2);
            return base2;
        }
コード例 #9
0
ファイル: BindingTests.cs プロジェクト: JayBazuzi/Pash
        public void BindingParameter()
        {
            CommandProcessor cmdProc = new CommandProcessor(info);
            TestParameterCommand cmdlet = new TestParameterCommand();
            cmdProc.Command = cmdlet;

            cmdProc.AddParameter("InputObject", 10);

            cmdProc.BindArguments(null);

            Assert.AreEqual("10", cmdlet.InputObject.ToString());
        }
コード例 #10
0
ファイル: BindingTests.cs プロジェクト: JayBazuzi/Pash
        public void BindingParameterSetSelectionSingleAlias()
        {
            CommandProcessor cmdProc = new CommandProcessor(info);
            TestParameterCommand cmdlet = new TestParameterCommand();
            cmdProc.Command = cmdlet;

            cmdProc.AddParameter("PSPath", null);
            cmdProc.AddParameter(null, "a path");

            cmdProc.BindArguments(null);

            Assert.AreEqual("File", cmdlet.ParameterSetName);
        }
コード例 #11
0
ファイル: BindingTests.cs プロジェクト: JayBazuzi/Pash
        public void BindingParameterSetSelectionDoubleShouldFail()
        {
            CommandProcessor cmdProc = new CommandProcessor(info);
            TestParameterCommand cmdlet = new TestParameterCommand();
            cmdProc.Command = cmdlet;

            cmdProc.AddParameter("Variable", null);
            cmdProc.AddParameter(null, "test");
            cmdProc.AddParameter("FilePath", null);
            cmdProc.AddParameter(null, "a path");

            Assert.Throws(typeof(Exception), delegate()
            {
                cmdProc.BindArguments(null);
            });
        }
コード例 #12
0
ファイル: BindingTests.cs プロジェクト: b333z/Pash
        public void BindingParameterAlias()
        {
            CommandProcessor cmdProc = new CommandProcessor(info);
            TestParameterCommand cmdlet = new TestParameterCommand();
            cmdProc.Command = cmdlet;

            cmdProc.AddParameter("Path", "a path");

            cmdProc.BindArguments(null);

            Assert.AreEqual("a path", cmdlet.FilePath.ToString());
        }
コード例 #13
0
ファイル: BaseCommand.cs プロジェクト: 40a/PowerShell
        private void DelayedInternalInitialize()
        {
            _pp = new PipelineProcessor();

            CmdletInfo cmdletInfo = new CmdletInfo(_commandName, _commandType, null, null, _context);

            CommandProcessor cp = new CommandProcessor(cmdletInfo, _context);

            foreach (CommandParameterInternal par in _commandParameterList)
            {
                cp.AddParameter(par);
            }

            _pp.Add(cp);
        }