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


C# ErrorRecord.ToList方法代码示例

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


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

示例1: ExecutePipeline

        private Collection<PSObject> ExecutePipeline(ExecutionOptions options, Pipeline tempPipeline,
                                                     Collection<PSObject> collection, out IEnumerable<ErrorRecord> exceptionThrown)
        {
            exceptionThrown = null;
            try
            {
                bool acquired = Monitor.TryEnter(_runspace);
                if (! acquired)
                {
                    return null;
                }

                try
                {
                    _currentPipeline = tempPipeline;

                    IEnumerable<ErrorRecord> exception = null;
                    try
                    {
                        WaitWhileRunspaceIsBusy();

                        tempPipeline.StateChanged += OnPipelineStateChange;
                        try
                        {
                            ExecutePipeline(options, tempPipeline);
                        }
                        catch (PSInvalidOperationException ioe)
                        {
                            /*
                             * HACK: there seems to be some lag between the toggle of the runspace
                             * availability state and the clearing of the runspace's current
                             * pipeline state.  it's possible for the runspace to report it's available
                             * for use and then raise a PSInvalidOperationException indicating that another
                             * pipeline is currently executing.
                             * 
                             * This is a hacky way around the issue - wait 1/3 of a second for the 
                             * runspace state to clear and try again.
                             * 
                             * I've also tried adding a WaitWhilePipelineIsRunning method that spins
                             * on a DoWait while the pipeline is not in the completed or failed state;
                             * however this seems to slow the execution down considerably.  
                             */
                            if (tempPipeline.PipelineStateInfo.State == PipelineState.NotStarted)
                            {
                                Thread.Sleep(333);
                                ExecutePipeline(options, tempPipeline);
                            }
                        }
                        tempPipeline.Input.Close();

                        // WaitWhilePipelineIsRunning(tempPipeline);                    

                        collection = tempPipeline.Output.ReadToEnd();
                        if (null != tempPipeline.PipelineStateInfo.Reason)
                        {
                            throw tempPipeline.PipelineStateInfo.Reason;
                        }
                        exception = GetPipelineErrors(options, tempPipeline);
                    }
                    catch( RuntimeException re )
                    {
                        exception = new ErrorRecord[]{re.ErrorRecord};
                    }
                    catch( Exception e )
                    {
                        exception = new ErrorRecord[]
                                        {
                                            new ErrorRecord( e, e.GetType().FullName, ErrorCategory.NotSpecified, null), 
                                        };
                    }
                    finally
                    {
                        _currentPipeline = null;
                    }

                    if (null != exception)
                    {
                        if (!options.HasFlag(ExecutionOptions.DoNotRaisePipelineException))
                        {
                            exception.ToList().ForEach( RaisePipelineExceptionEvent );
                        }
                        exceptionThrown = exception;
                    }
                }
                finally
                {
                    Monitor.Exit(_runspace);
                }
            }
            catch (Exception ex)
            {
                exceptionThrown = new ErrorRecord[]
                                        {
                                            new ErrorRecord( ex, ex.GetType().FullName, ErrorCategory.NotSpecified, null), 
                                        };
            }
            return collection;
        }
开发者ID:wangchunlei,项目名称:MyGit,代码行数:98,代码来源:Executor.cs


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