当前位置: 首页>>代码示例>>C#>>正文


C# Command.MergeMyResults方法代码示例

本文整理汇总了C#中System.Management.Automation.Runspaces.Command.MergeMyResults方法的典型用法代码示例。如果您正苦于以下问题:C# Command.MergeMyResults方法的具体用法?C# Command.MergeMyResults怎么用?C# Command.MergeMyResults使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Management.Automation.Runspaces.Command的用法示例。


在下文中一共展示了Command.MergeMyResults方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InvokeScript

        /// <summary>
        /// Invokes a script
        /// </summary>
        /// <param name="cmdToRun"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        private PSDataCollection<PSObject> InvokeScript(Command cmdToRun, RunspaceCreatedEventArgs args)
        {
            Debug.Assert(cmdToRun != null, "cmdToRun shouldn't be null");

            cmdToRun.CommandOrigin = CommandOrigin.Internal;
            cmdToRun.MergeMyResults(PipelineResultTypes.Error, PipelineResultTypes.Output);
            PowerShell powershell = PowerShell.Create();
            powershell.AddCommand(cmdToRun).AddCommand("out-default");

            return InvokePowerShell(powershell, args);
        }
开发者ID:40a,项目名称:PowerShell,代码行数:17,代码来源:ServerRunspacePoolDriver.cs

示例2: PoshHost

		public PoshHost(IPSUI psUi)
		{
			_buffer = psUi.Console;
			_tabExpander = new TabExpander(this);

			MakeConsole();

			Options = new PoshOptions(this, _buffer);
			_psUi = psUi;

			try
			{
				// we have to be careful here, because this is an interface member ...
				// but in the current implementation, _buffer.RawUI returns _buffer
				_rawUI = new PoshRawUI(_buffer.RawUI);
				_UI = new PoshUI(_rawUI, psUi);

				// pre-create this
				_outDefault = new Command("Out-Default");
				// for now, merge the errors with the rest of the output
				_outDefault.MergeMyResults(PipelineResultTypes.Error, PipelineResultTypes.Output);
				_outDefault.MergeUnclaimedPreviousCommandResults = PipelineResultTypes.Error | PipelineResultTypes.Output;
			}
			catch (Exception ex)
			{
				MessageBox.Show(
					"Can't create PowerShell interface, are you sure PowerShell is installed? \n" + ex.Message + "\nAt:\n" +
						ex.Source, "Error Starting PoshConsole", MessageBoxButton.OK, MessageBoxImage.Stop);
				throw;
			}
			_buffer.CommandBox.IsEnabled = false;
			_buffer.Expander.TabComplete += _tabExpander.Expand;
			_buffer.Command += OnGotUserInput;

			// Some delegates we think we can get away with making only once...
			Properties.Settings.Default.PropertyChanged += SettingsPropertyChanged;

			_runner = new CommandRunner(this, Resources.Prompt);
			_runner.RunspaceReady += (source, args) => _buffer.Dispatcher.BeginInvoke((Action) (() =>
				{
					_buffer.CommandBox.IsEnabled = true;
					ExecutePromptFunction(null, PipelineState.Completed);
				}));

			_runner.ShouldExit += (source, args) => SetShouldExit(args);
		}
开发者ID:ForNeVeR,项目名称:PoshConsole,代码行数:46,代码来源:PoshHost.cs

示例3: ConvertCommand

        private void ConvertCommand(CommandAst commandAst, bool isTrustedInput)
        {
            // First need command name.
            var commandName = GetCommandName(commandAst.CommandElements[0], isTrustedInput);

            var command = new Command(commandName, isScript: false, useLocalScope: _createLocalScope);

            // Handle redirections, if any (there can really be just 0 or 1).
            if (commandAst.Redirections.Count > 0)
            {
                Diagnostics.Assert(commandAst.Redirections.Count == 1, "only 1 kind of redirection is supported");
                Diagnostics.Assert(commandAst.Redirections[0] is MergingRedirectionAst, "unexpected redirection type");

                PipelineResultTypes toType = PipelineResultTypes.Output;
                PipelineResultTypes fromType;
                switch (commandAst.Redirections[0].FromStream)
                {
                    case RedirectionStream.Error:
                        fromType = PipelineResultTypes.Error;
                        break;

                    case RedirectionStream.Warning:
                        fromType = PipelineResultTypes.Warning;
                        break;

                    case RedirectionStream.Verbose:
                        fromType = PipelineResultTypes.Verbose;
                        break;

                    case RedirectionStream.Debug:
                        fromType = PipelineResultTypes.Debug;
                        break;

                    case RedirectionStream.Information:
                        fromType = PipelineResultTypes.Information;
                        break;

                    case RedirectionStream.All:
                        fromType = PipelineResultTypes.All;
                        break;

                    default:
                        // Default to Error->Output to be compatible with V2.
                        fromType = PipelineResultTypes.Error;
                        break;
                }

                command.MergeMyResults(fromType, toType);
            }

            _powershell.AddCommand(command);

            // Now the parameters and arguments.
            foreach (var ast in commandAst.CommandElements.Skip(1))
            {
                var exprAst = ast as ExpressionAst;
                if (exprAst != null)
                {
                    VariableExpressionAst variableAst = null;

                    var usingExprAst = ast as UsingExpressionAst;
                    if (usingExprAst != null)
                    {
                        string usingAstKey = PsUtils.GetUsingExpressionKey(usingExprAst);
                        object usingValue = _usingValueMap[usingAstKey];
                        variableAst = usingExprAst.SubExpression as VariableExpressionAst;
                        if (variableAst != null && variableAst.Splatted)
                        {
                            // Support the splatting of a dictionary
                            var parameters = usingValue as System.Collections.IDictionary;
                            if (parameters != null)
                            {
                                _powershell.AddParameters(parameters);
                            }
                            else
                            {
                                // Support the splatting of an array
                                var arguments = usingValue as System.Collections.IEnumerable;
                                if (arguments != null)
                                {
                                    foreach (Object argument in arguments)
                                    {
                                        _powershell.AddArgument(argument);
                                    }
                                }
                                else
                                {
                                    // Splat the object directly.
                                    _powershell.AddArgument(usingValue);
                                }
                            }
                        }
                        else
                        {
                            _powershell.AddArgument(usingValue);
                        }
                        continue;
                    }

                    variableAst = ast as VariableExpressionAst;
//.........这里部分代码省略.........
开发者ID:40a,项目名称:PowerShell,代码行数:101,代码来源:ScriptBlockToPowerShell.cs

示例4: ProcessImportModule

 private void ProcessImportModule(string name, PSModuleInfo moduleInfoToLoad, bool startLifeCycleEventWritten)
 {
     using (PowerShell shell = PowerShell.Create())
     {
         List<ErrorRecord> errors = new List<ErrorRecord>();
         if (!this.InitialSessionState.ThrowOnRunspaceOpenError)
         {
             CommandInfo importModuleCommandInfo = this.GetImportModuleCommandInfo(name, ref errors);
             if (importModuleCommandInfo != null)
             {
                 Command command = new Command(importModuleCommandInfo);
                 if (moduleInfoToLoad != null)
                 {
                     command.Parameters.Add("ModuleInfo", moduleInfoToLoad);
                 }
                 else
                 {
                     command.Parameters.Add("Name", name);
                 }
                 command.MergeMyResults(PipelineResultTypes.Error, PipelineResultTypes.Output);
                 shell.AddCommand(command);
                 importModuleCommandInfo = this.GetOutDefaultCommandInfo(name, ref errors);
                 if (importModuleCommandInfo != null)
                 {
                     shell.AddCommand(new Command(importModuleCommandInfo));
                 }
             }
         }
         else
         {
             CommandInfo commandInfo = this.GetImportModuleCommandInfo(name, ref errors);
             if (commandInfo != null)
             {
                 Command command2 = new Command(commandInfo);
                 if (moduleInfoToLoad != null)
                 {
                     command2.Parameters.Add("ModuleInfo", moduleInfoToLoad);
                 }
                 else
                 {
                     command2.Parameters.Add("Name", name);
                 }
                 shell.AddCommand(command2);
             }
         }
         if (((shell.Commands != null) && (shell.Commands.Commands != null)) && (shell.Commands.Commands.Count > 0))
         {
             shell.Runspace = this;
             shell.Invoke();
         }
         this.ValidateAndThrowRunspaceOpenModuleLoadException(shell, errors, startLifeCycleEventWritten, name, null);
     }
 }
开发者ID:nickchal,项目名称:pash,代码行数:53,代码来源:LocalRunspace.cs

示例5: FromPSObjectForRemoting

 internal static Command FromPSObjectForRemoting(PSObject commandAsPSObject)
 {
     if (commandAsPSObject == null)
     {
         throw PSTraceSource.NewArgumentNullException("commandAsPSObject");
     }
     string propertyValue = RemotingDecoder.GetPropertyValue<string>(commandAsPSObject, "Cmd");
     bool isScript = RemotingDecoder.GetPropertyValue<bool>(commandAsPSObject, "IsScript");
     bool? useLocalScope = RemotingDecoder.GetPropertyValue<bool?>(commandAsPSObject, "UseLocalScope");
     Command command = new Command(propertyValue, isScript, useLocalScope);
     PipelineResultTypes myResult = RemotingDecoder.GetPropertyValue<PipelineResultTypes>(commandAsPSObject, "MergeMyResult");
     PipelineResultTypes toResult = RemotingDecoder.GetPropertyValue<PipelineResultTypes>(commandAsPSObject, "MergeToResult");
     command.MergeMyResults(myResult, toResult);
     command.MergeUnclaimedPreviousCommandResults = RemotingDecoder.GetPropertyValue<PipelineResultTypes>(commandAsPSObject, "MergePreviousResults");
     if (commandAsPSObject.Properties["MergeError"] != null)
     {
         command.MergeInstructions[0] = RemotingDecoder.GetPropertyValue<PipelineResultTypes>(commandAsPSObject, "MergeError");
     }
     if (commandAsPSObject.Properties["MergeWarning"] != null)
     {
         command.MergeInstructions[1] = RemotingDecoder.GetPropertyValue<PipelineResultTypes>(commandAsPSObject, "MergeWarning");
     }
     if (commandAsPSObject.Properties["MergeVerbose"] != null)
     {
         command.MergeInstructions[2] = RemotingDecoder.GetPropertyValue<PipelineResultTypes>(commandAsPSObject, "MergeVerbose");
     }
     if (commandAsPSObject.Properties["MergeDebug"] != null)
     {
         command.MergeInstructions[3] = RemotingDecoder.GetPropertyValue<PipelineResultTypes>(commandAsPSObject, "MergeDebug");
     }
     foreach (PSObject obj2 in RemotingDecoder.EnumerateListProperty<PSObject>(commandAsPSObject, "Args"))
     {
         command.Parameters.Add(CommandParameter.FromPSObjectForRemoting(obj2));
     }
     return command;
 }
开发者ID:nickchal,项目名称:pash,代码行数:36,代码来源:Command.cs

示例6: ConvertCommand

        private void ConvertCommand(CommandAst commandAst)
        {
            Command command = new Command(this.GetCommandName(commandAst.CommandElements[0]), false, this._createLocalScope);
            if (commandAst.Redirections.Count > 0)
            {
                PipelineResultTypes all;
                PipelineResultTypes output = PipelineResultTypes.Output;
                switch (commandAst.Redirections[0].FromStream)
                {
                    case RedirectionStream.All:
                        all = PipelineResultTypes.All;
                        break;

                    case RedirectionStream.Error:
                        all = PipelineResultTypes.Error;
                        break;

                    case RedirectionStream.Warning:
                        all = PipelineResultTypes.Warning;
                        break;

                    case RedirectionStream.Verbose:
                        all = PipelineResultTypes.Verbose;
                        break;

                    case RedirectionStream.Debug:
                        all = PipelineResultTypes.Debug;
                        break;

                    default:
                        all = PipelineResultTypes.Error;
                        break;
                }
                command.MergeMyResults(all, output);
            }
            this._powershell.AddCommand(command);
            foreach (CommandElementAst ast in commandAst.CommandElements.Skip<CommandElementAst>(1))
            {
                ExpressionAst exprAst = ast as ExpressionAst;
                if (exprAst != null)
                {
                    VariableExpressionAst variableAst = null;
                    UsingExpressionAst ast4 = ast as UsingExpressionAst;
                    if (ast4 != null)
                    {
                        variableAst = ast4.SubExpression as VariableExpressionAst;
                        if ((variableAst != null) && variableAst.Splatted)
                        {
                            IDictionary parameters = this._usingValues[ast4.RuntimeUsingIndex] as IDictionary;
                            if (parameters != null)
                            {
                                this._powershell.AddParameters(parameters);
                            }
                            else
                            {
                                IEnumerable enumerable = this._usingValues[ast4.RuntimeUsingIndex] as IEnumerable;
                                if (enumerable != null)
                                {
                                    foreach (object obj2 in enumerable)
                                    {
                                        this._powershell.AddArgument(obj2);
                                    }
                                }
                                else
                                {
                                    this._powershell.AddArgument(this._usingValues[ast4.RuntimeUsingIndex]);
                                }
                            }
                        }
                        else
                        {
                            this._powershell.AddArgument(this._usingValues[ast4.RuntimeUsingIndex]);
                        }
                    }
                    else
                    {
                        variableAst = ast as VariableExpressionAst;
                        if ((variableAst != null) && variableAst.Splatted)
                        {
                            this.GetSplattedVariable(variableAst);
                        }
                        else
                        {
                            object expressionValue;
                            ConstantExpressionAst ast5 = ast as ConstantExpressionAst;
                            if ((ast5 != null) && LanguagePrimitives.IsNumeric(LanguagePrimitives.GetTypeCode(ast5.StaticType)))
                            {
                                string text = ast5.Extent.Text;
                                expressionValue = ast5.Value;
                                if (!text.Equals(ast5.Value.ToString(), StringComparison.Ordinal))
                                {
                                    expressionValue = ParserOps.WrappedNumber(expressionValue, text);
                                }
                            }
                            else
                            {
                                expressionValue = this.GetExpressionValue(exprAst);
                            }
                            this._powershell.AddArgument(expressionValue);
                        }
//.........这里部分代码省略.........
开发者ID:nickchal,项目名称:pash,代码行数:101,代码来源:ScriptBlockToPowerShellConverter.cs

示例7: InvokeScript

 private PSDataCollection<PSObject> InvokeScript(Command cmdToRun, RunspaceCreatedEventArgs args)
 {
     cmdToRun.MergeMyResults(PipelineResultTypes.Error, PipelineResultTypes.Output);
     PowerShell powershell = PowerShell.Create();
     powershell.AddCommand(cmdToRun).AddCommand("out-default");
     return this.InvokePowerShell(powershell, args);
 }
开发者ID:nickchal,项目名称:pash,代码行数:7,代码来源:ServerRunspacePoolDriver.cs


注:本文中的System.Management.Automation.Runspaces.Command.MergeMyResults方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。