18
18
using System . ComponentModel ;
19
19
using System . Diagnostics . Tracing ;
20
20
using System . Net . Http ;
21
- using System . Threading ;
22
21
using System . Threading . Tasks ;
23
- using GetEventData = System . Func < Microsoft . Azure . Commands . Common . EventData > ;
24
22
25
23
26
24
namespace Microsoft . Azure . Commands . Common
27
25
{
28
26
29
27
30
- using EventListenerDelegate = Func < EventData , Task > ;
31
- using GetParameterDelegate = Func < string , Dictionary < string , object > , string , object > ;
32
- using SendAsyncStep = Func < HttpRequestMessage , IEventListener , ISendAsync , Task < HttpResponseMessage > > ;
33
- using PipelineChangeDelegate = Action < EventData > ;
28
+ using EventListenerDelegate = Func < EventData , Task > ;
29
+ using GetParameterDelegate = Func < string , Dictionary < string , object > , string , object > ;
30
+ using SendAsyncStep = Func < HttpRequestMessage , IEventListener , ISendAsync , Task < HttpResponseMessage > > ;
31
+ using PipelineChangeDelegate = Action < EventData > ;
34
32
35
- /// <summary>
36
- /// The IEventListener Interface defines the communication mechanism for Signaling events during a remote call.
37
- /// </summary>
38
- /// <remarks>
39
- /// The interface is designed to be as minimal as possible, allow for quick peeking of the event type (<c>id</c>)
40
- /// and the cancellation status and provides a delegate for retrieving the event details themselves.
41
- /// </remarks>
42
- public interface IEventListener
43
- {
44
- Task Signal ( string id , CancellationToken token , GetEventData createMessage ) ;
45
- CancellationToken Token { get ; }
46
- System . Action Cancel { get ; }
47
- }
48
-
49
- public class Response : EventData
50
- {
51
- public Response ( ) : base ( )
52
- {
53
- }
54
- }
55
-
56
- public class Response < T > : Response
57
- {
58
- private Func < Task < T > > _resultDelegate ;
59
- private Task < T > _resultValue ;
60
-
61
- public Response ( T value ) : base ( ) => _resultValue = Task . FromResult ( value ) ;
62
- public Response ( Func < T > value ) : base ( ) => _resultDelegate = ( ) => Task . FromResult ( value ( ) ) ;
63
- public Response ( Func < Task < T > > value ) : base ( ) => _resultDelegate = value ;
64
- public Task < T > Result => _resultValue ?? ( _resultValue = this . _resultDelegate ( ) ) ;
65
- }
66
-
67
-
68
- /// <summary>
69
- /// The interface for sending an HTTP request across the wire.
70
- /// </summary>
71
- public interface ISendAsync
72
- {
73
- Task < HttpResponseMessage > SendAsync ( HttpRequestMessage request , IEventListener callback ) ;
74
- }
75
33
76
34
77
-
78
- [ TypeConverter ( typeof ( EventDataConverter ) ) ]
35
+ [ TypeConverter ( typeof ( EventDataConverter ) ) ]
79
36
/// <remarks>
80
37
/// In PowerShell, we add on the EventDataConverter to support sending events between modules.
81
38
/// Obviously, this code would need to be duplcated on both modules.
@@ -135,6 +92,38 @@ public partial class EventData : EventArgs
135
92
/// </summary>
136
93
public object ResponseMessage ;
137
94
95
+ /// <summary>
96
+ /// The name of the cmdlet that is being executed
97
+ /// </summary>
98
+ public string CmdletName ;
99
+
100
+ /// <summary>
101
+ /// Correlation Id for cmdlet invocation
102
+ /// </summary>
103
+ public string CmdletInvocationId ;
104
+
105
+ /// <summary>
106
+ ///
107
+ /// </summary>
108
+ public string ProcessRecordId ;
109
+
110
+ /// <summary>
111
+ ///
112
+ /// </summary>
113
+ public string ParameterSet ;
114
+
115
+ /// <summary>
116
+ ///
117
+ /// </summary>
118
+ public string RequestCorrelationId ;
119
+
120
+ /// <summary>
121
+ /// The 'this.MyInvocation.BoundParameters' from the cmdlet
122
+ /// </summary>
123
+ public System . Collections . Generic . IDictionary < string , object > BoundParamters ;
124
+
125
+ public System . Exception Exception ;
126
+
138
127
/// <summary>
139
128
/// Cancellation method for this event.
140
129
///
@@ -146,81 +135,4 @@ public partial class EventData : EventArgs
146
135
public System . Action Cancel ;
147
136
}
148
137
149
- /// <summary>
150
- /// A PowerShell PSTypeConverter to adapt an <c>EventData</c> object that has been passed.
151
- /// Usually used between modules.
152
- /// </summary>
153
- public class EventDataConverter : System . Management . Automation . PSTypeConverter
154
- {
155
- public override bool CanConvertTo ( object sourceValue , Type destinationType ) => false ;
156
- public override object ConvertTo ( object sourceValue , Type destinationType , IFormatProvider formatProvider , bool ignoreCase ) => null ;
157
- public override bool CanConvertFrom ( dynamic sourceValue , Type destinationType ) => destinationType == typeof ( EventData ) && CanConvertFrom ( sourceValue ) ;
158
- public override object ConvertFrom ( dynamic sourceValue , Type destinationType , IFormatProvider formatProvider , bool ignoreCase ) => ConvertFrom ( sourceValue ) ;
159
-
160
- public static bool CanConvertFrom ( dynamic sv )
161
- {
162
- var result = true ;
163
- try
164
- {
165
- // check if this has required parameters...
166
- sv ? . Id ? . GetType ( ) ;
167
- sv ? . Message ? . GetType ( ) ;
168
- sv ? . Parameter ? . GetType ( ) ;
169
- sv ? . Value ? . GetType ( ) ;
170
- sv ? . RequestMessage ? . GetType ( ) ;
171
- sv ? . ResponseMessage ? . GetType ( ) ;
172
- sv ? . Cancel ? . GetType ( ) ;
173
- }
174
- catch
175
- {
176
- return false ;
177
- }
178
- return result ;
179
- }
180
-
181
- public static EventData ConvertFrom ( dynamic sv )
182
- {
183
- try
184
- {
185
- return new EventData
186
- {
187
- Id = sv . Id ,
188
- Message = sv . Message ,
189
- Parameter = sv . Parameter ,
190
- Value = sv . Value ,
191
- RequestMessage = sv . RequestMessage ,
192
- ResponseMessage = sv . ResponseMessage ,
193
- Cancel = sv . Cancel
194
- } ;
195
- }
196
- catch
197
- {
198
- }
199
- return null ;
200
- }
201
- }
202
- public static class Events
203
- {
204
- public const string Log = nameof ( Log ) ;
205
- public const string Validation = nameof ( Validation ) ;
206
- public const string ValidationWarning = nameof ( ValidationWarning ) ;
207
- public const string AfterValidation = nameof ( AfterValidation ) ;
208
- public const string RequestCreated = nameof ( RequestCreated ) ;
209
- public const string ResponseCreated = nameof ( ResponseCreated ) ;
210
- public const string URLCreated = nameof ( URLCreated ) ;
211
- public const string Finally = nameof ( Finally ) ;
212
- public const string HeaderParametersAdded = nameof ( HeaderParametersAdded ) ;
213
- public const string BodyContentSet = nameof ( BodyContentSet ) ;
214
- public const string BeforeCall = nameof ( BeforeCall ) ;
215
- public const string BeforeResponseDispatch = nameof ( BeforeResponseDispatch ) ;
216
- public const string CmdletProcessRecordStart = nameof ( CmdletProcessRecordStart ) ;
217
- public const string CmdletException = nameof ( CmdletException ) ;
218
- public const string CmdletGetPipeline = nameof ( CmdletGetPipeline ) ;
219
- public const string CmdletBeforeAPICall = nameof ( CmdletBeforeAPICall ) ;
220
- public const string CmdletAfterAPICall = nameof ( CmdletAfterAPICall ) ;
221
- public const string FollowingNextLink = nameof ( FollowingNextLink ) ;
222
- public const string DelayBeforePolling = nameof ( DelayBeforePolling ) ;
223
- public const string Polling = nameof ( Polling ) ;
224
- }
225
-
226
138
}
0 commit comments