|
| 1 | +// ------------------------------------------------------------------------------ |
| 2 | +// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. |
| 3 | +// ------------------------------------------------------------------------------ |
| 4 | + |
| 5 | +namespace Microsoft.Graph.Beta.PowerShell |
| 6 | +{ |
| 7 | + using System; |
| 8 | + using System.Text.RegularExpressions; |
| 9 | + using System.Threading; |
| 10 | + using System.Threading.Tasks; |
| 11 | + using Microsoft.Graph.Beta.PowerShell.Runtime; |
| 12 | + |
| 13 | + public static class EventExtensions |
| 14 | + { |
| 15 | + /// <summary> |
| 16 | + /// Print event details to the provided stream |
| 17 | + /// </summary> |
| 18 | + /// <param name="getEventData">The event data to print</param> |
| 19 | + /// <param name="signal">The delegate for signaling events to the runtime</param> |
| 20 | + /// <param name="token">The cancellation token for the request</param> |
| 21 | + /// <param name="streamName">The name of the stream to print data to</param> |
| 22 | + /// <param name="eventName">The name of the event to be printed</param> |
| 23 | + public static async void Print(this Func<EventArgs> getEventData, Func<string, CancellationToken, Func<EventArgs>, Task> signal, CancellationToken token, string streamName, string eventName) |
| 24 | + { |
| 25 | + var eventDisplayName = EventFactory.SplitPascalCase(eventName).ToUpperInvariant(); |
| 26 | + var data = EventDataConverter.ConvertFrom(getEventData()); // also, we manually use our TypeConverter to return an appropriate type |
| 27 | + if (data.Id != Events.Verbose && data.Id != Events.Warning && data.Id != Events.Debug && data.Id != Events.Information && data.Id != Events.Error) |
| 28 | + { |
| 29 | + await signal(streamName, token, () => EventFactory.CreateLogEvent($"{eventDisplayName} The contents are '{data?.Id}' and '{data?.Message}'")); |
| 30 | + if (data != null) |
| 31 | + { |
| 32 | + await signal(streamName, token, () => EventFactory.CreateLogEvent($"{eventDisplayName} Parameter: '{data.Parameter}'\n{eventDisplayName} RequestMessage '{data.RequestMessage}'\n{eventDisplayName} Response: '{data.ResponseMessage}'\n{eventDisplayName} Value: '{data.Value}'")); |
| 33 | + await signal(streamName, token, () => EventFactory.CreateLogEvent($"{eventDisplayName} ExtendedData Type: '{data.ExtendedData?.GetType()}'\n{eventDisplayName} ExtendedData '{data.ExtendedData}'")); |
| 34 | + } |
| 35 | + } |
| 36 | + } |
| 37 | + } |
| 38 | +} |
0 commit comments