using System; using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Umbraco.Cms.Core.Configuration; using Umbraco.Cms.Core.Configuration.Models; using Umbraco.Cms.Core.Install.Models; namespace Umbraco.Cms.Core.Install.InstallSteps { [InstallSetupStep(InstallationType.NewInstall | InstallationType.Upgrade, "TelemetryIdConfiguration", 0, "", PerformsAppRestart = false)] public class TelemetryIdentifierStep : InstallSetupStep { private readonly ILogger _logger; private readonly IOptions _globalSettings; private readonly IConfigManipulator _configManipulator; public TelemetryIdentifierStep(ILogger logger, IOptions globalSettings, IConfigManipulator configManipulator) { _logger = logger; _globalSettings = globalSettings; _configManipulator = configManipulator; } public override Task ExecuteAsync(object model) { // Generate GUID var telemetrySiteIdentifier = Guid.NewGuid(); try { _configManipulator.SetGlobalId(telemetrySiteIdentifier.ToString()); } catch (Exception ex) { _logger.LogError(ex, "Couldn't update config files with a telemetry site identifier"); } return Task.FromResult(null); } public override bool RequiresExecution(object model) { // Verify that Json value is not empty string // Try & get a value stored in appSettings.json var backofficeIdentifierRaw = _globalSettings.Value.Id; // No need to add Id again if already found return string.IsNullOrEmpty(backofficeIdentifierRaw); } } }