Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes308downloads
IObjectReader.cs181 linesDownload Raw Back to utils
1// Copyright (c) Microsoft Corporation.2// Licensed under the MIT License.3 4using System.Collections.Generic;5using System.Collections.ObjectModel;6using System.Threading;7 8namespace System.Management.Automation.Runspaces9{10    /// <summary>11    /// PipelineReader provides asynchronous access to the stream of objects emitted by12    /// a <see cref="System.Management.Automation.Runspaces.Pipeline"/>.13    /// </summary>14    /// <seealso cref="System.Management.Automation.Runspaces.Pipeline.Output"/>15    /// <seealso cref="System.Management.Automation.Runspaces.Pipeline.Error"/>16    public abstract class PipelineReader<T>17    {18        /// <summary>19        /// Event fired when data is added to the buffer.20        /// </summary>21        public abstract event EventHandler DataReady;22 23        /// <summary>24        /// Signaled when data is available.25        /// </summary>26        public abstract WaitHandle WaitHandle27        {28            get;29        }30 31        /// <summary>32        /// Check if the stream is closed and contains no data.33        /// </summary>34        /// <value>True if the stream is closed and contains no data, otherwise false</value>35        /// <remarks>36        /// Attempting to read from the underlying stream if EndOfPipeline is true returns37        /// zero objects.38        /// </remarks>39        public abstract bool EndOfPipeline40        {41            get;42        }43 44        /// <summary>45        /// Check if the stream is open for further writes.46        /// </summary>47        /// <value>true if the underlying stream is open, otherwise false</value>48        /// <remarks>49        /// The underlying stream may be readable after it is closed if data remains in the50        /// internal buffer. Check <see cref="EndOfPipeline"/> to determine if51        /// the underlying stream is closed and contains no data.52        /// </remarks>53        public abstract bool IsOpen54        {55            get;56        }57 58        /// <summary>59        /// Returns the number of objects currently available in the underlying stream.60        /// </summary>61        public abstract int Count62        {63            get;64        }65 66        /// <summary>67        /// Get the capacity of the stream.68        /// </summary>69        /// <value>70        /// The capacity of the stream.71        /// </value>72        /// <remarks>73        /// The capacity is the number of objects that stream may contain at one time.  Once this74        /// limit is reached, attempts to write into the stream block until buffer space75        /// becomes available.76        /// </remarks>77        public abstract int MaxCapacity78        {79            get;80        }81 82        /// <summary>83        /// Close the stream.84        /// </summary>85        /// <remarks>86        /// Causes subsequent calls to IsOpen to return false and calls to87        /// a write operation to throw an PipelineClosedException.88        /// All calls to Close() after the first call are silently ignored.89        /// </remarks>90        /// <exception cref="PipelineClosedException">91        /// The stream is already disposed92        /// </exception>93        public abstract void Close();94 95        /// <summary>96        /// Read at most <paramref name="count"/> objects.97        /// </summary>98        /// <param name="count">The maximum number of objects to read.</param>99        /// <returns>The objects read.</returns>100        /// <remarks>101        /// This method blocks if the number of objects in the stream is less than <paramref name="count"/>102        /// and the stream is not closed.103        /// </remarks>104        public abstract Collection<T> Read(int count);105 106        /// <summary>107        /// Read a single object from the stream.108        /// </summary>109        /// <returns>The next object in the stream.</returns>110        /// <remarks>This method blocks if the stream is empty</remarks>111        public abstract T Read();112 113        /// <summary>114        /// Blocks until the pipeline closes and reads all objects.115        /// </summary>116        /// <returns>A collection of zero or more objects.</returns>117        /// <remarks>118        /// If the stream is empty, an empty collection is returned.119        /// </remarks>120        public abstract Collection<T> ReadToEnd();121 122        /// <summary>123        /// Reads all objects currently in the stream, but does not block.124        /// </summary>125        /// <returns>A collection of zero or more objects.</returns>126        /// <remarks>127        /// This method performs a read of all objects currently in the128        /// stream.  If there are no objects in the stream,129        /// an empty collection is returned.130        /// </remarks>131        public abstract Collection<T> NonBlockingRead();132 133        // 892370-2003/10/29-JonN added this method134        /// <summary>135        /// Reads objects currently in the stream, but does not block.136        /// </summary>137        /// <returns>A collection of zero or more objects.</returns>138        /// <remarks>139        /// This method performs a read of objects currently in the140        /// stream.  If there are no objects in the stream,141        /// an empty collection is returned.142        /// </remarks>143        /// <param name="maxRequested">144        /// Return no more than maxRequested objects.145        /// </param>146        public abstract Collection<T> NonBlockingRead(int maxRequested);147 148        /// <summary>149        /// Peek the next object, but do not remove it from the stream.  Non-blocking.150        /// </summary>151        /// <returns>152        /// The next object in the stream or AutomationNull.Value if the stream is empty153        /// </returns>154        /// <exception cref="PipelineClosedException">The stream is closed.</exception>155        public abstract T Peek();156 157        #region IEnumerable<T> Members158 159        /// <summary>160        /// Returns an enumerator that reads the items in the pipeline.161        /// </summary>162        internal IEnumerator<T> GetReadEnumerator()163        {164            while (!this.EndOfPipeline)165            {166                T t = this.Read();167                if (object.Equals(t, System.Management.Automation.Internal.AutomationNull.Value))168                {169                    yield break;170                }171                else172                {173                    yield return t;174                }175            }176        }177 178        #endregion179    }180}181