@@ -33,91 +33,41 @@ internal PSOutputStreams(Worker worker)
3333 SetStreamHandlers ( ) ;
3434 }
3535
36+ internal void AddOutput ( PSOutputData data ) => OutputPipe . Add ( data ) ;
37+
3638 private void SetStreamHandlers ( )
3739 {
38- Success . DataAdded += ( s , e ) =>
39- {
40- foreach ( PSObject data in Success . ReadAll ( ) )
41- {
42- WriteObject ( data ) ;
43- }
44- } ;
45-
46- Error . DataAdded += ( s , e ) =>
47- {
48- foreach ( ErrorRecord error in Error . ReadAll ( ) )
49- {
50- WriteError ( error ) ;
51- }
52- } ;
53-
54- Debug . DataAdded += ( s , e ) =>
55- {
56- foreach ( DebugRecord debug in Debug . ReadAll ( ) )
57- {
58- WriteDebug ( debug ) ;
59- }
60- } ;
61-
62-
63- Information . DataAdded += ( s , e ) =>
64- {
65- foreach ( InformationRecord information in Information . ReadAll ( ) )
66- {
67- WriteInformation ( information ) ;
68- }
69- } ;
70-
71- Progress . DataAdded += ( s , e ) =>
72- {
73- foreach ( ProgressRecord progress in Progress . ReadAll ( ) )
74- {
75- WriteProgress ( progress ) ;
76- }
77- } ;
78-
79- Verbose . DataAdded += ( s , e ) =>
80- {
81- foreach ( VerboseRecord verbose in Verbose . ReadAll ( ) )
82- {
83- WriteVerbose ( verbose ) ;
84- }
85- } ;
86-
87- Warning . DataAdded += ( s , e ) =>
88- {
89- foreach ( WarningRecord warning in Warning . ReadAll ( ) )
90- {
91- WriteWarning ( warning ) ;
92- }
93- } ;
94- }
40+ Success . DataAdding += ( s , e ) =>
41+ AddOutput ( PSOutputData . WriteObject ( e . ItemAdded ) ) ;
9542
96- private void WriteObject ( PSObject data ) =>
97- OutputPipe . Add ( PSOutputData . WriteObject ( data ) , Token ) ;
43+ Error . DataAdding += ( s , e ) =>
44+ AddOutput ( PSOutputData . WriteError ( e . ItemAdded ) ) ;
9845
99- internal void WriteError ( ErrorRecord error ) =>
100- OutputPipe . Add ( PSOutputData . WriteError ( error ) , Token ) ;
46+ Debug . DataAdding += ( s , e ) =>
47+ AddOutput ( PSOutputData . WriteDebug ( e . ItemAdded ) ) ;
10148
102- private void WriteDebug ( DebugRecord debug ) =>
103- OutputPipe . Add ( PSOutputData . WriteDebug ( debug ) , Token ) ;
49+ Information . DataAdding += ( s , e ) =>
50+ AddOutput ( PSOutputData . WriteInformation ( e . ItemAdded ) ) ;
10451
105- private void WriteInformation ( InformationRecord information ) =>
106- OutputPipe . Add ( PSOutputData . WriteInformation ( information ) , Token ) ;
52+ Progress . DataAdding += ( s , e ) =>
53+ AddOutput ( PSOutputData . WriteProgress ( e . ItemAdded ) ) ;
10754
108- private void WriteProgress ( ProgressRecord progress ) =>
109- OutputPipe . Add ( PSOutputData . WriteProgress ( progress ) , Token ) ;
55+ Verbose . DataAdding += ( s , e ) =>
56+ AddOutput ( PSOutputData . WriteVerbose ( e . ItemAdded ) ) ;
11057
111- private void WriteVerbose ( VerboseRecord verbose ) =>
112- OutputPipe . Add ( PSOutputData . WriteVerbose ( verbose ) , Token ) ;
113-
114- private void WriteWarning ( WarningRecord warning ) =>
115- OutputPipe . Add ( PSOutputData . WriteWarning ( warning ) , Token ) ;
58+ Warning . DataAdding += ( s , e ) =>
59+ AddOutput ( PSOutputData . WriteWarning ( e . ItemAdded ) ) ;
60+ }
11661
11762 public void Dispose ( )
11863 {
11964 Success . Dispose ( ) ;
12065 Error . Dispose ( ) ;
66+ Debug . Dispose ( ) ;
67+ Information . Dispose ( ) ;
68+ Progress . Dispose ( ) ;
69+ Verbose . Dispose ( ) ;
70+ Warning . Dispose ( ) ;
12171 OutputPipe . Dispose ( ) ;
12272 GC . SuppressFinalize ( this ) ;
12373 }
0 commit comments