From 73f8d84885a7980f5062d8f88ca2392bf5b2fbf4 Mon Sep 17 00:00:00 2001 From: Emre KARA Date: Thu, 12 Jun 2025 10:06:58 +0300 Subject: [PATCH] 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. --- .../Providers/TelemetryDeviceInfoEnricher.cs | 107 +----------------- .../Constants/ActivityPropertyNames.cs | 1 - .../Telemetry/Constants/Enums/DeviceType.cs | 8 -- 3 files changed, 1 insertion(+), 115 deletions(-) delete mode 100644 framework/src/Volo.Abp.Core/Volo/Abp/Telemetry/Constants/Enums/DeviceType.cs diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/Telemetry/Activity/Providers/TelemetryDeviceInfoEnricher.cs b/framework/src/Volo.Abp.Core/Volo/Abp/Telemetry/Activity/Providers/TelemetryDeviceInfoEnricher.cs index f5819da09c..ca4fd4655c 100644 --- a/framework/src/Volo.Abp.Core/Volo/Abp/Telemetry/Activity/Providers/TelemetryDeviceInfoEnricher.cs +++ b/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; - } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/Telemetry/Constants/ActivityPropertyNames.cs b/framework/src/Volo.Abp.Core/Volo/Abp/Telemetry/Constants/ActivityPropertyNames.cs index 36a6fc439e..5d93049f3b 100644 --- a/framework/src/Volo.Abp.Core/Volo/Abp/Telemetry/Constants/ActivityPropertyNames.cs +++ b/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); diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/Telemetry/Constants/Enums/DeviceType.cs b/framework/src/Volo.Abp.Core/Volo/Abp/Telemetry/Constants/Enums/DeviceType.cs deleted file mode 100644 index 7feb608ff9..0000000000 --- a/framework/src/Volo.Abp.Core/Volo/Abp/Telemetry/Constants/Enums/DeviceType.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Volo.Abp.Telemetry.Constants.Enums; - -public enum DeviceType -{ - Unknown = 0, - Desktop = 1, - Laptop = 2 -} \ No newline at end of file