2021-01-18 15:40:22 +01:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
using Microsoft.Extensions.Options;
|
2021-02-18 11:06:02 +01:00
|
|
|
|
using Umbraco.Cms.Core.Configuration;
|
|
|
|
|
|
using Umbraco.Cms.Core.Configuration.Models;
|
|
|
|
|
|
using Umbraco.Cms.Core.Install.Models;
|
2021-01-18 15:40:22 +01:00
|
|
|
|
|
2021-02-18 11:06:02 +01:00
|
|
|
|
namespace Umbraco.Cms.Core.Install.InstallSteps
|
2021-01-18 15:40:22 +01:00
|
|
|
|
{
|
|
|
|
|
|
[InstallSetupStep(InstallationType.NewInstall | InstallationType.Upgrade,
|
|
|
|
|
|
"TelemetryIdConfiguration", 0, "",
|
|
|
|
|
|
PerformsAppRestart = false)]
|
|
|
|
|
|
public class TelemetryIdentifierStep : InstallSetupStep<object>
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly ILogger<TelemetryIdentifierStep> _logger;
|
|
|
|
|
|
private readonly IOptions<GlobalSettings> _globalSettings;
|
|
|
|
|
|
private readonly IConfigManipulator _configManipulator;
|
|
|
|
|
|
|
|
|
|
|
|
public TelemetryIdentifierStep(ILogger<TelemetryIdentifierStep> logger, IOptions<GlobalSettings> globalSettings, IConfigManipulator configManipulator)
|
|
|
|
|
|
{
|
|
|
|
|
|
_logger = logger;
|
|
|
|
|
|
_globalSettings = globalSettings;
|
|
|
|
|
|
_configManipulator = configManipulator;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override Task<InstallSetupResult> 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<InstallSetupResult>(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);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|