Browse Source
Add `DeviceInfo` to `IWebClientInfoProvider`.
pull/18242/head
maliming
2 years ago
No known key found for this signature in database
GPG Key ID: A646B9CB645ECEA4
4 changed files with
33 additions and
0 deletions
-
Directory.Packages.props
-
framework/src/Volo.Abp.AspNetCore/Volo.Abp.AspNetCore.csproj
-
framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/WebClientInfo/HttpContextWebClientInfoProvider.cs
-
framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/WebClientInfo/IWebClientInfoProvider.cs
|
|
|
@ -26,6 +26,7 @@ |
|
|
|
<PackageVersion Include="Dapper" Version="2.1.21" /> |
|
|
|
<PackageVersion Include="Dapr.AspNetCore" Version="1.12.0" /> |
|
|
|
<PackageVersion Include="Dapr.Client" Version="1.12.0" /> |
|
|
|
<PackageVersion Include="DeviceDetector.NET" Version="6.1.4" /> |
|
|
|
<PackageVersion Include="Devart.Data.Oracle.EFCore" Version="10.1.151.7" /> |
|
|
|
<PackageVersion Include="DistributedLock.Core" Version="1.0.5" /> |
|
|
|
<PackageVersion Include="DistributedLock.Redis" Version="1.0.2" /> |
|
|
|
|
|
|
|
@ -30,6 +30,7 @@ |
|
|
|
<ProjectReference Include="..\Volo.Abp.VirtualFileSystem\Volo.Abp.VirtualFileSystem.csproj" /> |
|
|
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" /> |
|
|
|
<PackageReference Include="IdentityModel" /> |
|
|
|
<PackageReference Include="DeviceDetector.NET" /> |
|
|
|
</ItemGroup> |
|
|
|
|
|
|
|
</Project> |
|
|
|
|
|
|
|
@ -1,4 +1,5 @@ |
|
|
|
using System; |
|
|
|
using DeviceDetectorNET; |
|
|
|
using Microsoft.AspNetCore.Http; |
|
|
|
using Microsoft.Extensions.Logging; |
|
|
|
using Volo.Abp.DependencyInjection; |
|
|
|
@ -22,6 +23,8 @@ public class HttpContextWebClientInfoProvider : IWebClientInfoProvider, ITransie |
|
|
|
|
|
|
|
public string? ClientIpAddress => GetClientIpAddress(); |
|
|
|
|
|
|
|
public string? DeviceInfo => GetDeviceInfo(); |
|
|
|
|
|
|
|
protected virtual string? GetBrowserInfo() |
|
|
|
{ |
|
|
|
return HttpContextAccessor.HttpContext?.Request?.Headers?["User-Agent"]; |
|
|
|
@ -39,4 +42,30 @@ public class HttpContextWebClientInfoProvider : IWebClientInfoProvider, ITransie |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
protected virtual string? GetDeviceInfo() |
|
|
|
{ |
|
|
|
string? deviceInfo = null; |
|
|
|
var deviceDetector = new DeviceDetector(GetBrowserInfo()); |
|
|
|
deviceDetector.Parse(); |
|
|
|
if (!deviceDetector.IsParsed()) |
|
|
|
{ |
|
|
|
return deviceInfo; |
|
|
|
} |
|
|
|
|
|
|
|
var osInfo = deviceDetector.GetOs(); |
|
|
|
if (osInfo.Success) |
|
|
|
{ |
|
|
|
deviceInfo = osInfo.Match.Name; |
|
|
|
} |
|
|
|
|
|
|
|
var clientInfo = deviceDetector.GetClient(); |
|
|
|
if (clientInfo.Success) |
|
|
|
{ |
|
|
|
deviceInfo = deviceInfo.IsNullOrWhiteSpace() ? clientInfo.Match.Name : deviceInfo + " " + clientInfo.Match.Name; |
|
|
|
} |
|
|
|
|
|
|
|
return deviceInfo; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@ -5,4 +5,6 @@ public interface IWebClientInfoProvider |
|
|
|
string? BrowserInfo { get; } |
|
|
|
|
|
|
|
string? ClientIpAddress { get; } |
|
|
|
|
|
|
|
string? DeviceInfo { get; } |
|
|
|
} |
|
|
|
|