Files
Umbraco-CMS/src/Umbraco.Core/Telemetry/TelemetryService.cs

71 lines
2.2 KiB
C#
Raw Normal View History

Package telemetry (#11738) * Add TelemetryService Currently it only allows you to get a list of the name of all the installed packages * Create model class for package telemetry And move the telemetry report data out of ReportSiteTask * Add version as an option in package manifest * Use TelemetryService to generate telemetry data Instead of doing it directly in the ReportSiteTask * Seal TelemetryService This should not be overwritten * Add option for package creators to opt out * Add global setting to restrict package telemetry * Add TelemetryService unit tests * Add ManifestParser tests for new properties * Clean * Update src/Umbraco.Core/Telemetry/TelemetryService.cs Co-authored-by: Bjarke Berg <mail@bergmania.dk> * Create interface for telemetry service * Use IOptionsMonitor instead of IOptions However I chose to use CurrentValue since according to microsoft: "Some file systems, such as Docker containers and network shares, may not reliably send change notifications.", additionally TelemetryService only runs once pr. day, so it shouldn't be too much of an issue that it doesn't cache the result. * Use is false instead of negation It's a bit more readable * Track restrict package telemetry value * Save RestrictPackageTelemetry in report data Not packages, since it'll be the same for all packages * Fix TelemetryService unit tests * Clean * Update src/Umbraco.Core/Telemetry/ITelemetryService.cs Co-authored-by: Bjarke Berg <mail@bergmania.dk> * Remove RestrictPackageTelemetry Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-12-14 16:09:31 +01:00
using System;
using System.Collections.Generic;
using Umbraco.Cms.Core.Configuration;
using Umbraco.Cms.Core.Manifest;
using Umbraco.Cms.Core.Telemetry.Models;
using Umbraco.Extensions;
namespace Umbraco.Cms.Core.Telemetry
{
/// <inheritdoc/>
internal class TelemetryService : ITelemetryService
{
private readonly IManifestParser _manifestParser;
private readonly IUmbracoVersion _umbracoVersion;
private readonly ISiteIdentifierService _siteIdentifierService;
Package telemetry (#11738) * Add TelemetryService Currently it only allows you to get a list of the name of all the installed packages * Create model class for package telemetry And move the telemetry report data out of ReportSiteTask * Add version as an option in package manifest * Use TelemetryService to generate telemetry data Instead of doing it directly in the ReportSiteTask * Seal TelemetryService This should not be overwritten * Add option for package creators to opt out * Add global setting to restrict package telemetry * Add TelemetryService unit tests * Add ManifestParser tests for new properties * Clean * Update src/Umbraco.Core/Telemetry/TelemetryService.cs Co-authored-by: Bjarke Berg <mail@bergmania.dk> * Create interface for telemetry service * Use IOptionsMonitor instead of IOptions However I chose to use CurrentValue since according to microsoft: "Some file systems, such as Docker containers and network shares, may not reliably send change notifications.", additionally TelemetryService only runs once pr. day, so it shouldn't be too much of an issue that it doesn't cache the result. * Use is false instead of negation It's a bit more readable * Track restrict package telemetry value * Save RestrictPackageTelemetry in report data Not packages, since it'll be the same for all packages * Fix TelemetryService unit tests * Clean * Update src/Umbraco.Core/Telemetry/ITelemetryService.cs Co-authored-by: Bjarke Berg <mail@bergmania.dk> * Remove RestrictPackageTelemetry Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-12-14 16:09:31 +01:00
/// <summary>
/// Initializes a new instance of the <see cref="TelemetryService"/> class.
/// </summary>
public TelemetryService(
IManifestParser manifestParser,
IUmbracoVersion umbracoVersion,
ISiteIdentifierService siteIdentifierService)
Package telemetry (#11738) * Add TelemetryService Currently it only allows you to get a list of the name of all the installed packages * Create model class for package telemetry And move the telemetry report data out of ReportSiteTask * Add version as an option in package manifest * Use TelemetryService to generate telemetry data Instead of doing it directly in the ReportSiteTask * Seal TelemetryService This should not be overwritten * Add option for package creators to opt out * Add global setting to restrict package telemetry * Add TelemetryService unit tests * Add ManifestParser tests for new properties * Clean * Update src/Umbraco.Core/Telemetry/TelemetryService.cs Co-authored-by: Bjarke Berg <mail@bergmania.dk> * Create interface for telemetry service * Use IOptionsMonitor instead of IOptions However I chose to use CurrentValue since according to microsoft: "Some file systems, such as Docker containers and network shares, may not reliably send change notifications.", additionally TelemetryService only runs once pr. day, so it shouldn't be too much of an issue that it doesn't cache the result. * Use is false instead of negation It's a bit more readable * Track restrict package telemetry value * Save RestrictPackageTelemetry in report data Not packages, since it'll be the same for all packages * Fix TelemetryService unit tests * Clean * Update src/Umbraco.Core/Telemetry/ITelemetryService.cs Co-authored-by: Bjarke Berg <mail@bergmania.dk> * Remove RestrictPackageTelemetry Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-12-14 16:09:31 +01:00
{
_manifestParser = manifestParser;
_umbracoVersion = umbracoVersion;
_siteIdentifierService = siteIdentifierService;
Package telemetry (#11738) * Add TelemetryService Currently it only allows you to get a list of the name of all the installed packages * Create model class for package telemetry And move the telemetry report data out of ReportSiteTask * Add version as an option in package manifest * Use TelemetryService to generate telemetry data Instead of doing it directly in the ReportSiteTask * Seal TelemetryService This should not be overwritten * Add option for package creators to opt out * Add global setting to restrict package telemetry * Add TelemetryService unit tests * Add ManifestParser tests for new properties * Clean * Update src/Umbraco.Core/Telemetry/TelemetryService.cs Co-authored-by: Bjarke Berg <mail@bergmania.dk> * Create interface for telemetry service * Use IOptionsMonitor instead of IOptions However I chose to use CurrentValue since according to microsoft: "Some file systems, such as Docker containers and network shares, may not reliably send change notifications.", additionally TelemetryService only runs once pr. day, so it shouldn't be too much of an issue that it doesn't cache the result. * Use is false instead of negation It's a bit more readable * Track restrict package telemetry value * Save RestrictPackageTelemetry in report data Not packages, since it'll be the same for all packages * Fix TelemetryService unit tests * Clean * Update src/Umbraco.Core/Telemetry/ITelemetryService.cs Co-authored-by: Bjarke Berg <mail@bergmania.dk> * Remove RestrictPackageTelemetry Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-12-14 16:09:31 +01:00
}
/// <inheritdoc/>
public bool TryGetTelemetryReportData(out TelemetryReportData telemetryReportData)
{
if (_siteIdentifierService.TryGetOrCreateSiteIdentifier(out Guid telemetryId) is false)
Package telemetry (#11738) * Add TelemetryService Currently it only allows you to get a list of the name of all the installed packages * Create model class for package telemetry And move the telemetry report data out of ReportSiteTask * Add version as an option in package manifest * Use TelemetryService to generate telemetry data Instead of doing it directly in the ReportSiteTask * Seal TelemetryService This should not be overwritten * Add option for package creators to opt out * Add global setting to restrict package telemetry * Add TelemetryService unit tests * Add ManifestParser tests for new properties * Clean * Update src/Umbraco.Core/Telemetry/TelemetryService.cs Co-authored-by: Bjarke Berg <mail@bergmania.dk> * Create interface for telemetry service * Use IOptionsMonitor instead of IOptions However I chose to use CurrentValue since according to microsoft: "Some file systems, such as Docker containers and network shares, may not reliably send change notifications.", additionally TelemetryService only runs once pr. day, so it shouldn't be too much of an issue that it doesn't cache the result. * Use is false instead of negation It's a bit more readable * Track restrict package telemetry value * Save RestrictPackageTelemetry in report data Not packages, since it'll be the same for all packages * Fix TelemetryService unit tests * Clean * Update src/Umbraco.Core/Telemetry/ITelemetryService.cs Co-authored-by: Bjarke Berg <mail@bergmania.dk> * Remove RestrictPackageTelemetry Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-12-14 16:09:31 +01:00
{
telemetryReportData = null;
return false;
}
telemetryReportData = new TelemetryReportData
{
Id = telemetryId,
Version = _umbracoVersion.SemanticVersion.ToSemanticStringWithoutBuild(),
Packages = GetPackageTelemetry(),
Package telemetry (#11738) * Add TelemetryService Currently it only allows you to get a list of the name of all the installed packages * Create model class for package telemetry And move the telemetry report data out of ReportSiteTask * Add version as an option in package manifest * Use TelemetryService to generate telemetry data Instead of doing it directly in the ReportSiteTask * Seal TelemetryService This should not be overwritten * Add option for package creators to opt out * Add global setting to restrict package telemetry * Add TelemetryService unit tests * Add ManifestParser tests for new properties * Clean * Update src/Umbraco.Core/Telemetry/TelemetryService.cs Co-authored-by: Bjarke Berg <mail@bergmania.dk> * Create interface for telemetry service * Use IOptionsMonitor instead of IOptions However I chose to use CurrentValue since according to microsoft: "Some file systems, such as Docker containers and network shares, may not reliably send change notifications.", additionally TelemetryService only runs once pr. day, so it shouldn't be too much of an issue that it doesn't cache the result. * Use is false instead of negation It's a bit more readable * Track restrict package telemetry value * Save RestrictPackageTelemetry in report data Not packages, since it'll be the same for all packages * Fix TelemetryService unit tests * Clean * Update src/Umbraco.Core/Telemetry/ITelemetryService.cs Co-authored-by: Bjarke Berg <mail@bergmania.dk> * Remove RestrictPackageTelemetry Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-12-14 16:09:31 +01:00
};
return true;
}
private IEnumerable<PackageTelemetry> GetPackageTelemetry()
{
List<PackageTelemetry> packages = new();
Package telemetry (#11738) * Add TelemetryService Currently it only allows you to get a list of the name of all the installed packages * Create model class for package telemetry And move the telemetry report data out of ReportSiteTask * Add version as an option in package manifest * Use TelemetryService to generate telemetry data Instead of doing it directly in the ReportSiteTask * Seal TelemetryService This should not be overwritten * Add option for package creators to opt out * Add global setting to restrict package telemetry * Add TelemetryService unit tests * Add ManifestParser tests for new properties * Clean * Update src/Umbraco.Core/Telemetry/TelemetryService.cs Co-authored-by: Bjarke Berg <mail@bergmania.dk> * Create interface for telemetry service * Use IOptionsMonitor instead of IOptions However I chose to use CurrentValue since according to microsoft: "Some file systems, such as Docker containers and network shares, may not reliably send change notifications.", additionally TelemetryService only runs once pr. day, so it shouldn't be too much of an issue that it doesn't cache the result. * Use is false instead of negation It's a bit more readable * Track restrict package telemetry value * Save RestrictPackageTelemetry in report data Not packages, since it'll be the same for all packages * Fix TelemetryService unit tests * Clean * Update src/Umbraco.Core/Telemetry/ITelemetryService.cs Co-authored-by: Bjarke Berg <mail@bergmania.dk> * Remove RestrictPackageTelemetry Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-12-14 16:09:31 +01:00
IEnumerable<PackageManifest> manifests = _manifestParser.GetManifests();
foreach (PackageManifest manifest in manifests)
{
if (manifest.AllowPackageTelemetry is false)
{
continue;
}
packages.Add(new PackageTelemetry
{
Name = manifest.PackageName,
Version = manifest.Version ?? string.Empty,
Package telemetry (#11738) * Add TelemetryService Currently it only allows you to get a list of the name of all the installed packages * Create model class for package telemetry And move the telemetry report data out of ReportSiteTask * Add version as an option in package manifest * Use TelemetryService to generate telemetry data Instead of doing it directly in the ReportSiteTask * Seal TelemetryService This should not be overwritten * Add option for package creators to opt out * Add global setting to restrict package telemetry * Add TelemetryService unit tests * Add ManifestParser tests for new properties * Clean * Update src/Umbraco.Core/Telemetry/TelemetryService.cs Co-authored-by: Bjarke Berg <mail@bergmania.dk> * Create interface for telemetry service * Use IOptionsMonitor instead of IOptions However I chose to use CurrentValue since according to microsoft: "Some file systems, such as Docker containers and network shares, may not reliably send change notifications.", additionally TelemetryService only runs once pr. day, so it shouldn't be too much of an issue that it doesn't cache the result. * Use is false instead of negation It's a bit more readable * Track restrict package telemetry value * Save RestrictPackageTelemetry in report data Not packages, since it'll be the same for all packages * Fix TelemetryService unit tests * Clean * Update src/Umbraco.Core/Telemetry/ITelemetryService.cs Co-authored-by: Bjarke Berg <mail@bergmania.dk> * Remove RestrictPackageTelemetry Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-12-14 16:09:31 +01:00
});
}
return packages;
}
}
}