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


C# PSDataCollection.Complete方法代码示例

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


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

示例1: ExtractErrorFromErrorRecord

        public static string ExtractErrorFromErrorRecord(this Runspace runspace, ErrorRecord record)
        {
            Pipeline pipeline = runspace.CreatePipeline("$input", false);
            pipeline.Commands.Add("out-string");

            Collection<PSObject> result;
            using (PSDataCollection<object> inputCollection = new PSDataCollection<object>())
            {
                inputCollection.Add(record);
                inputCollection.Complete();
                result = pipeline.Invoke(inputCollection);
            }

            if (result.Count > 0)
            {
                string str = result[0].BaseObject as string;
                if (!string.IsNullOrEmpty(str))
                {
                    // Remove \r\n, which is added by the Out-String cmdlet.
                    return str.Substring(0, str.Length - 2);
                }
            }

            return String.Empty;
        }
开发者ID:monoman,项目名称:NugetCracker,代码行数:25,代码来源:RunspaceExtensions.cs

示例2: BeginInvoke

        /// <summary>
        /// Starts the pipeline script async.
        /// </summary>
        public void BeginInvoke(Queue<PSObject> queue, int count)
        {
            var input = new PSDataCollection<PSObject>(count);
            while (--count >= 0)
                input.Add(queue.Dequeue());
            input.Complete();

            _async = _posh.BeginInvoke(input);
        }
开发者ID:nightroman,项目名称:SplitPipeline,代码行数:12,代码来源:Job.cs

示例3: TestDebugOutput

 public void TestDebugOutput()
 {
     using (var ps = PowerShell.Create())
     {
         using (var rs = RunspaceFactory.CreateRunspace(_iss))
         {
             rs.Open();
             ps.Runspace = rs;
             ps.AddScript("$DebugPreference=[System.Management.Automation.ActionPreference]::Continue", false).Invoke();
             ps.Commands.Clear();
             ps.AddStatement()
                 .AddCommand("Invoke-Parallel", false)
                 .AddParameter("ScriptBlock", ScriptBlock.Create("Write-Debug $_"))
                 .AddParameter("ThrottleLimit", 1);
             var input = new PSDataCollection<int> { 1, 2, 3, 4, 5 };
             input.Complete();
             ps.Invoke<int>(input);
             Assert.IsFalse(ps.HadErrors, "We don't expect errors here");
             var dbg = ps.Streams.Debug.ReadAll();
             Assert.IsTrue(dbg.Any(d => d.Message == "1"), "Some debug message should be '1'");
         }
     }
 }
开发者ID:powercode,项目名称:PSParallel,代码行数:23,代码来源:InvokeParallelTests.cs

示例4: TestWarningOutput

 public void TestWarningOutput()
 {
     using (var ps = PowerShell.Create())
     {
         ps.RunspacePool = m_runspacePool;
         ps.AddScript("$WarningPreference='Continue'", false).Invoke();
         ps.Commands.Clear();
         ps.AddStatement()
             .AddCommand("Invoke-Parallel", false)
             .AddParameter("ScriptBlock", ScriptBlock.Create("Write-Warning $_"))
             .AddParameter("ThrottleLimit", 1);
         var input = new PSDataCollection<int> {1, 2, 3, 4, 5};
         input.Complete();
         ps.Invoke<int>(input);
         var wrn = ps.Streams.Warning.ReadAll();
         Assert.IsTrue(wrn.Any(w => w.Message == "1"), "Some warning message should be '1'");
     }
 }
开发者ID:powercode,项目名称:PSParallel,代码行数:18,代码来源:InvokeParallelTests.cs

示例5: TestVerboseOutput

 public void TestVerboseOutput()
 {
     using (var ps = PowerShell.Create())
     {
         ps.RunspacePool = m_runspacePool;
         ps.AddScript("$VerbosePreference=[System.Management.Automation.ActionPreference]::Continue", false).Invoke();
         ps.Commands.Clear();
         ps.AddStatement()
             .AddCommand("Invoke-Parallel", false)
             .AddParameter("ScriptBlock", ScriptBlock.Create("Write-Verbose $_"))
             .AddParameter("ThrottleLimit", 1);
         var input = new PSDataCollection<int> {1, 2, 3, 4, 5};
         input.Complete();
         ps.Invoke<int>(input);
         Assert.IsFalse(ps.HadErrors, "We don't expect errors here");
         var vrb = ps.Streams.Verbose.ReadAll();
         Assert.IsTrue(vrb.Any(v => v.Message == "1"), "Some verbose message should be '1'");
     }
 }
开发者ID:powercode,项目名称:PSParallel,代码行数:19,代码来源:InvokeParallelTests.cs

示例6: TestRecursiveFunctionCaptureOutput

        public void TestRecursiveFunctionCaptureOutput()
        {
            using (var ps = PowerShell.Create())
            {
                ps.RunspacePool = m_runspacePool;
                ps.AddScript(@"
            function foo($x) {return 2 * $x}
            function bar($x) {return 3 * (foo $x)}
            ", false);

                ps.AddStatement()
                    .AddCommand("Invoke-Parallel", false)
                    .AddParameter("ScriptBlock", ScriptBlock.Create("bar $_"))
                    .AddParameter("ThrottleLimit", 1)
                    .AddParameter("NoProgress");

                var input = new PSDataCollection<int> {1, 2, 3, 4, 5};
                input.Complete();
                var output = ps.Invoke<int>(input);
                var sum = output.Aggregate(0, (a, b) => a + b);
                Assert.AreEqual(90, sum);
            }
        }
开发者ID:powercode,项目名称:PSParallel,代码行数:23,代码来源:InvokeParallelTests.cs

示例7: TestProgressOutput2Workers

        public void TestProgressOutput2Workers()
        {
            using (var ps = PowerShell.Create())
            {
                ps.RunspacePool = m_runspacePool;
                ps.AddScript("$ProgressPreference='Continue'", false).Invoke();
                ps.AddStatement()
                    .AddCommand("Invoke-Parallel", false)
                    .AddParameter("ScriptBlock",
                        ScriptBlock.Create("Write-Progress -activity 'Test' -Status 'Status' -currentoperation $_"))
                    .AddParameter("ThrottleLimit", 2);

                var input = new PSDataCollection<int> { 1, 2, 3, 4, 5, 6, 7,8, 9,10  };
                input.Complete();
                ps.Invoke(input);
                var progress = ps.Streams.Progress.ReadAll();
                Assert.IsTrue(19 <= progress.Count(pr => pr.Activity == "Invoke-Parallel" || pr.Activity == "Test"));
            }
        }
开发者ID:powercode,项目名称:PSParallel,代码行数:19,代码来源:InvokeParallelTests.cs

示例8: ExtractErrorFromErrorRecord

        public string ExtractErrorFromErrorRecord(ErrorRecord record)
        {
            Pipeline pipeline = _runspace.CreatePipeline(command: "$input", addToHistory: false);
            pipeline.Commands.Add("out-string");

            Collection<PSObject> result;
            using (var inputCollection = new PSDataCollection<object>())
            {
                inputCollection.Add(record);
                inputCollection.Complete();
                result = InvokeCore(pipeline, inputCollection);
            }

            if (result.Count > 0)
            {
                string str = result[0].BaseObject as string;
                if (!string.IsNullOrEmpty(str))
                {
                    // Remove \r\n, which is added by the Out-String cmdlet.
                    return str.TrimEnd(new[] { '\r', '\n' });
                }
            }

            return String.Empty;
        }
开发者ID:Newtopian,项目名称:nuget,代码行数:25,代码来源:RunspaceDispatcher.cs

示例9: TestNoProgressOutput

        public void TestNoProgressOutput()
        {
            using (var ps = PowerShell.Create())
            {
                ps.RunspacePool = m_runspacePool;

                ps.AddStatement()
                    .AddCommand("Invoke-Parallel", false)
                    .AddParameter("ScriptBlock",
                        ScriptBlock.Create("Write-Progress -activity 'Test' -Status 'Status' -currentoperation $_"))
                    .AddParameter("ThrottleLimit", 1)
                    .AddParameter("NoProgress");

                var input = new PSDataCollection<int> {1, 2, 3, 4, 5};
                input.Complete();
                ps.Invoke(input);
                var progress = ps.Streams.Progress.ReadAll();
                Assert.IsFalse(progress.Any(pr => pr.Activity == "Invoke-Parallel"));
                Assert.AreEqual(5, progress.Count(pr => pr.Activity == "Test"));
            }
        }
开发者ID:powercode,项目名称:PSParallel,代码行数:21,代码来源:InvokeParallelTests.cs

示例10: TestNoErrorOutputWithoutPreference

 public void TestNoErrorOutputWithoutPreference()
 {
     using (var ps = PowerShell.Create())
     {
         ps.RunspacePool = m_runspacePool;
         ps.AddScript("$ErrorActionPreference='SilentlyContinue'", false).Invoke();
         ps.Commands.Clear();
         ps.AddStatement()
             .AddCommand("Invoke-Parallel", false)
             .AddParameter("ScriptBlock", ScriptBlock.Create("Write-Error -message $_ -TargetObject $_"))
             .AddParameter("ThrottleLimit", 1);
         var input = new PSDataCollection<int> {1, 2, 3, 4, 5};
         input.Complete();
         ps.Invoke<int>(input);
         var err = ps.Streams.Error.ReadAll();
         Assert.IsFalse(err.Any(e => e.Exception.Message == "1"), "No Error message should be '1'");
     }
 }
开发者ID:powercode,项目名称:PSParallel,代码行数:18,代码来源:InvokeParallelTests.cs

示例11: TestNoDebugOutputWithoutPreference

 public void TestNoDebugOutputWithoutPreference()
 {
     using (var ps = PowerShell.Create())
     {
         ps.RunspacePool = m_runspacePool;
         ps.Commands.Clear();
         ps.AddStatement()
             .AddCommand("Invoke-Parallel", false)
             .AddParameter("ScriptBlock", ScriptBlock.Create("Write-Debug $_"))
             .AddParameter("ThrottleLimit", 1);
         var input = new PSDataCollection<int> {1, 2, 3, 4, 5};
         input.Complete();
         ps.Invoke<int>(input);
         var dbg = ps.Streams.Debug.ReadAll();
         Assert.IsFalse(dbg.Any(d => d.Message == "1"), "No debug message should be '1'");
     }
 }
开发者ID:powercode,项目名称:PSParallel,代码行数:17,代码来源:InvokeParallelTests.cs

示例12: ProcessDebugCommand

            private DebuggerCommandResults ProcessDebugCommand(string cmd, out Exception e)
            {
                DebuggerCommandResults results = null;

                try
                {
                    _parent.DebuggerCanStopCommand = true;

                    // Use PowerShell object to write streaming data to host.
                    using (System.Management.Automation.PowerShell ps = System.Management.Automation.PowerShell.Create())
                    {
                        PSInvocationSettings settings = new PSInvocationSettings()
                        {
                            Host = _parent
                        };

                        PSDataCollection<PSObject> output = new PSDataCollection<PSObject>();
                        ps.AddCommand("Out-Default");
                        IAsyncResult async = ps.BeginInvoke<PSObject>(output, settings, null, null);

                        // Let debugger evaluate command and stream output data.
                        results = _parent.Runspace.Debugger.ProcessCommand(
                            new PSCommand(
                                new Command(cmd, true)),
                            output);

                        output.Complete();
                        ps.EndInvoke(async);
                    }

                    e = null;
                }
                catch (Exception ex)
                {
                    ConsoleHost.CheckForSevereException(ex);
                    e = ex;
                    results = new DebuggerCommandResults(null, false);
                }
                finally
                {
                    _parent.DebuggerCanStopCommand = false;
                }

                // Exit debugger if command fails to evaluate.
                return results ?? new DebuggerCommandResults(DebuggerResumeAction.Continue, false);
            }
开发者ID:dfinke,项目名称:powershell,代码行数:46,代码来源:ConsoleHost.cs

示例13: ContinueCommand

        internal static void ContinueCommand(RemoteRunspace remoteRunspace, Pipeline cmd, PSHost host, bool inDebugMode, System.Management.Automation.ExecutionContext context)
        {
            RemotePipeline remotePipeline = cmd as RemotePipeline;

            if (remotePipeline != null)
            {
                using (System.Management.Automation.PowerShell ps = System.Management.Automation.PowerShell.Create())
                {
                    PSInvocationSettings settings = new PSInvocationSettings()
                    {
                        Host = host
                    };

                    PSDataCollection<PSObject> input = new PSDataCollection<PSObject>();

                    CommandInfo commandInfo = new CmdletInfo("Out-Default", typeof(OutDefaultCommand), null, null, context);
                    Command outDefaultCommand = new Command(commandInfo);
                    ps.AddCommand(outDefaultCommand);
                    IAsyncResult async = ps.BeginInvoke<PSObject>(input, settings, null, null);

                    RemoteDebugger remoteDebugger = remoteRunspace.Debugger as RemoteDebugger;
                    if (remoteDebugger != null)
                    {
                        // Update client with breakpoint information from pushed runspace.
                        // Information will be passed to the client via the Debugger.BreakpointUpdated event.
                        remoteDebugger.SendBreakpointUpdatedEvents();

                        if (!inDebugMode)
                        {
                            // Enter debug mode if remote runspace is in debug stop mode.
                            remoteDebugger.CheckStateAndRaiseStopEvent();
                        }
                    }

                    // Wait for debugged cmd to complete.
                    while (!remotePipeline.Output.EndOfPipeline)
                    {
                        remotePipeline.Output.WaitHandle.WaitOne();
                        while (remotePipeline.Output.Count > 0)
                        {
                            input.Add(remotePipeline.Output.Read());
                        }
                    }

                    input.Complete();
                    ps.EndInvoke(async);
                }
            }
        }
开发者ID:40a,项目名称:PowerShell,代码行数:49,代码来源:PushRunspaceCommand.cs

示例14: ReportException

		/// <summary>
		///     To display an exception using the display formatter,
		///     run a second pipeline passing in the error record.
		///     The runtime will bind this to the $input variable,
		///     which is why $input is being piped to the Out-String
		///     cmdlet. The WriteErrorLine method is called to make sure
		///     the error gets displayed in the correct error color.
		/// </summary>
		/// <param name="e">The exception to display.</param>
		private void ReportException(Exception e)
		{
			if (e == null) return;
			var icer = e as IContainsErrorRecord;
			object error = icer != null ? icer.ErrorRecord : new ErrorRecord(e, "Host.ReportException", ErrorCategory.NotSpecified, null);

			lock (_instanceLock)
			{
				_currentPowerShell = PowerShell.Create();
			}

			_currentPowerShell.Runspace = _runspace;

			try
			{
				_currentPowerShell.AddScript("$input").AddCommand("out-string");

				// Do not merge errors, this function will swallow errors.
				var inputCollection = new PSDataCollection<object> {error};
				inputCollection.Complete();
				var result = _currentPowerShell.Invoke(inputCollection);

				if (result.Count > 0)
				{
					var str = result[0].BaseObject as string;
					if (!string.IsNullOrEmpty(str))
					{
						// Remove \r\n, which is added by the Out-String cmdlet.
						_host.UI.WriteErrorLine(str.Substring(0, str.Length - 2));
					}
				}
			}
			finally
			{
				// Dispose of the pipeline and set it to null, locking it  because 
				// currentPowerShell may be accessed by the ctrl-C handler.
				lock (_instanceLock)
				{
					_currentPowerShell.Dispose();
					_currentPowerShell = null;
				}
			}
		}
开发者ID:killbug2004,项目名称:PSExt,代码行数:52,代码来源:PSSession.cs

示例15: ReportException

        private void ReportException(Exception e)
        {
            if (e != null)
            {
                object error;
                IContainsErrorRecord icer = e as IContainsErrorRecord;
                if (icer != null)
                {
                    error = icer.ErrorRecord;
                }
                else
                {
                    error = (object)new ErrorRecord(e, "Host.ReportException", ErrorCategory.NotSpecified, null);
                }

                lock (this.instanceLock)
                {
                    this.currentPowerShell = PowerShell.Create();
                }

                this.currentPowerShell.Runspace = this.myRunSpace;

                try
                {
                    this.currentPowerShell.AddScript("$input").AddCommand("out-string");

                    Collection<PSObject> result;
                    PSDataCollection<object> inputCollection = new PSDataCollection<object>();
                    inputCollection.Add(error);
                    inputCollection.Complete();
                    result = this.currentPowerShell.Invoke(inputCollection);

                    if (result.Count > 0)
                    {
                        string str = result[0].BaseObject as string;
                        if (!string.IsNullOrEmpty(str))
                        { 
                            this.myHost.UI.WriteErrorLine(str.Substring(0, str.Length - 2));
                        }
                    }
                }
                finally
                {
                    lock (this.instanceLock)
                    {
                        this.currentPowerShell.Dispose();
                        this.currentPowerShell = null;
                    }
                }
            }
        }
开发者ID:lei720,项目名称:p0wnedShell,代码行数:51,代码来源:p0wnedListenerConsole.cs


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