/
ManagementEventArgs.cs
311 lines (280 loc) · 10.1 KB
/
ManagementEventArgs.cs
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
namespace System.Management
{
internal sealed class IdentifierChangedEventArgs : EventArgs
{
internal IdentifierChangedEventArgs() { }
}
internal sealed class InternalObjectPutEventArgs : EventArgs
{
private readonly ManagementPath path;
internal InternalObjectPutEventArgs(ManagementPath path)
{
this.path = path.Clone();
}
internal ManagementPath Path
{
get { return path; }
}
}
/// <summary>
/// <para>Represents the virtual base class to hold event data for WMI events.</para>
/// </summary>
public abstract class ManagementEventArgs : EventArgs
{
private readonly object context;
/// <summary>
/// Constructor. This is not callable directly by applications.
/// </summary>
/// <param name="context">The operation context which is echoed back
/// from the operation which trigerred the event.</param>
internal ManagementEventArgs(object context)
{
this.context = context;
}
/// <summary>
/// <para> Gets the operation context echoed back
/// from the operation that triggered the event.</para>
/// </summary>
/// <value>
/// A WMI context object containing
/// context information provided by the operation that triggered the event.
/// </value>
public object Context
{
get { return context; }
}
}
/// <summary>
/// <para>Holds event data for the <see cref='System.Management.ManagementOperationObserver.ObjectReady'/> event.</para>
/// </summary>
public class ObjectReadyEventArgs : ManagementEventArgs
{
private readonly ManagementBaseObject wmiObject;
/// <summary>
/// Constructor.
/// </summary>
/// <param name="context">The operation context which is echoed back
/// from the operation which triggered the event.</param>
/// <param name="wmiObject">The newly arrived WmiObject.</param>
internal ObjectReadyEventArgs(object context, ManagementBaseObject wmiObject) : base(context)
{
this.wmiObject = wmiObject;
}
/// <summary>
/// <para> Gets the newly-returned object.</para>
/// </summary>
/// <value>
/// <para>A <see cref='System.Management.ManagementBaseObject'/> representing the
/// newly-returned object.</para>
/// </value>
public ManagementBaseObject NewObject
{
get
{
return wmiObject;
}
}
}
/// <summary>
/// <para> Holds event data for the <see cref='System.Management.ManagementOperationObserver.Completed'/> event.</para>
/// </summary>
public class CompletedEventArgs : ManagementEventArgs
{
private readonly int status;
private readonly ManagementBaseObject wmiObject;
/// <summary>
/// Constructor.
/// </summary>
/// <param name="context">The operation context which is echoed back
/// from the operation which trigerred the event.</param>
/// <param name="status">The completion status of the operation.</param>
/// <param name="wmiStatusObject">Additional status information
/// encapsulated within a WmiObject. This may be null.</param>
internal CompletedEventArgs(object context, int status, ManagementBaseObject wmiStatusObject) : base(context)
{
wmiObject = wmiStatusObject;
this.status = status;
}
/// <summary>
/// <para>Gets or sets additional status information
/// within a WMI object. This may be null.</para>
/// </summary>
/// <value>
/// <para><see langword='null '/> if an error did not occur. Otherwise, may be non-null if the provider
/// supports extended error information.</para>
/// </value>
public ManagementBaseObject StatusObject
{
get
{
return wmiObject;
}
}
/// <summary>
/// <para>Gets the completion status of the operation.</para>
/// </summary>
/// <value>
/// <para>A <see cref='System.Management.ManagementStatus'/> value
/// indicating the return code of the operation.</para>
/// </value>
public ManagementStatus Status
{
get
{
return (ManagementStatus)status;
}
}
}
/// <summary>
/// <para>Holds event data for the <see cref='System.Management.ManagementOperationObserver.ObjectPut'/> event.</para>
/// </summary>
public class ObjectPutEventArgs : ManagementEventArgs
{
private readonly ManagementPath wmiPath;
/// <summary>
/// Constructor
/// </summary>
/// <param name="context">The operation context which is echoed back
/// from the operation which trigerred the event.</param>
/// <param name="path">The WmiPath representing the identity of the
/// object that has been put.</param>
internal ObjectPutEventArgs(object context, ManagementPath path) : base(context)
{
wmiPath = path;
}
/// <summary>
/// <para> Gets the identity of the
/// object that has been put.</para>
/// </summary>
/// <value>
/// <para>A <see cref='System.Management.ManagementPath'/> containing the path of the object that has
/// been put.</para>
/// </value>
public ManagementPath Path
{
get
{
return wmiPath;
}
}
}
/// <summary>
/// <para>Holds event data for the <see cref='System.Management.ManagementOperationObserver.Progress'/> event.</para>
/// </summary>
public class ProgressEventArgs : ManagementEventArgs
{
private readonly int upperBound;
private readonly int current;
private readonly string message;
/// <summary>
/// Constructor
/// </summary>
/// <param name="context">The operation context which is echoed back
/// from the operation which trigerred the event.</param>
/// <param name="upperBound">A quantity representing the total
/// amount of work required to be done by the operation.</param>
/// <param name="current">A quantity representing the current
/// amount of work required to be done by the operation. This is
/// always less than or equal to upperBound.</param>
/// <param name="message">Optional additional information regarding
/// operation progress.</param>
internal ProgressEventArgs(object context, int upperBound, int current, string message) : base(context)
{
this.upperBound = upperBound;
this.current = current;
this.message = message;
}
/// <summary>
/// <para> Gets the total
/// amount of work required to be done by the operation.</para>
/// </summary>
/// <value>
/// An integer representing the total
/// amount of work for the operation.
/// </value>
public int UpperBound
{
get
{
return upperBound;
}
}
/// <summary>
/// <para> Gets the current amount of work
/// done by the operation. This is always less than or equal to <see cref='System.Management.ProgressEventArgs.UpperBound'/>.</para>
/// </summary>
/// <value>
/// <para>An integer representing the current amount of work
/// already completed by the operation.</para>
/// </value>
public int Current
{
get
{
return current;
}
}
/// <summary>
/// <para>Gets or sets optional additional information regarding the operation's progress.</para>
/// </summary>
/// <value>
/// A string containing additional
/// information regarding the operation's progress.
/// </value>
public string Message
{
get
{
return message ?? string.Empty;
}
}
}
/// <summary>
/// <para>Holds event data for the <see cref='System.Management.ManagementEventWatcher.EventArrived'/> event.</para>
/// </summary>
public class EventArrivedEventArgs : ManagementEventArgs
{
private readonly ManagementBaseObject eventObject;
internal EventArrivedEventArgs(object context, ManagementBaseObject eventObject) : base(context)
{
this.eventObject = eventObject;
}
/// <summary>
/// <para> Gets the WMI event that was delivered.</para>
/// </summary>
/// <value>
/// The object representing the WMI event.
/// </value>
public ManagementBaseObject NewEvent
{
get { return this.eventObject; }
}
}
/// <summary>
/// <para>Holds event data for the <see cref='System.Management.ManagementEventWatcher.Stopped'/> event.</para>
/// </summary>
public class StoppedEventArgs : ManagementEventArgs
{
private readonly int status;
internal StoppedEventArgs(object context, int status) : base(context)
{
this.status = status;
}
/// <summary>
/// <para> Gets the completion status of the operation.</para>
/// </summary>
/// <value>
/// <para>A <see cref='System.Management.ManagementStatus'/> value representing the status of the
/// operation.</para>
/// </value>
public ManagementStatus Status
{
get
{
return (ManagementStatus)status;
}
}
}
}