File size: 8,413 Bytes
8c763fb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 | // Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
namespace System.Management.Automation
{
/// <summary>
/// Define all the output streams and one input stream for a workflow.
/// </summary>
public sealed class PowerShellStreams<TInput, TOutput> : IDisposable
{
/// <summary>
/// Input stream for incoming objects.
/// </summary>
private PSDataCollection<TInput> _inputStream;
/// <summary>
/// Output stream for returned objects.
/// </summary>
private PSDataCollection<TOutput> _outputStream;
/// <summary>
/// Error stream for error messages.
/// </summary>
private PSDataCollection<ErrorRecord> _errorStream;
/// <summary>
/// Warning stream for warning messages.
/// </summary>
private PSDataCollection<WarningRecord> _warningStream;
/// <summary>
/// Progress stream for progress messages.
/// </summary>
private PSDataCollection<ProgressRecord> _progressStream;
/// <summary>
/// Verbose stream for verbose messages.
/// </summary>
private PSDataCollection<VerboseRecord> _verboseStream;
/// <summary>
/// Debug stream for debug messages.
/// </summary>
private PSDataCollection<DebugRecord> _debugStream;
/// <summary>
/// Information stream for Information messages.
/// </summary>
private PSDataCollection<InformationRecord> _informationStream;
/// <summary>
/// If the object is already disposed or not.
/// </summary>
private bool _disposed;
/// <summary>
/// Private object for thread-safe execution.
/// </summary>
private readonly object _syncLock = new object();
/// <summary>
/// Default constructor.
/// </summary>
public PowerShellStreams()
{
_inputStream = null;
_outputStream = null;
_errorStream = null;
_warningStream = null;
_progressStream = null;
_verboseStream = null;
_debugStream = null;
_informationStream = null;
_disposed = false;
}
/// <summary>
/// Default constructor.
/// </summary>
public PowerShellStreams(PSDataCollection<TInput> pipelineInput)
{
// Populate the input collection if there is any...
_inputStream = pipelineInput ?? new PSDataCollection<TInput>();
_inputStream.Complete();
_outputStream = new PSDataCollection<TOutput>();
_errorStream = new PSDataCollection<ErrorRecord>();
_warningStream = new PSDataCollection<WarningRecord>();
_progressStream = new PSDataCollection<ProgressRecord>();
_verboseStream = new PSDataCollection<VerboseRecord>();
_debugStream = new PSDataCollection<DebugRecord>();
_informationStream = new PSDataCollection<InformationRecord>();
_disposed = false;
}
/// <summary>
/// Dispose implementation.
/// </summary>
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}
/// <summary>
/// Protected virtual implementation of Dispose.
/// </summary>
/// <param name="disposing"></param>
private void Dispose(bool disposing)
{
if (_disposed)
return;
lock (_syncLock)
{
if (!_disposed)
{
if (disposing)
{
_inputStream.Dispose();
_outputStream.Dispose();
_errorStream.Dispose();
_warningStream.Dispose();
_progressStream.Dispose();
_verboseStream.Dispose();
_debugStream.Dispose();
_informationStream.Dispose();
_inputStream = null;
_outputStream = null;
_errorStream = null;
_warningStream = null;
_progressStream = null;
_verboseStream = null;
_debugStream = null;
_informationStream = null;
}
_disposed = true;
}
}
}
/// <summary>
/// Gets input stream.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public PSDataCollection<TInput> InputStream
{
get { return _inputStream; }
set { _inputStream = value; }
}
/// <summary>
/// Gets output stream.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public PSDataCollection<TOutput> OutputStream
{
get { return _outputStream; }
set { _outputStream = value; }
}
/// <summary>
/// Gets error stream.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public PSDataCollection<ErrorRecord> ErrorStream
{
get { return _errorStream; }
set { _errorStream = value; }
}
/// <summary>
/// Gets warning stream.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public PSDataCollection<WarningRecord> WarningStream
{
get { return _warningStream; }
set { _warningStream = value; }
}
/// <summary>
/// Gets progress stream.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public PSDataCollection<ProgressRecord> ProgressStream
{
get { return _progressStream; }
set { _progressStream = value; }
}
/// <summary>
/// Gets verbose stream.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public PSDataCollection<VerboseRecord> VerboseStream
{
get { return _verboseStream; }
set { _verboseStream = value; }
}
/// <summary>
/// Get debug stream.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public PSDataCollection<DebugRecord> DebugStream
{
get { return _debugStream; }
set { _debugStream = value; }
}
/// <summary>
/// Gets Information stream.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public PSDataCollection<InformationRecord> InformationStream
{
get { return _informationStream; }
set { _informationStream = value; }
}
/// <summary>
/// Marking all the streams as completed so that no further data can be added and
/// jobs will know that there is no more data coming in.
/// </summary>
public void CloseAll()
{
if (!_disposed)
{
lock (_syncLock)
{
if (!_disposed)
{
_outputStream.Complete();
_errorStream.Complete();
_warningStream.Complete();
_progressStream.Complete();
_verboseStream.Complete();
_debugStream.Complete();
_informationStream.Complete();
}
}
}
}
}
}
|