예제 #1
0
파일: Pipe.cs 프로젝트: zuisom/PowerShell
        /// <summary>
        /// Writes a set of objects to the pipe.  This could recursively
        /// call to the downstream cmdlet, or write the objects to the
        /// external output.
        /// </summary>
        /// <param name="objects">
        /// Each of the objects are added to the pipe
        /// </param>
        /// <exception cref="PipelineStoppedException">
        /// The pipeline has already been stopped,
        /// or a terminating error occurred in a downstream cmdlet.
        /// </exception>
        /// <exception cref="PipelineClosedException">
        /// The ExternalWriter stream is closed
        /// </exception>
        internal void AddItems(object objects)
        {
            // Use the extended type system to try and get an enumerator for the object being added.
            // If we get an enumerator, then add the individual elements. If the object isn't
            // enumerable (i.e. the call returned null) then add the object to the pipe
            // as a single element.
            IEnumerator ie = LanguagePrimitives.GetEnumerator(objects);

            try
            {
                if (ie == null)
                {
                    Add(objects);
                }
                else
                {
                    while (ParserOps.MoveNext(_context, null, ie))
                    {
                        object o = ParserOps.Current(null, ie);

                        // Slip over any instance of AutomationNull.Value in the pipeline...
                        if (o == AutomationNull.Value)
                        {
                            continue;
                        }

                        Add(o);
                    }
                }
            }
            finally
            {
                // If our object came from GetEnumerator (and hence is not IEnumerator), then we need to dispose
                // Otherwise, we don't own the object, so don't dispose.
                var disposable = ie as IDisposable;
                if (disposable != null && objects is not IEnumerator)
                {
                    disposable.Dispose();
                }
            }

            if (_externalWriter != null)
            {
                return;
            }

            // If there are objects waiting for the downstream command
            // call it now
            if (_downstreamCmdlet != null && ObjectQueue != null && ObjectQueue.Count > OutBufferCount)
            {
                _downstreamCmdlet.DoExecute();
            }
        }
예제 #2
0
파일: Pipe.cs 프로젝트: zuisom/PowerShell
        /// <summary>
        /// Returns an object from the pipe. If pipe is empty returns null.
        /// This will try the ExternalReader if there are no queued objects.
        /// </summary>
        /// <returns>
        /// object that is retrieved, or AutomationNull.Value if none
        /// </returns>
        internal object Retrieve()
        {
            if (ObjectQueue != null && ObjectQueue.Count != 0)
            {
                return(ObjectQueue.Dequeue());
            }
            else if (_enumeratorToProcess != null)
            {
                if (_enumeratorToProcessIsEmpty)
                {
                    return(AutomationNull.Value);
                }

                if (!ParserOps.MoveNext(_context, null, _enumeratorToProcess))
                {
                    _enumeratorToProcessIsEmpty = true;
                    return(AutomationNull.Value);
                }

                return(ParserOps.Current(null, _enumeratorToProcess));
            }
            else if (ExternalReader != null)
            {
                try
                {
                    object o = ExternalReader.Read();
                    if (AutomationNull.Value == o)
                    {
                        // NOTICE-2004/06/08-JonN 963367
                        // The fix to this bug involves making one last
                        // attempt to read from the pipeline in DoComplete.
                        // We should be sure to not hit the ExternalReader
                        // again if it already reported completion.
                        ExternalReader = null;
                    }

                    return(o);
                }
                catch (PipelineClosedException)
                {
                    return(AutomationNull.Value);
                }
                catch (ObjectDisposedException)
                {
                    return(AutomationNull.Value);
                }
            }
            else
            {
                return(AutomationNull.Value);
            }
        }
예제 #3
0
 private void WriteOutIEnumerator(IEnumerator list)
 {
     if (list != null)
     {
         while (ParserOps.MoveNext(base.Context, null, list))
         {
             object sendToPipeline = ParserOps.Current(null, list);
             if (sendToPipeline != AutomationNull.Value)
             {
                 base.WriteObject(sendToPipeline);
             }
         }
     }
 }
예제 #4
0
파일: Pipe.cs 프로젝트: modulexcite/pash-1
        internal void AddItems(object objects)
        {
            IEnumerator enumerator = LanguagePrimitives.GetEnumerator(objects);

            try
            {
                object obj2;
                if (enumerator != null)
                {
                    goto Label_002A;
                }
                this.Add(objects);
                goto Label_0054;
Label_0013:
                obj2 = ParserOps.Current(null, enumerator);
                if (obj2 != AutomationNull.Value)
                {
                    this.Add(obj2);
                }
Label_002A:
                if (ParserOps.MoveNext(this._context, null, enumerator))
                {
                    goto Label_0013;
                }
            }
            finally
            {
                IDisposable disposable = enumerator as IDisposable;
                if ((disposable != null) && !(objects is IEnumerator))
                {
                    disposable.Dispose();
                }
            }
Label_0054:
            if (this._externalWriter != null)
            {
                return;
            }
            if (((this._downstreamCmdlet != null) && (this._objectQueue != null)) && (this._objectQueue.Count > this._outBufferCount))
            {
                this._downstreamCmdlet.DoExecute();
            }
        }
예제 #5
0
파일: Pipe.cs 프로젝트: modulexcite/pash-1
 internal object Retrieve()
 {
     if ((this._objectQueue != null) && (this._objectQueue.Count != 0))
     {
         return(this._objectQueue.Dequeue());
     }
     if (this._enumeratorToProcess != null)
     {
         if (this._enumeratorToProcessIsEmpty)
         {
             return(AutomationNull.Value);
         }
         if (!ParserOps.MoveNext(this._context, null, this._enumeratorToProcess))
         {
             this._enumeratorToProcessIsEmpty = true;
             return(AutomationNull.Value);
         }
         return(ParserOps.Current(null, this._enumeratorToProcess));
     }
     if (this.ExternalReader != null)
     {
         try
         {
             object obj2 = this.ExternalReader.Read();
             if (AutomationNull.Value == obj2)
             {
                 this.ExternalReader = null;
             }
             return(obj2);
         }
         catch (PipelineClosedException)
         {
             return(AutomationNull.Value);
         }
         catch (ObjectDisposedException)
         {
             return(AutomationNull.Value);
         }
     }
     return(AutomationNull.Value);
 }