forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInformationalRecord.cs
More file actions
267 lines (241 loc) · 8.6 KB
/
Copy pathInformationalRecord.cs
File metadata and controls
267 lines (241 loc) · 8.6 KB
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
/********************************************************************++
* Copyright (c) Microsoft Corporation. All rights reserved.
* --********************************************************************/
using System.Collections;
using System.Collections.ObjectModel;
using System.Runtime.Serialization;
namespace System.Management.Automation
{
/// <summary>
/// Base class for items in the PSInformationalBuffers.
///
/// A PSInformationalRecord consists of a string Message and the InvocationInfo and pipeline state corresponding
/// to the command that created the record.
/// </summary>
[DataContract()]
public abstract class InformationalRecord
{
/// <remarks>
/// This class can be instantiated only by its derived classes
/// </remarks>
internal InformationalRecord(string message)
{
_message = message;
_invocationInfo = null;
_pipelineIterationInfo = null;
_serializeExtendedInfo = false;
}
/// <summary>
/// Creates an InformationalRecord object from a record serialized as a PSObject by ToPSObjectForRemoting.
/// </summary>
internal InformationalRecord(PSObject serializedObject)
{
_message = (string)SerializationUtilities.GetPropertyValue(serializedObject, "InformationalRecord_Message");
_serializeExtendedInfo = (bool)SerializationUtilities.GetPropertyValue(serializedObject, "InformationalRecord_SerializeInvocationInfo");
if (_serializeExtendedInfo)
{
_invocationInfo = new InvocationInfo(serializedObject);
ArrayList pipelineIterationInfo = (ArrayList)SerializationUtilities.GetPsObjectPropertyBaseObject(serializedObject, "InformationalRecord_PipelineIterationInfo");
_pipelineIterationInfo = new ReadOnlyCollection<int>((int[])pipelineIterationInfo.ToArray(typeof(int)));
}
else
{
_invocationInfo = null;
}
}
/// <summary>
/// The message written by the command that created this record
/// </summary>
public string Message
{
get
{
return _message;
}
set { _message = value; }
}
/// <summary>
/// The InvocationInfo of the command that created this record
/// </summary>
/// <remarks>
/// The InvocationInfo can be null if the record was not created by a command.
/// </remarks>
public InvocationInfo InvocationInfo
{
get
{
return _invocationInfo;
}
}
/// <summary>
/// The status of the pipeline when this record was created.
/// </summary>
/// <remarks>
/// The PipelineIterationInfo can be null if the record was not created by a command.
/// </remarks>
public ReadOnlyCollection<int> PipelineIterationInfo
{
get
{
return _pipelineIterationInfo;
}
}
/// <summary>
/// Sets the InvocationInfo (and PipelineIterationInfo) for this record
/// </summary>
internal void SetInvocationInfo(InvocationInfo invocationInfo)
{
_invocationInfo = invocationInfo;
//
// Copy a snapshot of the PipelineIterationInfo from the InvocationInfo to this InformationalRecord
//
if (invocationInfo.PipelineIterationInfo != null)
{
int[] snapshot = (int[])invocationInfo.PipelineIterationInfo.Clone();
_pipelineIterationInfo = new ReadOnlyCollection<int>(snapshot);
}
}
/// <summary>
/// Whether to serialize the InvocationInfo and PipelineIterationInfo during remote calls
/// </summary>
internal bool SerializeExtendedInfo
{
get
{
return _serializeExtendedInfo;
}
set
{
_serializeExtendedInfo = value;
}
}
/// <summary>
/// Returns the record's message
/// </summary>
public override string ToString()
{
return this.Message;
}
/// <summary>
/// Adds the information about this informational record to a PSObject as note properties.
/// The PSObject is used to serialize the record during remote operations.
/// </summary>
internal virtual void ToPSObjectForRemoting(PSObject psObject)
{
RemotingEncoder.AddNoteProperty<string>(psObject, "InformationalRecord_Message", () => this.Message);
//
// The invocation info may be null if the record was created via WriteVerbose/Warning/DebugLine instead of WriteVerbose/Warning/Debug, in that case
// we set InformationalRecord_SerializeInvocationInfo to false.
//
if (!this.SerializeExtendedInfo || _invocationInfo == null)
{
RemotingEncoder.AddNoteProperty(psObject, "InformationalRecord_SerializeInvocationInfo", () => false);
}
else
{
RemotingEncoder.AddNoteProperty(psObject, "InformationalRecord_SerializeInvocationInfo", () => true);
_invocationInfo.ToPSObjectForRemoting(psObject);
RemotingEncoder.AddNoteProperty<object>(psObject, "InformationalRecord_PipelineIterationInfo", () => this.PipelineIterationInfo);
}
}
[DataMember()]
private string _message;
private InvocationInfo _invocationInfo;
private ReadOnlyCollection<int> _pipelineIterationInfo;
private bool _serializeExtendedInfo;
}
/// <summary>
/// A warning record in the PSInformationalBuffers.
/// </summary>
[DataContract()]
public class WarningRecord : InformationalRecord
{
/// <summary>
///
/// </summary>
/// <param name="message"></param>
public WarningRecord(string message)
: base(message)
{ }
/// <summary>
///
/// </summary>
/// <param name="record"></param>
public WarningRecord(PSObject record)
: base(record)
{ }
/// <summary>
/// Constructor for Fully qualified warning Id.
/// </summary>
/// <param name="fullyQualifiedWarningId">Fully qualified warning Id</param>
/// <param name="message">Warning message</param>
public WarningRecord(string fullyQualifiedWarningId, string message)
: base(message)
{
_fullyQualifiedWarningId = fullyQualifiedWarningId;
}
/// <summary>
/// Constructor for Fully qualified warning Id.
/// </summary>
/// <param name="fullyQualifiedWarningId">Fully qualified warning Id</param>
/// <param name="record">Warning serialized object</param>
public WarningRecord(string fullyQualifiedWarningId, PSObject record)
: base(record)
{
_fullyQualifiedWarningId = fullyQualifiedWarningId;
}
/// <summary>
/// String which uniquely identifies this warning condition.
/// </summary>
public string FullyQualifiedWarningId
{
get
{
return _fullyQualifiedWarningId ?? string.Empty;
}
}
private string _fullyQualifiedWarningId;
}
/// <summary>
/// A debug record in the PSInformationalBuffers.
/// </summary>
[DataContract()]
public class DebugRecord : InformationalRecord
{
/// <summary>
///
/// </summary>
/// <param name="message"></param>
public DebugRecord(string message)
: base(message)
{ }
/// <summary>
///
/// </summary>
/// <param name="record"></param>
public DebugRecord(PSObject record)
: base(record)
{ }
}
/// <summary>
/// A verbose record in the PSInformationalBuffers.
/// </summary>
[DataContract()]
public class VerboseRecord : InformationalRecord
{
/// <summary>
///
/// </summary>
/// <param name="message"></param>
public VerboseRecord(string message)
: base(message)
{ }
/// <summary>
///
/// </summary>
/// <param name="record"></param>
public VerboseRecord(PSObject record)
: base(record)
{ }
}
}