- Notifications
You must be signed in to change notification settings - Fork 187
/
Copy pathEventExtensions.cs
38 lines (36 loc) · 2.44 KB
/
EventExtensions.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
// ------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
// ------------------------------------------------------------------------------
namespaceNamespacePrefixPlaceholder.PowerShell
{
usingSystem;
usingSystem.Text.RegularExpressions;
usingSystem.Threading;
usingSystem.Threading.Tasks;
usingNamespacePrefixPlaceholder.PowerShell.Runtime;
publicstaticclassEventExtensions
{
/// <summary>
/// Print event details to the provided stream
/// </summary>
/// <param name="getEventData">The event data to print</param>
/// <param name="signal">The delegate for signaling events to the runtime</param>
/// <param name="token">The cancellation token for the request</param>
/// <param name="streamName">The name of the stream to print data to</param>
/// <param name="eventName">The name of the event to be printed</param>
publicstaticasyncvoidPrint(thisFunc<EventArgs>getEventData,Func<string,CancellationToken,Func<EventArgs>,Task>signal,CancellationTokentoken,stringstreamName,stringeventName)
{
vareventDisplayName=EventFactory.SplitPascalCase(eventName).ToUpperInvariant();
vardata=EventDataConverter.ConvertFrom(getEventData());// also, we manually use our TypeConverter to return an appropriate type
if(data.Id!=Events.Verbose&&data.Id!=Events.Warning&&data.Id!=Events.Debug&&data.Id!=Events.Information&&data.Id!=Events.Error)
{
awaitsignal(streamName,token,()=>EventFactory.CreateLogEvent($"{eventDisplayName} The contents are '{data?.Id}' and '{data?.Message}'"));
if(data!=null)
{
awaitsignal(streamName,token,()=>EventFactory.CreateLogEvent($"{eventDisplayName} Parameter: '{data.Parameter}'\n{eventDisplayName} RequestMessage '{data.RequestMessage}'\n{eventDisplayName} Response: '{data.ResponseMessage}'\n{eventDisplayName} Value: '{data.Value}'"));
awaitsignal(streamName,token,()=>EventFactory.CreateLogEvent($"{eventDisplayName} ExtendedData Type: '{data.ExtendedData?.GetType()}'\n{eventDisplayName} ExtendedData '{data.ExtendedData}'"));
}
}
}
}
}