/// <summary> /// Generate a pseudo-random pipe name using the specified process ID, hashed MAC address and process path. /// </summary> /// <param name="processId">The process ID to use for generating the pipe name.</param> /// <param name="values">Additional values to incorporate into the generated name.</param> /// <returns>A string containing the pipe name.</returns> public static string CreatePipeName(int processId, params string[] values) { // Reinvoking the host can cause differences between the original path, e.g., // "C:\Program Files" and "c:\Program Files". This will generate different UUID values and cause // deadlock when the client and server are trying to connect, so always use the lower invariant of the process. return(Uuid.Create($"{processId};{Environment.ProcessPath.ToLowerInvariant()};{Sha256Hasher.Hash(MacAddressGetter.GetMacAddress())};{string.Join(";", values)}") .ToString("B")); }
/// <summary> /// Generate a pseudo-random pipe name using the specified process ID, hashed MAC address and process path. /// </summary> /// <param name="processId">The process ID to use for generating the pipe name.</param> /// <param name="values">Additional values to incorporate into the generated name.</param> /// <returns>A string containing the pipe name.</returns> public static string CreatePipeName(int processId, params string[] values) { return(Uuid.Create($"{processId};{Environment.ProcessPath};{Sha256Hasher.Hash(MacAddressGetter.GetMacAddress())};{string.Join(";", values)}") .ToString("B")); }
public Client(Guid sessionid, ClientAppHostEnvironment host, UpdaterService updater) { if (Interactive.Client.CommandLineTool.TestDriver.ShouldRun) { return; } PreferenceStore.Default.Subscribe(ObservePreferenceChange); try { if (!Prefs.Telemetry.Enabled.GetValue()) { Log.Info(TAG, "Telemetry is disabled"); return; } // InMemoryChannel is the default channel, but we set it up manually here so we can tweak several // default settings that are undesirable for desktop apps. channel = new InMemoryChannel { // Defaults to 30s, but since we are changing buffer.Capacity to 1, we can make this infinite and // avoid pointlessly waking up InMemoryTransmitter's Runner. SendingInterval = Timeout.InfiniteTimeSpan, }; // There is no reasonable public API for changing the buffer capacity at this time. // You can achieve it by turning on DeveloperMode, but that has other consequences. // So we reflect. // // The default Capacity is 500, which is far too large for us (and perhaps most non-server apps). // We want to avoid having to perform a blocking Flush call on the UI thread, and since our events // are currently few and far between, we set Capacity to 1 to essentially get auto-flush. var channelBuffer = typeof(InMemoryChannel) .GetField("buffer", BindingFlags.NonPublic | BindingFlags.Instance) .GetValue(channel); channelBuffer .GetType() .GetProperty("Capacity", BindingFlags.Public | BindingFlags.Instance) .SetValue(channelBuffer, 1); var config = new TelemetryConfiguration("@TELEMETRY_INSTRUMENTATION_KEY@", channel); appInsightsClient = new TelemetryClient(config); appInsightsClient.Context.Session.Id = sessionid.ToString(); appInsightsClient.Context.Device.OperatingSystem = host.OSName.ToString(); // TODO: Make these GlobalProperties when we bump to 2.7.0-beta3 or later var globalProperties = appInsightsClient.Context.Properties; globalProperties.Add( "Product Version", BuildInfo.VersionString); globalProperties.Add( "Build Hash", BuildInfo.Hash); globalProperties.Add( "OS Platform", Runtime.CurrentProcessRuntime.OSPlatform.ToString()); globalProperties.Add( "OS Architecture", RuntimeInformation.OSArchitecture.ToString()); globalProperties.Add( "Process Architecture", Runtime.CurrentProcessRuntime.Architecture.ToString()); globalProperties.Add( "Runtime Identifier", Runtime.CurrentProcessRuntime.RuntimeIdentifier); globalProperties.Add( "OS Version", host.OSVersion.ToString()); globalProperties.Add( "Release Candidate Level", ((byte)BuildInfo.Version.CandidateLevel).ToString()); globalProperties.Add( "Release Candidate Level Name", BuildInfo.Version.CandidateLevel.ToString().ToLowerInvariant()); globalProperties.Add( "Machine ID", Sha256Hasher.Hash(MacAddressGetter.GetMacAddress())); globalProperties.Add( "Update Channel", updater.UpdateChannel); enabled = true; } catch (Exception e) { LogErrorWithoutTelemetry(e, "Unable to create AppInsights client for telemetry"); } }