TelemetryEvent.cs (4759B)
1 // ----------------------------------------------------------------------------- 2 // <copyright file="TelemetryEvent.cs" company="Microsoft Corporation"> 3 // Copyright (c) Microsoft Corporation. Licensed under the MIT License. 4 // </copyright> 5 // ----------------------------------------------------------------------------- 6 7 namespace Microsoft.Management.Configuration.UnitTests.Helpers 8 { 9 using System; 10 using System.Collections.Generic; 11 12 /// <summary> 13 /// This class holds the data about a telemetry event detected via the diagnostics side channel. 14 /// </summary> 15 public class TelemetryEvent 16 { 17 /// <summary> 18 /// The initial indicator that the diagnostics message contains the contents of a telemetry event. 19 /// </summary> 20 public const string Preamble = "#DebugEventStream"; 21 22 /// <summary> 23 /// The name of the ConfigUnitRun event. 24 /// </summary> 25 public const string ConfigUnitRunName = "ConfigUnitRun"; 26 27 /// <summary> 28 /// The name of the ConfigProcessingSummary event. 29 /// </summary> 30 public const string ConfigProcessingSummaryName = "ConfigProcessingSummary"; 31 32 #pragma warning disable SA1600 // Elements should be documented 33 34 // Shared fields 35 public const string SetID = "SetID"; 36 public const string RunIntent = "RunIntent"; 37 public const string Result = "Result"; 38 public const string FailurePoint = "FailurePoint"; 39 40 // ConfigUnitRun fields 41 public const string UnitID = "UnitID"; 42 public const string UnitName = "UnitName"; 43 public const string ModuleName = "ModuleName"; 44 public const string UnitIntent = "UnitIntent"; 45 public const string Action = "Action"; 46 public const string SettingsProvided = "SettingsProvided"; 47 48 // ConfigProcessingSummary fields 49 public const string FromHistory = "FromHistory"; 50 public const string AssertCount = "AssertCount"; 51 public const string AssertsRun = "AssertsRun"; 52 public const string AssertsFailed = "AssertsFailed"; 53 public const string InformCount = "InformCount"; 54 public const string InformsRun = "InformsRun"; 55 public const string InformsFailed = "InformsFailed"; 56 public const string ApplyCount = "ApplyCount"; 57 public const string AppliesRun = "AppliesRun"; 58 public const string AppliesFailed = "AppliesFailed"; 59 #pragma warning restore SA1600 // Elements should be documented 60 61 /// <summary> 62 /// Initializes a new instance of the <see cref="TelemetryEvent"/> class. 63 /// </summary> 64 /// <param name="eventMessage">The message containing the event data.</param> 65 public TelemetryEvent(string eventMessage) 66 { 67 bool preambleSeen = false; 68 69 foreach (string line in eventMessage.Split('\n')) 70 { 71 if (line == Preamble) 72 { 73 preambleSeen = true; 74 continue; 75 } 76 77 if (!preambleSeen) 78 { 79 // Skip all lines until the preamble is seen 80 continue; 81 } 82 83 int splitIndex = line.IndexOf(": "); 84 if (splitIndex != -1) 85 { 86 this.Properties.Add(line.Substring(0, splitIndex), line.Substring(splitIndex + 2)); 87 } 88 } 89 } 90 91 /// <summary> 92 /// Gets the properties for this event. 93 /// </summary> 94 public Dictionary<string, string> Properties { get; private set; } = new Dictionary<string, string>(); 95 96 /// <summary> 97 /// Gets the name of the event. 98 /// </summary> 99 public string Name 100 { 101 get 102 { 103 return this.Properties["Event"]; 104 } 105 } 106 107 /// <summary> 108 /// Gets the activity id. 109 /// </summary> 110 public Guid ActivityID 111 { 112 get 113 { 114 return Guid.Parse(this.Properties["ActivityID"]); 115 } 116 } 117 118 /// <summary> 119 /// Gets the version of the code. 120 /// </summary> 121 public string CodeVersion 122 { 123 get 124 { 125 return this.Properties["CodeVersion"]; 126 } 127 } 128 129 /// <summary> 130 /// Gets the caller. 131 /// </summary> 132 public string Caller 133 { 134 get 135 { 136 return this.Properties["Caller"]; 137 } 138 } 139 } 140 }