Browse Source

Remove DeviceType-related logic and references

Eliminated the DeviceType enum, field, and related logic from the codebase. This includes database migrations, entity models, services, and activity enrichers. The change simplifies the data model and removes unnecessary complexity.
pull/23059/head
Emre KARA 1 year ago
parent
commit
73f8d84885
  1. 107
      framework/src/Volo.Abp.Core/Volo/Abp/Telemetry/Activity/Providers/TelemetryDeviceInfoEnricher.cs
  2. 1
      framework/src/Volo.Abp.Core/Volo/Abp/Telemetry/Constants/ActivityPropertyNames.cs
  3. 8
      framework/src/Volo.Abp.Core/Volo/Abp/Telemetry/Constants/Enums/DeviceType.cs

107
framework/src/Volo.Abp.Core/Volo/Abp/Telemetry/Activity/Providers/TelemetryDeviceInfoEnricher.cs

@ -57,7 +57,6 @@ public class TelemetryDeviceInfoEnricher : ITelemetryActivityEventEnricher, ISin
}
activity[ActivityPropertyNames.DeviceLanguage] = CultureInfo.CurrentUICulture.Name;
activity[ActivityPropertyNames.DeviceType] = GetDeviceType();
activity[ActivityPropertyNames.OperatingSystem] = GetOperatingSystem();
activity[ActivityPropertyNames.CountryIsoCode] = GetCountry();
}
@ -108,31 +107,7 @@ public class TelemetryDeviceInfoEnricher : ITelemetryActivityEventEnricher, ISin
return OperationSystem.Unknown;
}
private static DeviceType GetDeviceType()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return DetectDeviceTypeOnWindows();
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
return DetectDeviceTypeOnLinux();
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
return DetectDeviceTypeOnMacOS();
}
if (RuntimeInformation.OSDescription.ToLower().Contains("ios"))
{
return DeviceType.Laptop;
}
return DeviceType.Unknown;
}
private static string GetCountry()
{
var culture = CultureInfo.CurrentUICulture;
@ -144,84 +119,4 @@ public class TelemetryDeviceInfoEnricher : ITelemetryActivityEventEnricher, ISin
var region = new RegionInfo(culture.Name);
return region.TwoLetterISORegionName;
}
private static DeviceType DetectDeviceTypeOnWindows()
{
#if WINDOWS
try
{
using var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_SystemEnclosure");
foreach (var obj in searcher.Get())
{
if (obj["ChassisTypes"] is ushort[] chassisTypes &&
chassisTypes.Any(t => t is 8 or 9 or 10 or 14))
{
return DeviceType.Laptop;
}
}
}
catch
{
// ignored
}
#endif
return DeviceType.Desktop;
}
private static DeviceType DetectDeviceTypeOnLinux()
{
try
{
if (File.Exists("/sys/class/dmi/id/chassis_type"))
{
var type = File.ReadAllText("/sys/class/dmi/id/chassis_type");
if (int.TryParse(type.Trim(), out var code) && code is 8 or 9 or 10 or 14)
{
return DeviceType.Laptop;
}
}
}
catch
{
// ignored
}
return DeviceType.Desktop;
}
private static DeviceType DetectDeviceTypeOnMacOS()
{
try
{
using var process = new Process();
process.StartInfo = new ProcessStartInfo
{
FileName = "system_profiler",
Arguments = "SPHardwareDataType",
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true
};
process.Start();
var output = process.StandardOutput.ReadToEnd();
process.WaitForExit();
if (output.Contains("MacBook"))
{
return DeviceType.Laptop;
}
if (output.Contains("iMac") || output.Contains("Mac Pro"))
{
return DeviceType.Desktop;
}
}
catch
{
// ignored
}
return DeviceType.Unknown;
}
}

1
framework/src/Volo.Abp.Core/Volo/Abp/Telemetry/Constants/ActivityPropertyNames.cs

@ -12,7 +12,6 @@ public static class ActivityPropertyNames
public const string IpAddress = nameof(IpAddress);
public const string IsFirstSession = nameof(IsFirstSession);
public const string DeviceId = nameof(DeviceId);
public const string DeviceType = nameof(DeviceType);
public const string DeviceLanguage = nameof(DeviceLanguage);
public const string OperatingSystem = nameof(OperatingSystem);
public const string CountryIsoCode = nameof(CountryIsoCode);

8
framework/src/Volo.Abp.Core/Volo/Abp/Telemetry/Constants/Enums/DeviceType.cs

@ -1,8 +0,0 @@
namespace Volo.Abp.Telemetry.Constants.Enums;
public enum DeviceType
{
Unknown = 0,
Desktop = 1,
Laptop = 2
}
Loading…
Cancel
Save