private void ExternalToolsInstaller_AfterUninstall(object sender, InstallEventArgs e)
        {
            // Read version installed
            ExternalToolConfiguration externalToolConfiguration = ReadExternalToolConfiguration();
            string versionInstalled = GetInstallerProductVersion() ?? externalToolConfiguration?.version ?? "unknown";

            // Enable telemetry if it was enabled in configuration file or if there is no configuration
            bool telemetryEnabled = externalToolConfiguration?.arguments?.Contains(TELEMETRY_ARGUMENT) ?? true;
            var  ev = new EventTelemetry
            {
                Name = "Uninstall"
            };

            ev.Properties["Version"] = versionInstalled;

            // Initialize Telemetry
            TelemetryClient tc = GetTelemetryClient(telemetryEnabled);

            try
            {
                // Send telemetry
                tc.TrackEvent(ev);
                tc.Flush();
            }
            catch (Exception ex)
            {
                // In case of error, send exception to Telemetry
                tc.TrackException(ex);
                tc.Flush();
                throw;
            }
        }
        private void WriteExternalToolConfiguration(ExternalToolConfiguration configuration)
        {
            string updatedConfig = JsonConvert.SerializeObject(configuration, Formatting.Indented);

            System.IO.File.WriteAllText(PathConfiguration.FullPath, updatedConfig);
        }
        private void ExternalToolsInstaller_AfterInstall(object sender, InstallEventArgs e)
        {
            bool telemetryEnabled = IsSetupTelemetryEnabled();
            var  ev = new EventTelemetry
            {
                Name = "Install"
            };

            // Fix version installed
            ExternalToolConfiguration externalToolConfiguration = ReadExternalToolConfiguration();

            externalToolConfiguration.version = GetInstallerProductVersion() ?? externalToolConfiguration.version;
            ev.Properties["Version"]          = externalToolConfiguration.version;

            // Fix executable in configuration
            string assemblyPath;

            if (Context.Parameters.ContainsKey(SETUP_ASSEMBLYPATH))
            {
                assemblyPath = Context.Parameters[SETUP_ASSEMBLYPATH];
            }
            else
            {
                Context.LogMessage($"The {"ASSEMBLYPATH"} property is not available, assume directory of installer DLL instead.");
                assemblyPath = Assembly.GetExecutingAssembly().Location;
            }
            string externalToolsDirectory = System.IO.Path.GetDirectoryName(assemblyPath);
            string externalToolsExe       = System.IO.Path.Combine(externalToolsDirectory, EXTERNALTOOLS_EXENAME);

            externalToolConfiguration.path = externalToolsExe;

            // Remove existing telemetry option
            string telemetryOption = $" {TELEMETRY_ARGUMENT}";

            externalToolConfiguration.arguments = externalToolConfiguration.arguments.Replace(telemetryOption, "");
            externalToolConfiguration.arguments = externalToolConfiguration.arguments.Replace(telemetryOption.Trim(), "");

            // Add telemetry argument if telemetry is enabled during setup
            if (telemetryEnabled)
            {
                externalToolConfiguration.arguments += telemetryOption;
                Context.LogMessage($"Telemetry enabled");
            }

            // Initialize Telemetry
            TelemetryClient tc = GetTelemetryClient(telemetryEnabled);

            try
            {
                // Update external tool configuration
                WriteExternalToolConfiguration(externalToolConfiguration);

                // Send telemetry
                tc.TrackEvent(ev);
                tc.Flush();
            }
            catch (Exception ex)
            {
                // In case of error, send exception to Telemetry
                tc.TrackException(ex);
                tc.Flush();
                throw;
            }
        }