From 4072b170b7525ac9db179c1166340dc14bbb1762 Mon Sep 17 00:00:00 2001 From: colin Date: Sat, 28 Dec 2024 11:06:41 +0800 Subject: [PATCH 1/2] refactor(ipregion): Obtain the geographic description from the ip address. --- .../AbpAuditingMapperProfile.cs | 13 ++-- .../FodyWeavers.xml | 3 + .../FodyWeavers.xsd | 30 ++++++++ .../LINGYUN.Abp.AuditLogging.IP2Region.csproj | 25 +++++++ .../AbpAuditLoggingIP2RegionModule.cs | 26 +++++++ .../AbpAuditLoggingIP2RegionOptions.cs | 5 ++ .../IP2Region/IP2RegionAuditingStore.cs | 34 ++++++++++ .../IP2Region/IP2RegionSecurityLogStore.cs | 36 ++++++++++ .../Abp/IP2Region/AbpIP2RegionModule.cs | 3 + .../Abp/IP2Region}/IIpLocationInfoProvider.cs | 4 +- .../IP2RegionLocationInfoProvider.cs | 68 +++++++++++++++++++ .../LINGYUN/Abp/IP2Region/LocationInfo.cs | 8 +++ .../AbpIdentitySessionAspNetCoreOptions.cs | 37 +--------- .../HttpContextDeviceInfoProvider.cs | 13 +--- .../IP2RegionLocationInfoProvider.cs | 36 ---------- .../Abp/Identity/Session/LocationInfo.cs | 7 -- .../Session/NoneIpLocationInfoProvider.cs | 15 ---- 17 files changed, 251 insertions(+), 112 deletions(-) create mode 100644 aspnet-core/framework/auditing/LINGYUN.Abp.AuditLogging.IP2Region/FodyWeavers.xml create mode 100644 aspnet-core/framework/auditing/LINGYUN.Abp.AuditLogging.IP2Region/FodyWeavers.xsd create mode 100644 aspnet-core/framework/auditing/LINGYUN.Abp.AuditLogging.IP2Region/LINGYUN.Abp.AuditLogging.IP2Region.csproj create mode 100644 aspnet-core/framework/auditing/LINGYUN.Abp.AuditLogging.IP2Region/LINGYUN/Abp/AuditLogging/IP2Region/AbpAuditLoggingIP2RegionModule.cs create mode 100644 aspnet-core/framework/auditing/LINGYUN.Abp.AuditLogging.IP2Region/LINGYUN/Abp/AuditLogging/IP2Region/AbpAuditLoggingIP2RegionOptions.cs create mode 100644 aspnet-core/framework/auditing/LINGYUN.Abp.AuditLogging.IP2Region/LINGYUN/Abp/AuditLogging/IP2Region/IP2RegionAuditingStore.cs create mode 100644 aspnet-core/framework/auditing/LINGYUN.Abp.AuditLogging.IP2Region/LINGYUN/Abp/AuditLogging/IP2Region/IP2RegionSecurityLogStore.cs rename aspnet-core/{modules/identity/LINGYUN.Abp.Identity.Session/LINGYUN/Abp/Identity/Session => framework/common/LINGYUN.Abp.IP2Region/LINGYUN/Abp/IP2Region}/IIpLocationInfoProvider.cs (74%) create mode 100644 aspnet-core/framework/common/LINGYUN.Abp.IP2Region/LINGYUN/Abp/IP2Region/IP2RegionLocationInfoProvider.cs create mode 100644 aspnet-core/framework/common/LINGYUN.Abp.IP2Region/LINGYUN/Abp/IP2Region/LocationInfo.cs delete mode 100644 aspnet-core/modules/identity/LINGYUN.Abp.Identity.Session.AspNetCore/LINGYUN/Abp/Identity/Session/AspNetCore/IP2RegionLocationInfoProvider.cs delete mode 100644 aspnet-core/modules/identity/LINGYUN.Abp.Identity.Session/LINGYUN/Abp/Identity/Session/LocationInfo.cs delete mode 100644 aspnet-core/modules/identity/LINGYUN.Abp.Identity.Session/LINGYUN/Abp/Identity/Session/NoneIpLocationInfoProvider.cs diff --git a/aspnet-core/framework/auditing/LINGYUN.Abp.AuditLogging.EntityFrameworkCore/LINGYUN/Abp/AuditLogging/EntityFrameworkCore/AbpAuditingMapperProfile.cs b/aspnet-core/framework/auditing/LINGYUN.Abp.AuditLogging.EntityFrameworkCore/LINGYUN/Abp/AuditLogging/EntityFrameworkCore/AbpAuditingMapperProfile.cs index 14ac2d52b..091801817 100644 --- a/aspnet-core/framework/auditing/LINGYUN.Abp.AuditLogging.EntityFrameworkCore/LINGYUN/Abp/AuditLogging/EntityFrameworkCore/AbpAuditingMapperProfile.cs +++ b/aspnet-core/framework/auditing/LINGYUN.Abp.AuditLogging.EntityFrameworkCore/LINGYUN/Abp/AuditLogging/EntityFrameworkCore/AbpAuditingMapperProfile.cs @@ -1,4 +1,5 @@ using AutoMapper; +using Volo.Abp.ObjectExtending; namespace LINGYUN.Abp.AuditLogging.EntityFrameworkCore; @@ -7,14 +8,16 @@ public class AbpAuditingMapperProfile : Profile public AbpAuditingMapperProfile() { CreateMap() - .MapExtraProperties(); + .MapExtraProperties(MappingPropertyDefinitionChecks.None); CreateMap(); CreateMap() - .MapExtraProperties(); + .MapExtraProperties(MappingPropertyDefinitionChecks.None); CreateMap() - .MapExtraProperties(); + .MapExtraProperties(MappingPropertyDefinitionChecks.None); - CreateMap() - .MapExtraProperties(); + CreateMap(); + + CreateMap(MemberList.Destination) + .MapExtraProperties(MappingPropertyDefinitionChecks.None); } } diff --git a/aspnet-core/framework/auditing/LINGYUN.Abp.AuditLogging.IP2Region/FodyWeavers.xml b/aspnet-core/framework/auditing/LINGYUN.Abp.AuditLogging.IP2Region/FodyWeavers.xml new file mode 100644 index 000000000..00e1d9a1c --- /dev/null +++ b/aspnet-core/framework/auditing/LINGYUN.Abp.AuditLogging.IP2Region/FodyWeavers.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/aspnet-core/framework/auditing/LINGYUN.Abp.AuditLogging.IP2Region/FodyWeavers.xsd b/aspnet-core/framework/auditing/LINGYUN.Abp.AuditLogging.IP2Region/FodyWeavers.xsd new file mode 100644 index 000000000..3f3946e28 --- /dev/null +++ b/aspnet-core/framework/auditing/LINGYUN.Abp.AuditLogging.IP2Region/FodyWeavers.xsd @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed. + + + + + A comma-separated list of error codes that can be safely ignored in assembly verification. + + + + + 'false' to turn off automatic generation of the XML Schema file. + + + + + \ No newline at end of file diff --git a/aspnet-core/framework/auditing/LINGYUN.Abp.AuditLogging.IP2Region/LINGYUN.Abp.AuditLogging.IP2Region.csproj b/aspnet-core/framework/auditing/LINGYUN.Abp.AuditLogging.IP2Region/LINGYUN.Abp.AuditLogging.IP2Region.csproj new file mode 100644 index 000000000..d5b05534a --- /dev/null +++ b/aspnet-core/framework/auditing/LINGYUN.Abp.AuditLogging.IP2Region/LINGYUN.Abp.AuditLogging.IP2Region.csproj @@ -0,0 +1,25 @@ + + + + + + + netstandard2.0;netstandard2.1;net8.0 + enable + Nullable + LINGYUN.Abp.AuditLogging.IP2Region + LINGYUN.Abp.AuditLogging.IP2Region + false + false + false + + + netstandard2.0 + + + + + + + + diff --git a/aspnet-core/framework/auditing/LINGYUN.Abp.AuditLogging.IP2Region/LINGYUN/Abp/AuditLogging/IP2Region/AbpAuditLoggingIP2RegionModule.cs b/aspnet-core/framework/auditing/LINGYUN.Abp.AuditLogging.IP2Region/LINGYUN/Abp/AuditLogging/IP2Region/AbpAuditLoggingIP2RegionModule.cs new file mode 100644 index 000000000..a1b15a7e6 --- /dev/null +++ b/aspnet-core/framework/auditing/LINGYUN.Abp.AuditLogging.IP2Region/LINGYUN/Abp/AuditLogging/IP2Region/AbpAuditLoggingIP2RegionModule.cs @@ -0,0 +1,26 @@ +using LINGYUN.Abp.IP2Region; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; +using Volo.Abp.Auditing; +using Volo.Abp.Modularity; +using Volo.Abp.SecurityLog; + +namespace LINGYUN.Abp.AuditLogging.IP2Region; + +[DependsOn( + typeof(AbpIP2RegionModule), + typeof(AbpAuditLoggingModule))] +public class AbpAuditLoggingIP2RegionModule : AbpModule +{ + public override void PostConfigureServices(ServiceConfigurationContext context) + { + var configuration = context.Services.GetConfiguration(); + + Configure(configuration.GetSection("AuditLogging:IP2Region")); + + context.Services.Replace( + ServiceDescriptor.Transient()); + context.Services.Replace( + ServiceDescriptor.Transient()); + } +} diff --git a/aspnet-core/framework/auditing/LINGYUN.Abp.AuditLogging.IP2Region/LINGYUN/Abp/AuditLogging/IP2Region/AbpAuditLoggingIP2RegionOptions.cs b/aspnet-core/framework/auditing/LINGYUN.Abp.AuditLogging.IP2Region/LINGYUN/Abp/AuditLogging/IP2Region/AbpAuditLoggingIP2RegionOptions.cs new file mode 100644 index 000000000..50b3d2597 --- /dev/null +++ b/aspnet-core/framework/auditing/LINGYUN.Abp.AuditLogging.IP2Region/LINGYUN/Abp/AuditLogging/IP2Region/AbpAuditLoggingIP2RegionOptions.cs @@ -0,0 +1,5 @@ +namespace LINGYUN.Abp.AuditLogging.IP2Region; +public class AbpAuditLoggingIP2RegionOptions +{ + public bool IsEnabled { get; set; } +} diff --git a/aspnet-core/framework/auditing/LINGYUN.Abp.AuditLogging.IP2Region/LINGYUN/Abp/AuditLogging/IP2Region/IP2RegionAuditingStore.cs b/aspnet-core/framework/auditing/LINGYUN.Abp.AuditLogging.IP2Region/LINGYUN/Abp/AuditLogging/IP2Region/IP2RegionAuditingStore.cs new file mode 100644 index 000000000..837bc2d23 --- /dev/null +++ b/aspnet-core/framework/auditing/LINGYUN.Abp.AuditLogging.IP2Region/LINGYUN/Abp/AuditLogging/IP2Region/IP2RegionAuditingStore.cs @@ -0,0 +1,34 @@ +using LINGYUN.Abp.IP2Region; +using Microsoft.Extensions.Options; +using System; +using System.Threading.Tasks; +using Volo.Abp.Auditing; + +namespace LINGYUN.Abp.AuditLogging.IP2Region; +public class IP2RegionAuditingStore : AuditingStore +{ + private readonly AbpAuditLoggingIP2RegionOptions _options; + private readonly IIpLocationInfoProvider _ipLocationInfoProvider; + public IP2RegionAuditingStore( + IOptionsMonitor options, + IIpLocationInfoProvider ipLocationInfoProvider, + IAuditLogManager manager) + : base(manager) + { + _options = options.CurrentValue; + _ipLocationInfoProvider = ipLocationInfoProvider; + } + + public async override Task SaveAsync(AuditLogInfo auditInfo) + { + if (_options.IsEnabled && !auditInfo.ClientIpAddress.IsNullOrWhiteSpace()) + { + var locationInfo = await _ipLocationInfoProvider.GetLocationInfoAsync(auditInfo.ClientIpAddress); + if (locationInfo?.Remarks?.IsNullOrWhiteSpace() == false) + { + auditInfo.ExtraProperties.Add("Location", $"{locationInfo.Remarks}"); + } + } + await base.SaveAsync(auditInfo); + } +} diff --git a/aspnet-core/framework/auditing/LINGYUN.Abp.AuditLogging.IP2Region/LINGYUN/Abp/AuditLogging/IP2Region/IP2RegionSecurityLogStore.cs b/aspnet-core/framework/auditing/LINGYUN.Abp.AuditLogging.IP2Region/LINGYUN/Abp/AuditLogging/IP2Region/IP2RegionSecurityLogStore.cs new file mode 100644 index 000000000..44cf688c6 --- /dev/null +++ b/aspnet-core/framework/auditing/LINGYUN.Abp.AuditLogging.IP2Region/LINGYUN/Abp/AuditLogging/IP2Region/IP2RegionSecurityLogStore.cs @@ -0,0 +1,36 @@ +using LINGYUN.Abp.IP2Region; +using Microsoft.Extensions.Options; +using System; +using System.Threading.Tasks; +using Volo.Abp.SecurityLog; + +namespace LINGYUN.Abp.AuditLogging.IP2Region; + +public class IP2RegionSecurityLogStore : SecurityLogStore +{ + private readonly AbpAuditLoggingIP2RegionOptions _options; + private readonly IIpLocationInfoProvider _ipLocationInfoProvider; + public IP2RegionSecurityLogStore( + IOptionsMonitor options, + IIpLocationInfoProvider ipLocationInfoProvider, + ISecurityLogManager manager) + : base(manager) + { + _options = options.CurrentValue; + _ipLocationInfoProvider = ipLocationInfoProvider; + } + + public async override Task SaveAsync(SecurityLogInfo securityLogInfo) + { + if (_options.IsEnabled && !securityLogInfo.ClientIpAddress.IsNullOrWhiteSpace()) + { + var locationInfo = await _ipLocationInfoProvider.GetLocationInfoAsync(securityLogInfo.ClientIpAddress); + if (locationInfo?.Remarks?.IsNullOrWhiteSpace() == false) + { + securityLogInfo.ExtraProperties.Add("Location", $"{locationInfo.Remarks}"); + } + } + + await base.SaveAsync(securityLogInfo); + } +} diff --git a/aspnet-core/framework/common/LINGYUN.Abp.IP2Region/LINGYUN/Abp/IP2Region/AbpIP2RegionModule.cs b/aspnet-core/framework/common/LINGYUN.Abp.IP2Region/LINGYUN/Abp/IP2Region/AbpIP2RegionModule.cs index e8fd3ac03..7d3be1b5c 100644 --- a/aspnet-core/framework/common/LINGYUN.Abp.IP2Region/LINGYUN/Abp/IP2Region/AbpIP2RegionModule.cs +++ b/aspnet-core/framework/common/LINGYUN.Abp.IP2Region/LINGYUN/Abp/IP2Region/AbpIP2RegionModule.cs @@ -1,6 +1,7 @@ using IP2Region.Net.Abstractions; using IP2Region.Net.XDB; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; using Volo.Abp.Modularity; using Volo.Abp.VirtualFileSystem; @@ -24,5 +25,7 @@ public class AbpIP2RegionModule : AbpModule return searcher; }); + + context.Services.TryAddTransient(); } } diff --git a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Session/LINGYUN/Abp/Identity/Session/IIpLocationInfoProvider.cs b/aspnet-core/framework/common/LINGYUN.Abp.IP2Region/LINGYUN/Abp/IP2Region/IIpLocationInfoProvider.cs similarity index 74% rename from aspnet-core/modules/identity/LINGYUN.Abp.Identity.Session/LINGYUN/Abp/Identity/Session/IIpLocationInfoProvider.cs rename to aspnet-core/framework/common/LINGYUN.Abp.IP2Region/LINGYUN/Abp/IP2Region/IIpLocationInfoProvider.cs index bd9c7d09d..9b265b383 100644 --- a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Session/LINGYUN/Abp/Identity/Session/IIpLocationInfoProvider.cs +++ b/aspnet-core/framework/common/LINGYUN.Abp.IP2Region/LINGYUN/Abp/IP2Region/IIpLocationInfoProvider.cs @@ -1,6 +1,6 @@ using System.Threading.Tasks; -namespace LINGYUN.Abp.Identity.Session; +namespace LINGYUN.Abp.IP2Region; public interface IIpLocationInfoProvider { /// @@ -10,5 +10,5 @@ public interface IIpLocationInfoProvider /// /// 如果解析成功返回地理信息,否则返回null /// - Task GetLocationInfoAsync(string ipAddress); + Task GetLocationInfoAsync(string ipAddress); } diff --git a/aspnet-core/framework/common/LINGYUN.Abp.IP2Region/LINGYUN/Abp/IP2Region/IP2RegionLocationInfoProvider.cs b/aspnet-core/framework/common/LINGYUN.Abp.IP2Region/LINGYUN/Abp/IP2Region/IP2RegionLocationInfoProvider.cs new file mode 100644 index 000000000..d7dec2328 --- /dev/null +++ b/aspnet-core/framework/common/LINGYUN.Abp.IP2Region/LINGYUN/Abp/IP2Region/IP2RegionLocationInfoProvider.cs @@ -0,0 +1,68 @@ +using IP2Region.Net.Abstractions; +using System; +using System.Threading.Tasks; + +namespace LINGYUN.Abp.IP2Region; + +public class IP2RegionLocationInfoProvider : IIpLocationInfoProvider +{ + protected static readonly LocationInfo? _nullCache = null; + + protected ISearcher Searcher { get; } + public IP2RegionLocationInfoProvider(ISearcher searcher) + { + Searcher = searcher; + } + + public virtual Task GetLocationInfoAsync(string ipAddress) + { + var region = Searcher.Search(ipAddress); + if (string.IsNullOrWhiteSpace(region)) + { + return Task.FromResult(_nullCache); + } + + var regions = region!.Split('|'); + // | 0 | 1 | 2 |3| 4 | 5 | 6 | + // 39.128.0.0|39.128.31.255|中国|0|云南省|昆明市|移动 + // regions: + // 中国 0 云南省 昆明市 移动 + var locationInfo = new LocationInfo + { + Country = regions.Length >= 1 && !string.Equals(regions[0], "0") ? regions[0] : null, + Province = regions.Length >= 3 && !string.Equals(regions[2], "0") ? regions[2] : null, + City = regions.Length >= 4 && !string.Equals(regions[3], "0") ? regions[3] : null, + }; + + // 36.133.108.0|36.133.119.255|中国|0|重庆|重庆市|移动 + if (!locationInfo.Province.IsNullOrWhiteSpace() && !locationInfo.City.IsNullOrWhiteSpace()) + { + if (locationInfo.Province.Length < locationInfo.City.Length && + locationInfo.City.StartsWith(locationInfo.Province, StringComparison.InvariantCultureIgnoreCase)) + { + // 重庆市 + locationInfo.Remarks = $"{locationInfo.City}"; + } + // 111.26.31.0|111.26.31.127|中国|0|吉林省|吉林市|移动 + else + { + // 吉林省吉林市 + locationInfo.Remarks = $"{locationInfo.Province}{locationInfo.City}"; + } + } + // 220.246.0.0|220.246.255.255|中国|0|香港|0|电讯盈科 + else if (!locationInfo.Country.IsNullOrWhiteSpace() && !locationInfo.Province.IsNullOrWhiteSpace()) + { + // 中国香港 + locationInfo.Remarks = $"{locationInfo.Country}{locationInfo.Province}"; + } + // 220.247.4.0|220.247.31.255|日本|0|0|0|0 + else + { + // 日本 + locationInfo.Remarks = $"{locationInfo.Country}"; + } + + return Task.FromResult(locationInfo); + } +} diff --git a/aspnet-core/framework/common/LINGYUN.Abp.IP2Region/LINGYUN/Abp/IP2Region/LocationInfo.cs b/aspnet-core/framework/common/LINGYUN.Abp.IP2Region/LINGYUN/Abp/IP2Region/LocationInfo.cs new file mode 100644 index 000000000..8ce689377 --- /dev/null +++ b/aspnet-core/framework/common/LINGYUN.Abp.IP2Region/LINGYUN/Abp/IP2Region/LocationInfo.cs @@ -0,0 +1,8 @@ +namespace LINGYUN.Abp.IP2Region; +public class LocationInfo +{ + public string? Country { get; set; } + public string? Province { get; set; } + public string? City { get; set; } + public string? Remarks { get; set; } +} diff --git a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Session.AspNetCore/LINGYUN/Abp/Identity/Session/AspNetCore/AbpIdentitySessionAspNetCoreOptions.cs b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Session.AspNetCore/LINGYUN/Abp/Identity/Session/AspNetCore/AbpIdentitySessionAspNetCoreOptions.cs index a0b135255..b97781ede 100644 --- a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Session.AspNetCore/LINGYUN/Abp/Identity/Session/AspNetCore/AbpIdentitySessionAspNetCoreOptions.cs +++ b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Session.AspNetCore/LINGYUN/Abp/Identity/Session/AspNetCore/AbpIdentitySessionAspNetCoreOptions.cs @@ -1,48 +1,13 @@ -using System; -using System.Collections.Generic; - -namespace LINGYUN.Abp.Identity.Session.AspNetCore; +namespace LINGYUN.Abp.Identity.Session.AspNetCore; public class AbpIdentitySessionAspNetCoreOptions { /// /// 是否解析IP地理信息 /// public bool IsParseIpLocation { get; set; } - /// - /// 不做处理的省份 - /// - public IList IgnoreProvinces { get; set; } - /// - /// 地理信息解析 - /// - public Func LocationParser { get; set; } public AbpIdentitySessionAspNetCoreOptions() { IsParseIpLocation = false; - IgnoreProvinces = new List - { - // 中国直辖市不显示省份数据 - "北京", "上海", "天津", "重庆" - }; - LocationParser = (locationInfo) => - { - var location = ""; - - if (!locationInfo.Province.IsNullOrWhiteSpace() && - !IgnoreProvinces.Contains(locationInfo.Province)) - { - location += locationInfo.Province + " "; - } - if (!locationInfo.City.IsNullOrWhiteSpace()) - { - location += locationInfo.City; - } - if (location.IsNullOrWhiteSpace() && !locationInfo.Country.IsNullOrWhiteSpace()) - { - location = locationInfo.Country; - } - return location; - }; } } diff --git a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Session.AspNetCore/LINGYUN/Abp/Identity/Session/AspNetCore/HttpContextDeviceInfoProvider.cs b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Session.AspNetCore/LINGYUN/Abp/Identity/Session/AspNetCore/HttpContextDeviceInfoProvider.cs index 0764a975d..ff529367a 100644 --- a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Session.AspNetCore/LINGYUN/Abp/Identity/Session/AspNetCore/HttpContextDeviceInfoProvider.cs +++ b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Session.AspNetCore/LINGYUN/Abp/Identity/Session/AspNetCore/HttpContextDeviceInfoProvider.cs @@ -1,4 +1,5 @@ using DeviceDetectorNET; +using LINGYUN.Abp.IP2Region; using Microsoft.Extensions.Options; using System; using System.Threading.Tasks; @@ -51,17 +52,7 @@ public class HttpContextDeviceInfoProvider : IDeviceInfoProvider, ITransientDepe protected async virtual Task GetRegion(string ipAddress) { var locationInfo = await IpLocationInfoProvider.GetLocationInfoAsync(ipAddress); - if (locationInfo == null) - { - return null; - } - - if (Options.LocationParser != null) - { - return Options.LocationParser(locationInfo); - } - - return null; + return locationInfo?.Remarks; } private class BrowserDeviceInfo diff --git a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Session.AspNetCore/LINGYUN/Abp/Identity/Session/AspNetCore/IP2RegionLocationInfoProvider.cs b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Session.AspNetCore/LINGYUN/Abp/Identity/Session/AspNetCore/IP2RegionLocationInfoProvider.cs deleted file mode 100644 index a9177aec1..000000000 --- a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Session.AspNetCore/LINGYUN/Abp/Identity/Session/AspNetCore/IP2RegionLocationInfoProvider.cs +++ /dev/null @@ -1,36 +0,0 @@ -using IP2Region.Net.Abstractions; -using System; -using System.Threading.Tasks; - -namespace LINGYUN.Abp.Identity.Session.AspNetCore; - -public class IP2RegionLocationInfoProvider : IIpLocationInfoProvider -{ - protected static readonly LocationInfo _nullCache = null; - - protected ISearcher Searcher { get; } - public IP2RegionLocationInfoProvider(ISearcher searcher) - { - Searcher = searcher; - } - - public virtual Task GetLocationInfoAsync(string ipAddress) - { - var region = Searcher.Search(ipAddress); - if (region.IsNullOrWhiteSpace()) - { - return Task.FromResult(_nullCache); - } - - var regions = region.Split('|'); - // | 0 | 1 | 2 |3| 4 | 5 | 6 | - // 39.128.0.0|39.128.31.255|中国|0|云南省|昆明市|移动 - var locationInfo = new LocationInfo - { - Country = regions.Length >= 3 && !string.Equals(regions[2], "0") ? regions[2] : null, - Province = regions.Length >= 5 && !string.Equals(regions[4], "0") ? regions[4] : null, - City = regions.Length >= 6 && !string.Equals(regions[5], "0") ? regions[5] : null, - }; - return Task.FromResult(locationInfo); - } -} diff --git a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Session/LINGYUN/Abp/Identity/Session/LocationInfo.cs b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Session/LINGYUN/Abp/Identity/Session/LocationInfo.cs deleted file mode 100644 index 18f7b8bd3..000000000 --- a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Session/LINGYUN/Abp/Identity/Session/LocationInfo.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace LINGYUN.Abp.Identity.Session; -public class LocationInfo -{ - public string Country { get; set; } - public string Province { get; set; } - public string City { get; set; } -} diff --git a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Session/LINGYUN/Abp/Identity/Session/NoneIpLocationInfoProvider.cs b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Session/LINGYUN/Abp/Identity/Session/NoneIpLocationInfoProvider.cs deleted file mode 100644 index 73627198e..000000000 --- a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Session/LINGYUN/Abp/Identity/Session/NoneIpLocationInfoProvider.cs +++ /dev/null @@ -1,15 +0,0 @@ -using Microsoft.Extensions.DependencyInjection; -using System.Threading.Tasks; -using Volo.Abp.DependencyInjection; - -namespace LINGYUN.Abp.Identity.Session; - -[Dependency(ServiceLifetime.Singleton, TryRegister = true)] -public class NoneIpLocationInfoProvider : IIpLocationInfoProvider -{ - protected static readonly LocationInfo _nullCache = null; - public Task GetLocationInfoAsync(string ipAddress) - { - return Task.FromResult(_nullCache); - } -} From a27c465b9c78be70a3ff453745906503b8ee1e64 Mon Sep 17 00:00:00 2001 From: colin Date: Sat, 28 Dec 2024 11:09:08 +0800 Subject: [PATCH 2/2] refactor(ipregion): add FodyWeavers.xml. --- .../LINGYUN.Abp.AuditLogging.IP2Region/FodyWeavers.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aspnet-core/framework/auditing/LINGYUN.Abp.AuditLogging.IP2Region/FodyWeavers.xml b/aspnet-core/framework/auditing/LINGYUN.Abp.AuditLogging.IP2Region/FodyWeavers.xml index 00e1d9a1c..1715698cc 100644 --- a/aspnet-core/framework/auditing/LINGYUN.Abp.AuditLogging.IP2Region/FodyWeavers.xml +++ b/aspnet-core/framework/auditing/LINGYUN.Abp.AuditLogging.IP2Region/FodyWeavers.xml @@ -1,3 +1,3 @@ - - + + \ No newline at end of file