mirror of https://github.com/abpframework/abp.git
44 changed files with 253 additions and 260 deletions
@ -1,13 +0,0 @@ |
|||||
using System; |
|
||||
using System.Reflection; |
|
||||
using System.Threading; |
|
||||
using System.Threading.Tasks; |
|
||||
using Volo.Abp.Telemetry.Shared.Enums; |
|
||||
|
|
||||
namespace Volo.Abp.Telemetry.Activity; |
|
||||
|
|
||||
public interface IActivityDataProvider |
|
||||
{ |
|
||||
|
|
||||
Task AddExtraInformationAsync(ActivityData activity); |
|
||||
} |
|
||||
@ -0,0 +1,8 @@ |
|||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace Volo.Abp.Telemetry.Activity.Contracts; |
||||
|
|
||||
|
public interface ITelemetryActivityDataProvider |
||||
|
{ |
||||
|
Task AddExtraInformationAsync(ActivityData activity); |
||||
|
} |
||||
@ -1,126 +0,0 @@ |
|||||
using System; |
|
||||
using System.Collections.Generic; |
|
||||
using System.IO; |
|
||||
using System.Threading.Tasks; |
|
||||
using Volo.Abp.DependencyInjection; |
|
||||
using Volo.Abp.Telemetry.Activity.Contracts; |
|
||||
using Volo.Abp.Telemetry.EnvironmentInspection.Contracts; |
|
||||
using Volo.Abp.Telemetry.Shared; |
|
||||
using Volo.Abp.Telemetry.Shared.Enums; |
|
||||
|
|
||||
namespace Volo.Abp.Telemetry.Activity.Providers; |
|
||||
|
|
||||
public class ActivityDataProvider : IActivityDataProvider, IScopedDependency |
|
||||
{ |
|
||||
private readonly IDeviceInfoProvider _deviceInfoProvider; |
|
||||
private readonly ISoftwareInfoProvider _softwareInfoProvider; |
|
||||
private readonly IEnumerable<ITelemetryApplicationInfoContributor> _applicationInfoContributors; |
|
||||
private readonly IActivityStorage _activityStorage; |
|
||||
private readonly ISolutionInfoProvider _solutionInfoProvider; |
|
||||
|
|
||||
public ActivityDataProvider( |
|
||||
IDeviceInfoProvider deviceInfoProvider, |
|
||||
ISoftwareInfoProvider softwareInfoProvider, |
|
||||
IEnumerable<ITelemetryApplicationInfoContributor> applicationInfoContributors, |
|
||||
IActivityStorage activityStorage, ISolutionInfoProvider solutionInfoProvider) |
|
||||
{ |
|
||||
_deviceInfoProvider = deviceInfoProvider; |
|
||||
_softwareInfoProvider = softwareInfoProvider; |
|
||||
_applicationInfoContributors = applicationInfoContributors; |
|
||||
_activityStorage = activityStorage; |
|
||||
_solutionInfoProvider = solutionInfoProvider; |
|
||||
} |
|
||||
|
|
||||
protected virtual SessionType GetSessionType() |
|
||||
{ |
|
||||
return SessionType.ApplicationRuntime; |
|
||||
} |
|
||||
|
|
||||
public virtual async Task AddExtraInformationAsync(ActivityData activity) |
|
||||
{ |
|
||||
var (isFirstSession, sessionId) = await _activityStorage.GetOrCreateSessionInfoAsync(); |
|
||||
|
|
||||
AddSolutionId(activity); |
|
||||
var sessionType = GetSessionType(); |
|
||||
activity[ActivityPropertyName.SessionType] = sessionType; |
|
||||
activity[ActivityPropertyName.SessionId] = sessionId; |
|
||||
activity[ActivityPropertyName.IsFirstSession] = isFirstSession; |
|
||||
activity[ActivityPropertyName.DeviceId] = _deviceInfoProvider.GetDeviceId(); |
|
||||
|
|
||||
if (await _activityStorage.ShouldAddDeviceInfoAsync()) |
|
||||
{ |
|
||||
await AddDeviceInformationAsync(activity); |
|
||||
} |
|
||||
|
|
||||
if (activity.ContainsKey(ActivityPropertyName.Assembly) && sessionType == SessionType.ApplicationRuntime) |
|
||||
{ |
|
||||
await AddApplicationInformationAsync(activity); |
|
||||
activity.Remove(ActivityPropertyName.Assembly); |
|
||||
} |
|
||||
|
|
||||
if (await ShouldAddSolutionInformation(activity)) |
|
||||
{ |
|
||||
var solutionInfo = await _solutionInfoProvider.GetSolutionInfoAsync(activity[ActivityPropertyName.SolutionPath].ToString()!); |
|
||||
|
|
||||
foreach (var entry in solutionInfo) |
|
||||
{ |
|
||||
activity[entry.Key] = entry.Value; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
protected virtual async Task<bool> ShouldAddSolutionInformation(ActivityData activity) |
|
||||
{ |
|
||||
|
|
||||
if ( |
|
||||
!activity.TryGetValue(ActivityPropertyName.SolutionId, out var id) || |
|
||||
!Guid.TryParse(id.ToString(), out var solutionId) && activity.ContainsKey(ActivityPropertyName.SolutionPath)) |
|
||||
{ |
|
||||
return false; |
|
||||
} |
|
||||
|
|
||||
return await _activityStorage.ShouldAddSolutionInformation(solutionId); |
|
||||
} |
|
||||
|
|
||||
protected virtual async Task AddDeviceInformationAsync(ActivityData activityData) |
|
||||
{ |
|
||||
activityData[ActivityPropertyName.DeviceType] = _deviceInfoProvider.GetDeviceType(); |
|
||||
activityData[ActivityPropertyName.DeviceLanguage] = _deviceInfoProvider.GetLanguage(); |
|
||||
activityData[ActivityPropertyName.OperatingSystem] = _deviceInfoProvider.GetOperatingSystem(); |
|
||||
activityData[ActivityPropertyName.CountryIsoCode] = _deviceInfoProvider.GetCountry(); |
|
||||
|
|
||||
var softwareList = await _softwareInfoProvider.GetSoftwareInfoAsync(); |
|
||||
activityData[ActivityPropertyName.InstalledSoftwares] = softwareList; |
|
||||
|
|
||||
await _activityStorage.MarkDeviceInfoAsSentAsync(); |
|
||||
} |
|
||||
|
|
||||
protected virtual async Task AddApplicationInformationAsync(ActivityData activityData) |
|
||||
{ |
|
||||
foreach (var contributor in _applicationInfoContributors) |
|
||||
{ |
|
||||
await contributor.ContributeAsync(activityData); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
|
|
||||
protected virtual void AddSolutionId(ActivityData activityData) |
|
||||
{ |
|
||||
if (activityData.ContainsKey(ActivityPropertyName.SolutionId)) |
|
||||
{ |
|
||||
return; |
|
||||
} |
|
||||
|
|
||||
if (!activityData.TryGetValue(ActivityPropertyName.SolutionPath, out var path) || !File.Exists((string)path)) |
|
||||
{ |
|
||||
return; |
|
||||
} |
|
||||
|
|
||||
var solutionId = _solutionInfoProvider.GetSolutionId((string)path); |
|
||||
|
|
||||
if (solutionId.HasValue) |
|
||||
{ |
|
||||
activityData[ActivityPropertyName.SolutionId] = solutionId.Value; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,77 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
using Volo.Abp.Telemetry.Activity.Contracts; |
||||
|
using Volo.Abp.Telemetry.Constants; |
||||
|
using Volo.Abp.Telemetry.Constants.Enums; |
||||
|
using Volo.Abp.Telemetry.EnvironmentInspection.Contracts; |
||||
|
|
||||
|
namespace Volo.Abp.Telemetry.Activity.Providers; |
||||
|
|
||||
|
public class TelemetryActivityDataProvider : ITelemetryActivityDataProvider, ISingletonDependency |
||||
|
{ |
||||
|
private readonly IServiceProvider _serviceProvider; |
||||
|
|
||||
|
public TelemetryActivityDataProvider(IServiceProvider serviceProvider) |
||||
|
{ |
||||
|
_serviceProvider = serviceProvider; |
||||
|
} |
||||
|
|
||||
|
public virtual async Task AddExtraInformationAsync(ActivityData activity) |
||||
|
{ |
||||
|
var activityStorage = _serviceProvider.GetRequiredService<ITelemetryActivityStorage>(); |
||||
|
var sessionContext = _serviceProvider.GetRequiredService<ITelemetrySessionContextProvider>(); |
||||
|
var deviceInfoProvider = _serviceProvider.GetRequiredService<IDeviceInfoProvider>(); |
||||
|
|
||||
|
var (isFirstSession, sessionId) = await activityStorage.GetOrCreateSessionInfoAsync(); |
||||
|
|
||||
|
sessionContext.SetSolutionContext(activity); |
||||
|
activity[ActivityPropertyName.SessionType] = sessionContext.SessionType; |
||||
|
activity[ActivityPropertyName.SessionId] = sessionId; |
||||
|
activity[ActivityPropertyName.IsFirstSession] = isFirstSession; |
||||
|
activity[ActivityPropertyName.DeviceId] = deviceInfoProvider.GetDeviceId(); |
||||
|
|
||||
|
if (await activityStorage.ShouldAddDeviceInfoAsync()) |
||||
|
{ |
||||
|
activity[ActivityPropertyName.DeviceType] = deviceInfoProvider.GetDeviceType(); |
||||
|
activity[ActivityPropertyName.DeviceLanguage] = deviceInfoProvider.GetLanguage(); |
||||
|
activity[ActivityPropertyName.OperatingSystem] = deviceInfoProvider.GetOperatingSystem(); |
||||
|
activity[ActivityPropertyName.CountryIsoCode] = deviceInfoProvider.GetCountry(); |
||||
|
|
||||
|
var softwareInfo = _serviceProvider.GetRequiredService<ISoftwareInfoProvider>(); |
||||
|
var softwareList = await softwareInfo.GetSoftwareInfoAsync(); |
||||
|
activity[ActivityPropertyName.InstalledSoftwares] = softwareList; |
||||
|
|
||||
|
await activityStorage.MarkDeviceInfoAsSentAsync(); |
||||
|
} |
||||
|
|
||||
|
if (activity.ContainsKey(ActivityPropertyName.Assembly) && sessionContext.SessionType == SessionType.ApplicationRuntime) |
||||
|
{ |
||||
|
var contributors = _serviceProvider.GetRequiredService<IEnumerable<ITelemetryApplicationInfoContributor>>(); |
||||
|
foreach (var contributor in contributors) |
||||
|
{ |
||||
|
await contributor.ContributeAsync(activity); |
||||
|
} |
||||
|
activity.Remove(ActivityPropertyName.Assembly); |
||||
|
} |
||||
|
|
||||
|
if (activity.TryGetValue(ActivityPropertyName.SolutionId, out var rawSolutionId)) |
||||
|
{ |
||||
|
var solutionId = Guid.Parse(rawSolutionId!.ToString()!); |
||||
|
|
||||
|
if (await activityStorage.ShouldAddSolutionInformation(solutionId)) |
||||
|
{ |
||||
|
var solutionProvider = _serviceProvider.GetRequiredService<ITelemetrySolutionInfoProvider>(); |
||||
|
var solutionInfo = await solutionProvider.GetSolutionInfoAsync(activity[ActivityPropertyName.SolutionPath].ToString()!); |
||||
|
|
||||
|
foreach (var entry in solutionInfo) |
||||
|
{ |
||||
|
activity[entry.Key] = entry.Value; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,15 @@ |
|||||
|
namespace Volo.Abp.Telemetry.Constants; |
||||
|
|
||||
|
public static class AbpPlatformUrls |
||||
|
{ |
||||
|
#if DEBUG
|
||||
|
public const string AbpTelemetryApiUrl = "https://localhost:44393/"; |
||||
|
public const string AbpIoUrl = "https://localhost:44328/"; |
||||
|
#else
|
||||
|
public const string AbpTelemetryApiUrl = "https://telemetry.abp.io/"; |
||||
|
public const string AbpIoUrl = "https://abp.io/"; |
||||
|
|
||||
|
#endif
|
||||
|
|
||||
|
|
||||
|
} |
||||
@ -1,4 +1,4 @@ |
|||||
namespace Volo.Abp.Telemetry.Shared; |
namespace Volo.Abp.Telemetry.Constants; |
||||
|
|
||||
public static class ActivityNameConsts |
public static class ActivityNameConsts |
||||
{ |
{ |
||||
@ -1,4 +1,4 @@ |
|||||
namespace Volo.Abp.Telemetry.Shared; |
namespace Volo.Abp.Telemetry.Constants; |
||||
|
|
||||
public static class ActivityPropertyName |
public static class ActivityPropertyName |
||||
{ |
{ |
||||
@ -0,0 +1,9 @@ |
|||||
|
namespace Volo.Abp.Telemetry.Constants.Enums; |
||||
|
|
||||
|
public enum AbpTool : byte |
||||
|
{ |
||||
|
Unknown = 0, |
||||
|
StudioUI = 1, |
||||
|
StudioCli = 2, |
||||
|
OldCli = 3 |
||||
|
} |
||||
@ -1,4 +1,4 @@ |
|||||
namespace Volo.Abp.Telemetry.Shared.Enums; |
namespace Volo.Abp.Telemetry.Constants.Enums; |
||||
|
|
||||
public enum DeviceType |
public enum DeviceType |
||||
{ |
{ |
||||
@ -1,4 +1,4 @@ |
|||||
namespace Volo.Abp.Telemetry.Shared.Enums; |
namespace Volo.Abp.Telemetry.Constants.Enums; |
||||
|
|
||||
public enum OperationSystem |
public enum OperationSystem |
||||
{ |
{ |
||||
@ -1,4 +1,4 @@ |
|||||
namespace Volo.Abp.Telemetry.Shared.Enums; |
namespace Volo.Abp.Telemetry.Constants.Enums; |
||||
|
|
||||
public enum SessionType |
public enum SessionType |
||||
{ |
{ |
||||
@ -1,4 +1,4 @@ |
|||||
namespace Volo.Abp.Telemetry.Shared.Enums; |
namespace Volo.Abp.Telemetry.Constants.Enums; |
||||
|
|
||||
public enum SoftwareType : byte |
public enum SoftwareType : byte |
||||
{ |
{ |
||||
@ -1,31 +1,13 @@ |
|||||
using System; |
using System; |
||||
using System.IO; |
using System.IO; |
||||
|
|
||||
namespace Volo.Abp.Telemetry.Shared; |
namespace Volo.Abp.Telemetry.Constants; |
||||
|
|
||||
public static class AbpTelemetryPaths |
public static class TelemetryPaths |
||||
{ |
{ |
||||
public static string AccessToken => Path.Combine(AbpRootPath, "cli", "access-token.bin"); |
public static string AccessToken => Path.Combine(AbpRootPath, "cli", "access-token.bin"); |
||||
public static string ComputerId => Path.Combine(AbpRootPath, "cli", "computer-id.bin"); |
public static string ComputerId => Path.Combine(AbpRootPath, "cli", "computer-id.bin"); |
||||
public static string ActivityStorage => Path.Combine(AbpRootPath, "activity-storage.json"); |
public static string ActivityStorage => Path.Combine(AbpRootPath, "activity-storage.json"); |
||||
public static string Studio => Path.Combine(AbpRootPath, "studio"); |
public static string Studio => Path.Combine(AbpRootPath, "studio"); |
||||
private readonly static string AbpRootPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".abp"); |
private readonly static string AbpRootPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".abp"); |
||||
} |
|
||||
|
|
||||
|
|
||||
|
|
||||
public static class AbpPlatformUrls |
|
||||
{ |
|
||||
|
|
||||
|
|
||||
#if DEBUG
|
|
||||
public const string TelemetryApiUrl = "https://localhost:44393/"; |
|
||||
public const string AbpIoUrl = "https://localhost:44328/"; |
|
||||
#else
|
|
||||
public const string TelemetryApiUrl = "https://telemetry.abp.io/"; |
|
||||
public const string AbpIoUrl = "https://abp.io/"; |
|
||||
|
|
||||
#endif
|
|
||||
|
|
||||
|
|
||||
} |
} |
||||
@ -0,0 +1,10 @@ |
|||||
|
using Volo.Abp.Telemetry.Activity; |
||||
|
using Volo.Abp.Telemetry.Constants.Enums; |
||||
|
|
||||
|
namespace Volo.Abp.Telemetry; |
||||
|
|
||||
|
public interface ITelemetrySessionContextProvider |
||||
|
{ |
||||
|
public SessionType SessionType { get; } |
||||
|
void SetSolutionContext(ActivityData activity); |
||||
|
} |
||||
@ -0,0 +1,39 @@ |
|||||
|
using System.IO; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
using Volo.Abp.Telemetry.Activity; |
||||
|
using Volo.Abp.Telemetry.Activity.Contracts; |
||||
|
using Volo.Abp.Telemetry.Constants; |
||||
|
using Volo.Abp.Telemetry.Constants.Enums; |
||||
|
|
||||
|
namespace Volo.Abp.Telemetry; |
||||
|
|
||||
|
public class TelemetryApplicationRuntimeSessionTypeProvider : ITelemetrySessionContextProvider , ISingletonDependency |
||||
|
{ |
||||
|
private readonly ITelemetrySolutionInfoProvider _telemetrySolutionInfoProvider; |
||||
|
|
||||
|
public TelemetryApplicationRuntimeSessionTypeProvider(ITelemetrySolutionInfoProvider telemetrySolutionInfoProvider) |
||||
|
{ |
||||
|
_telemetrySolutionInfoProvider = telemetrySolutionInfoProvider; |
||||
|
} |
||||
|
|
||||
|
public virtual SessionType SessionType => SessionType.ApplicationRuntime; |
||||
|
public virtual void SetSolutionContext(ActivityData activity) |
||||
|
{ |
||||
|
if (activity.ContainsKey(ActivityPropertyName.SolutionId)) |
||||
|
{ |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
if (!activity.TryGetValue(ActivityPropertyName.SolutionPath, out var path) || !File.Exists((string)path)) |
||||
|
{ |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
var solutionId = _telemetrySolutionInfoProvider.GetSolutionId((string)path); |
||||
|
|
||||
|
if (solutionId.HasValue) |
||||
|
{ |
||||
|
activity[ActivityPropertyName.SolutionId] = solutionId.Value; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue