Exemplo n.º 1
0
 private void WritePipelineCollection <T>(Collection <T> collection, PSStreamObjectType psStreamType)
 {
     foreach (var item in collection)
     {
         if (item != null)
         {
             AddToDebugBlockingCollection(new PSStreamObject(psStreamType, item));
         }
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// </summary>
 /// <param name="objectType"></param>
 /// <param name="value"></param>
 public PSStreamObject(PSStreamObjectType objectType, object value) :
     this(objectType, value, Guid.Empty)
 {
 }
Exemplo n.º 3
0
 internal PSStreamObject(PSStreamObjectType objectType, object value, Guid id)
 {
     ObjectType = objectType;
     Value      = value;
     Id         = id;
 }
Exemplo n.º 4
0
        private T InvokeCmdletMethodAndWaitForResults <T>(Func <Cmdlet, T> invokeCmdletMethodAndReturnResult, out Exception exceptionThrownOnCmdletThread)
        {
            T         methodResult = default(T);
            Exception closureSafeExceptionThrownOnCmdletThread = null;
            object    resultsLock = new object();
            EventHandler <JobStateEventArgs> handler2 = null;

            using (ManualResetEventSlim gotResultEvent = new ManualResetEventSlim(false))
            {
                if (handler2 == null)
                {
                    handler2 = delegate(object sender, JobStateEventArgs eventArgs) {
                        if (this.IsFinishedState(eventArgs.JobStateInfo.State) || (eventArgs.JobStateInfo.State == JobState.Stopping))
                        {
                            lock (resultsLock)
                            {
                                closureSafeExceptionThrownOnCmdletThread = new OperationCanceledException();
                            }
                            gotResultEvent.Set();
                        }
                    };
                }
                EventHandler <JobStateEventArgs> handler = handler2;
                this.StateChanged += handler;
                Thread.MemoryBarrier();
                try
                {
                    handler(null, new JobStateEventArgs(this.JobStateInfo));
                    if (!gotResultEvent.IsSet)
                    {
                        this.SetJobState(JobState.Blocked);
                        CmdletMethodInvoker <T> invoker = new CmdletMethodInvoker <T> {
                            Action     = invokeCmdletMethodAndReturnResult,
                            Finished   = gotResultEvent,
                            SyncObject = resultsLock
                        };
                        PSStreamObjectType shouldMethod = PSStreamObjectType.ShouldMethod;
                        if (typeof(T) == typeof(object))
                        {
                            shouldMethod = PSStreamObjectType.BlockingError;
                        }
                        this.Results.Add(new PSStreamObject(shouldMethod, invoker));
                        gotResultEvent.Wait();
                        this.SetJobState(JobState.Running);
                        lock (resultsLock)
                        {
                            if (closureSafeExceptionThrownOnCmdletThread == null)
                            {
                                closureSafeExceptionThrownOnCmdletThread = invoker.ExceptionThrownOnCmdletThread;
                                methodResult = invoker.MethodResult;
                            }
                        }
                    }
                }
                finally
                {
                    this.StateChanged -= handler;
                }
            }
            lock (resultsLock)
            {
                exceptionThrownOnCmdletThread = closureSafeExceptionThrownOnCmdletThread;
                return(methodResult);
            }
        }
Exemplo n.º 5
0
 internal PSStreamObject(PSStreamObjectType objectType, object value, Guid id)
 {
     this.ObjectType = objectType;
     this.Value      = value;
     this.Id         = id;
 }
Exemplo n.º 6
0
 internal PSStreamObject(PSStreamObjectType objectType, object value) : this(objectType, value, Guid.Empty)
 {
 }
Exemplo n.º 7
0
 internal PSStreamObject(PSStreamObjectType objectType, object value)
 {
     this.objectType = objectType;
     this.value      = value;
 }