This commit is contained in:
Diego
2025-05-19 23:16:49 +08:00
parent 0f78f81c1c
commit 562b3f17c9
24 changed files with 471 additions and 56 deletions

View File

@@ -115,7 +115,7 @@ public sealed class OperDescAttribute : MoAttribute
private SysOperateLog GetOperLog(Type? localizerType, MethodContext context)
{
var methodBase = context.Method;
var clientInfo = AppService.ClientInfo;
var userAgent = AppService.UserAgent;
string? paramJson = null;
if (IsRecordPar)
{
@@ -138,8 +138,8 @@ public sealed class OperDescAttribute : MoAttribute
Category = LogCateGoryEnum.Operate,
ExeStatus = true,
OpIp = AppService?.RemoteIpAddress ?? string.Empty,
OpBrowser = clientInfo?.UA?.Family + clientInfo?.UA?.Major,
OpOs = clientInfo?.OS?.Family + clientInfo?.OS?.Major,
OpBrowser = userAgent?.Browser,
OpOs = userAgent?.Platform,
OpTime = DateTime.Now,
OpAccount = UserManager.UserAccount,
ReqUrl = null,

View File

@@ -55,7 +55,7 @@ public class HardwareJob : IJob, IHardwareJob
public async Task<List<HistoryHardwareInfo>> GetHistoryHardwareInfos()
{
using var db = DbContext.Db.GetConnectionScopeWithAttr<HistoryHardwareInfo>().CopyNew();
return await db.Queryable<HistoryHardwareInfo>().ToListAsync().ConfigureAwait(false);
return await db.Queryable<HistoryHardwareInfo>().Where(a => a.Date > DateTime.Now.AddDays(-3)).ToListAsync().ConfigureAwait(false);
}
private bool error = false;

View File

@@ -18,8 +18,6 @@ using ThingsGateway.Logging;
using ThingsGateway.NewLife.Json.Extension;
using ThingsGateway.Razor;
using UAParser;
namespace ThingsGateway.Admin.Application;
/// <summary>
@@ -53,7 +51,7 @@ public class DatabaseLoggingWriter : IDatabaseLoggingWriter
if (loggingMonitor.Validation == null)
{
var operation = logMsg.Context.Get(LoggingConst.Operation).ToString();//获取操作名称
var client = (ClientInfo)logMsg.Context.Get(LoggingConst.Client);//获取客户端信息
var client = (UserAgent)logMsg.Context.Get(LoggingConst.Client);//获取客户端信息
var path = logMsg.Context.Get(LoggingConst.Path).ToString();//获取操作名称
var method = logMsg.Context.Get(LoggingConst.Method).ToString();//获取方法
//表示访问日志
@@ -92,10 +90,10 @@ public class DatabaseLoggingWriter : IDatabaseLoggingWriter
/// <param name="operation">操作名称</param>
/// <param name="path">请求地址</param>
/// <param name="loggingMonitor">loggingMonitor</param>
/// <param name="clientInfo">客户端信息</param>
/// <param name="userAgent">客户端信息</param>
/// <param name="flush"></param>
/// <returns></returns>
private async Task<bool> CreateOperationLog(string operation, string path, LoggingMonitorJson loggingMonitor, ClientInfo clientInfo, bool flush)
private async Task<bool> CreateOperationLog(string operation, string path, LoggingMonitorJson loggingMonitor, UserAgent userAgent, bool flush)
{
//账号
var opAccount = loggingMonitor.AuthorizationClaims?.Where(it => it.Type == ClaimConst.Account).Select(it => it.Value).FirstOrDefault();
@@ -120,8 +118,8 @@ public class DatabaseLoggingWriter : IDatabaseLoggingWriter
Category = LogCateGoryEnum.Operate,
ExeStatus = true,
OpIp = loggingMonitor.RemoteIPv4,
OpBrowser = clientInfo?.UA?.Family + clientInfo?.UA?.Major,
OpOs = clientInfo?.OS?.Family + clientInfo?.OS?.Major,
OpBrowser = userAgent?.Browser,
OpOs = userAgent?.Platform,
OpTime = loggingMonitor.LogDateTime.LocalDateTime,
OpAccount = opAccount,
ReqMethod = loggingMonitor.HttpMethod,
@@ -161,9 +159,9 @@ public class DatabaseLoggingWriter : IDatabaseLoggingWriter
/// <param name="operation">访问类型</param>
/// <param name="path"></param>
/// <param name="loggingMonitor">loggingMonitor</param>
/// <param name="clientInfo">客户端信息</param>
/// <param name="userAgent">客户端信息</param>
/// <param name="flush"></param>
private async Task<bool> CreateVisitLog(string operation, string path, LoggingMonitorJson loggingMonitor, ClientInfo clientInfo, bool flush)
private async Task<bool> CreateVisitLog(string operation, string path, LoggingMonitorJson loggingMonitor, UserAgent userAgent, bool flush)
{
long verificatId = 0;//验证Id
var opAccount = "";//用户账号
@@ -188,8 +186,8 @@ public class DatabaseLoggingWriter : IDatabaseLoggingWriter
Category = path == "/api/auth/login" ? LogCateGoryEnum.Login : LogCateGoryEnum.Logout,
ExeStatus = true,
OpIp = loggingMonitor.RemoteIPv4,
OpBrowser = clientInfo?.UA?.Family + clientInfo?.UA?.Major,
OpOs = clientInfo?.OS?.Family + clientInfo?.OS?.Major,
OpBrowser = userAgent?.Browser,
OpOs = userAgent?.Platform,
OpTime = loggingMonitor.LogDateTime.LocalDateTime,
VerificatId = verificatId,
OpAccount = opAccount,

View File

@@ -15,12 +15,15 @@ using Microsoft.AspNetCore.WebUtilities;
using System.Security.Claims;
using UAParser;
namespace ThingsGateway.Admin.Application;
public class AppService : IAppService
{
private readonly IUserAgentService UserAgentService;
public AppService(IUserAgentService userAgentService)
{
UserAgentService = userAgentService;
}
public string GetReturnUrl(string returnUrl)
{
var url = QueryHelpers.AddQueryString(CookieAuthenticationDefaults.LoginPath, new Dictionary<string, string?>
@@ -41,18 +44,16 @@ public class AppService : IAppService
{
}
}
public Parser Parser = Parser.GetDefault();
public ClientInfo? ClientInfo
public UserAgent? UserAgent
{
get
{
var str = App.HttpContext?.Request?.Headers?.UserAgent;
ClientInfo? clientInfo = null;
if (!string.IsNullOrEmpty(str))
{
clientInfo = Parser.Parse(str);
return UserAgentService.Parse(str);
}
return clientInfo;
return null;
}
}

View File

@@ -13,19 +13,17 @@ using Microsoft.Extensions.DependencyInjection;
using System.Security.Claims;
using UAParser;
namespace ThingsGateway.Admin.Application;
public class HybridAppService : IAppService
{
public HybridAppService()
public HybridAppService(IUserAgentService userAgentService)
{
var str = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36 Edg/127.0.0.0";
ClientInfo = Parser.GetDefault().Parse(str);
UserAgent = userAgentService.Parse(str);
RemoteIpAddress = "127.0.0.1";
}
public ClientInfo? ClientInfo { get; }
public UserAgent? UserAgent { get; }
private static BlazorHybridAuthenticationStateProvider _authenticationStateProvider;
private static BlazorHybridAuthenticationStateProvider AuthenticationStateProvider

View File

@@ -11,8 +11,6 @@
using System.Security.Claims;
using UAParser;
namespace ThingsGateway.Admin.Application;
public interface IAppService
@@ -20,7 +18,7 @@ public interface IAppService
/// <summary>
/// ClientInfo
/// </summary>
public ClientInfo? ClientInfo { get; }
public UserAgent? UserAgent { get; }
/// <summary>
/// ClaimsPrincipal

View File

@@ -237,7 +237,7 @@ public class AuthService : IAuthService
var logingEvent = new LoginEvent
{
Ip = _appService.RemoteIpAddress,
Device = App.GetService<IAppService>().ClientInfo?.OS?.ToString(),
Device = App.GetService<IAppService>().UserAgent?.Platform,
Expire = expire,
SysUser = sysUser,
VerificatId = verificatId

View File

@@ -36,6 +36,7 @@ public class Startup : AppStartup
services.AddSingleton<ISugarAopService, SugarAopService>();
services.AddSingleton<ISugarConfigAopService, SugarConfigAopService>();
services.AddSingleton<IUserAgentService, UserAgentService>();
services.AddSingleton<IAppService, AppService>();
StaticConfig.EnableAllWhereIF = true;

View File

@@ -19,7 +19,6 @@
<ItemGroup>
<PackageReference Include="BootstrapBlazor.TableExport" Version="9.2.4" />
<PackageReference Include="UAParser" Version="3.1.47" />
<PackageReference Include="Rougamo.Fody" Version="5.0.0" />
<PackageReference Include="SqlSugarCore" Version="5.1.4.193" />
</ItemGroup>

View File

@@ -0,0 +1,14 @@
namespace ThingsGateway.Admin.Application
{
/// <summary>Default interface for UserAgentService</summary>
public interface IUserAgentService
{
/// <summary>Gets or sets the settings.</summary>
public UserAgentSettings Settings { get; set; }
/// <summary>Parses the specified user agent string.</summary>
/// <param name="userAgentString">The user agent string.</param>
/// <returns>An UserAgent object</returns>
UserAgent? Parse(string userAgentString);
}
}

View File

@@ -0,0 +1,145 @@
using System.Text.RegularExpressions;
namespace ThingsGateway.Admin.Application
{
/// <summary>
/// Parsed UserAgent object
/// </summary>
public class UserAgent
{
private readonly UserAgentSettings settings;
internal string Agent = "";
/// <summary>
/// Gets or sets a value indicating whether this UserAgent is a browser.
/// </summary>
/// <value>
/// <c>true</c> if this UserAgent is a browser; otherwise, <c>false</c>.
/// </value>
public bool IsBrowser { get; set; } = false;
/// <summary>
/// Gets or sets a value indicating whether this UserAgent is a robot.
/// </summary>
/// <value>
/// <c>true</c> if this UserAgent is a robot; otherwise, <c>false</c>.
/// </value>
public bool IsRobot { get; set; } = false;
/// <summary>
/// Gets or sets a value indicating whether this UserAgent is a mobile device.
/// </summary>
/// <value>
/// <c>true</c> if this UserAgent is a mobile device; otherwise, <c>false</c>.
/// </value>
public bool IsMobile { get; set; } = false;
/// <summary>
/// Gets or sets the platform.
/// </summary>
/// <value>
/// The platform or operating system.
/// </value>
public string Platform { get; set; } = "";
/// <summary>
/// Gets or sets the browser.
/// </summary>
/// <value>
/// The browser.
/// </value>
public string Browser { get; set; } = "";
/// <summary>
/// Gets or sets the browser version.
/// </summary>
/// <value>
/// The browser version.
/// </value>
public string BrowserVersion { get; set; } = "";
/// <summary>
/// Gets or sets the mobile device.
/// </summary>
/// <value>
/// The mobile device.
/// </value>
public string Mobile { get; set; } = "";
/// <summary>
/// Gets or sets the robot.
/// </summary>
/// <value>
/// The robot.
/// </value>
public string Robot { get; set; } = "";
internal UserAgent(UserAgentSettings settings, string? userAgentString = null)
{
this.settings = settings;
if (userAgentString != null)
{
Agent = userAgentString.Trim();
SetPlatform();
if (SetRobot()) return;
if (SetBrowser()) return;
if (SetMobile()) return;
}
}
internal bool SetPlatform()
{
foreach (var item in settings.Platforms)
{
if (Regex.IsMatch(Agent, $"{Regex.Escape(item.Key)}", RegexOptions.IgnoreCase))
{
Platform = item.Value;
return true;
}
}
Platform = "Unknown Platform";
return false;
}
internal bool SetBrowser()
{
foreach (var item in settings.Browsers)
{
var match = Regex.Match(Agent, $@"{item.Key}.*?([0-9\.]+)", RegexOptions.IgnoreCase);
if (match.Success)
{
IsBrowser = true;
BrowserVersion = match.Groups[1].Value;
Browser = item.Value;
SetMobile();
return true;
}
}
return false;
}
internal bool SetRobot()
{
foreach (var item in settings.Robots)
{
if (Regex.IsMatch(Agent, $"{Regex.Escape(item.Key)}", RegexOptions.IgnoreCase))
{
IsRobot = true;
Robot = item.Value;
SetMobile();
return true;
}
}
return false;
}
internal bool SetMobile()
{
foreach (var item in settings.Mobiles)
{
if (Agent?.IndexOf(item.Key, StringComparison.OrdinalIgnoreCase) != -1)
{
IsMobile = true;
Mobile = item.Value;
return true;
}
}
return false;
}
}
}

View File

@@ -0,0 +1,43 @@
using ThingsGateway.NewLife.Caching;
namespace ThingsGateway.Admin.Application
{
/// <summary>
/// The UserAgent service
/// </summary>
/// <seealso cref="ThingsGateway.Admin.Application.IUserAgentService" />
public class UserAgentService : IUserAgentService
{
/// <summary>
/// Gets or sets the settings.
/// </summary>
public UserAgentSettings Settings { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="UserAgentService"/> class.
/// </summary>
public UserAgentService()
{
Settings = new UserAgentSettings();
}
private MemoryCache MemoryCache { get; set; } = new();
/// <summary>
/// Parses the specified user agent string.
/// </summary>
/// <param name="userAgentString">The user agent string.</param>
/// <returns>
/// An UserAgent object
/// </returns>
public UserAgent? Parse(string? userAgentString)
{
userAgentString = ((userAgentString?.Length > Settings.UaStringSizeLimit) ? userAgentString?.Trim().Substring(0, Settings.UaStringSizeLimit) : userAgentString?.Trim()) ?? "";
return MemoryCache.GetOrAdd(userAgentString, entry =>
{
return new UserAgent(Settings, userAgentString);
});
}
}
}

View File

@@ -0,0 +1,214 @@
namespace ThingsGateway.Admin.Application
{
/// <summary>
/// UserAgent settings container.
/// </summary>
public class UserAgentSettings
{
/// <summary>
/// Gets or sets the maximum size of the useragent string. Limiting the length of the useragent string protects from hackers sending in extremely long user agent strings.
/// </summary>
public int UaStringSizeLimit { get; set; } = 512;
/// <summary>
/// Gets a dictionary containing mappings for platforms.
/// </summary>
public Dictionary<string, string> Platforms { get; } = new()
{
{"windows nt 10.0", "Windows 10"},
{"windows nt 6.3", "Windows 8.1"},
{"windows nt 6.2", "Windows 8"},
{"windows nt 6.1", "Windows 7"},
{"windows nt 6.0", "Windows Vista"},
{"windows nt 5.2", "Windows 2003"},
{"windows nt 5.1", "Windows XP"},
{"windows nt 5.0", "Windows 2000"},
{"windows nt 4.0", "Windows NT 4.0"},
{"winnt4.0", "Windows NT 4.0"},
{"winnt 4.0", "Windows NT"},
{"winnt", "Windows NT"},
{"windows 98", "Windows 98"},
{"win98", "Windows 98"},
{"windows 95", "Windows 95"},
{"win95", "Windows 95"},
{"windows phone", "Windows Phone"},
{"windows", "Unknown Windows OS"},
{"android", "Android"},
{"blackberry", "BlackBerry"},
{"iphone", "iOS"},
{"ipad", "iOS"},
{"ipod", "iOS"},
{"os x", "Mac OS X"},
{"ppc mac", "Power PC Mac"},
{"freebsd", "FreeBSD"},
{"ppc", "Macintosh"},
{"linux", "Linux"},
{"debian", "Debian"},
{"sunos", "Sun Solaris"},
{"beos", "BeOS"},
{"apachebench", "ApacheBench"},
{"aix", "AIX"},
{"irix", "Irix"},
{"osf", "DEC OSF"},
{"hp-ux", "HP-UX"},
{"netbsd", "NetBSD"},
{"bsdi", "BSDi"},
{"openbsd", "OpenBSD"},
{"gnu", "GNU/Linux"},
{"unix", "Unknown Unix OS"},
{"symbian", "Symbian OS"},
};
/// <summary>
/// Gets a dictionary containing mappings for browsers.
/// </summary>
public Dictionary<string, string> Browsers { get; } = new()
{
{"Microsoft Outlook", "Microsoft Outlook"},
{"OPR", "Opera"},
{"Flock", "Flock"},
{"Edge", "Edge"},
{"Edg", "Edge"},
{"Chrome", "Chrome"},
{"Opera.*?Version", "Opera"},
{"Opera", "Opera"},
{"MSIE", "Internet Explorer"},
{"Internet Explorer", "Internet Explorer"},
{"Trident.* rv" , "Internet Explorer"},
{"Shiira", "Shiira"},
{"Firefox", "Firefox"},
{"Chimera", "Chimera"},
{"Phoenix", "Phoenix"},
{"Firebird", "Firebird"},
{"Camino", "Camino"},
{"Netscape", "Netscape"},
{"OmniWeb", "OmniWeb"},
{"Safari", "Safari"},
{"Mozilla", "Mozilla"},
{"Konqueror", "Konqueror"},
{"icab", "iCab"},
{"Lynx", "Lynx"},
{"Links", "Links"},
{"hotjava", "HotJava"},
{"amaya", "Amaya"},
{"IBrowse", "IBrowse"},
{"Maxthon", "Maxthon"},
{"Ubuntu", "Ubuntu Web Browser"},
{"Vivaldi", "Vivaldi"},
};
/// <summary>
/// Gets a dictionary containing mappings for mobiles.
/// </summary>
public Dictionary<string, string> Mobiles { get; } = new()
{
// Legacy
{"mobileexplorer", "Mobile Explorer"},
{"palmsource", "Palm"},
{"palmscape", "Palmscape"},
// Phones and Manufacturers
{"motorola", "Motorola"},
{"nokia", "Nokia"},
{"palm", "Palm"},
{"iphone", "Apple iPhone"},
{"ipad", "iPad"},
{"ipod", "Apple iPod Touch"},
{"sony", "Sony Ericsson"},
{"ericsson", "Sony Ericsson"},
{"blackberry", "BlackBerry"},
{"cocoon", "O2 Cocoon"},
{"blazer", "Treo"},
{"lg", "LG"},
{"amoi", "Amoi"},
{"xda", "XDA"},
{"mda", "MDA"},
{"vario", "Vario"},
{"htc", "HTC"},
{"samsung", "Samsung"},
{"sharp", "Sharp"},
{"sie-", "Siemens"},
{"alcatel", "Alcatel"},
{"benq", "BenQ"},
{"ipaq", "HP iPaq"},
{"mot-", "Motorola"},
{"playstation portable", "PlayStation Portable"},
{"playstation 3", "PlayStation 3"},
{"playstation vita", "PlayStation Vita"},
{"hiptop", "Danger Hiptop"},
{"nec-", "NEC"},
{"panasonic", "Panasonic"},
{"philips", "Philips"},
{"sagem", "Sagem"},
{"sanyo", "Sanyo"},
{"spv", "SPV"},
{"zte", "ZTE"},
{"sendo", "Sendo"},
{"nintendo dsi", "Nintendo DSi"},
{"nintendo ds", "Nintendo DS"},
{"nintendo 3ds", "Nintendo 3DS"},
{"wii", "Nintendo Wii"},
{"open web", "Open Web"},
{"openweb", "OpenWeb"},
// Operating Systems
{"android", "Android"},
{"symbian", "Symbian"},
{"SymbianOS", "SymbianOS"},
{"elaine", "Palm"},
{"series60", "Symbian S60"},
{"windows ce", "Windows CE"},
// Browsers
{"obigo", "Obigo"},
{"netfront", "Netfront Browser"},
{"openwave", "Openwave Browser"},
{"mobilexplorer", "Mobile Explorer"},
{"operamini", "Opera Mini"},
{"opera mini", "Opera Mini"},
{"opera mobi", "Opera Mobile"},
{"fennec", "Firefox Mobile"},
// Other
{"digital paths", "Digital Paths"},
{"avantgo", "AvantGo"},
{"xiino", "Xiino"},
{"novarra", "Novarra Transcoder"},
{"vodafone", "Vodafone"},
{"docomo", "NTT DoCoMo"},
{"o2", "O2"},
// Fallback
{"mobile", "Generic Mobile"},
{"wireless", "Generic Mobile"},
{"j2me", "Generic Mobile"},
{"midp", "Generic Mobile"},
{"cldc", "Generic Mobile"},
{"up.link", "Generic Mobile"},
{"up.browser", "Generic Mobile"},
{"smartphone", "Generic Mobile"},
{"cellphone", "Generic Mobile"},
};
/// <summary>
/// Gets a dictionary containing mappings for robots.
/// </summary>
public Dictionary<string, string> Robots { get; } = new()
{
{"googlebot", "Googlebot"},
{"msnbot", "MSNBot"},
{"baiduspider", "Baiduspider"},
{"bingbot", "Bing"},
{"slurp", "Inktomi Slurp"},
{"yahoo", "Yahoo"},
{"ask jeeves", "Ask Jeeves"},
{"fastcrawler", "FastCrawler"},
{"infoseek", "InfoSeek Robot 1.0"},
{"lycos", "Lycos"},
{"yandex", "YandexBot"},
{"mediapartners-google", "MediaPartners Google"},
{"CRAZYWEBCRAWLER", "Crazy Webcrawler"},
{"adsbot-google", "AdsBot Google"},
{"feedfetcher-google", "Feedfetcher Google"},
{"curious george", "Curious George"},
{"ia_archiver", "Alexa Crawler"},
{"MJ12bot", "Majestic-12"},
{"Uptimebot", "Uptimebot"},
};
}
}

View File

@@ -220,7 +220,7 @@ public class Startup : AppStartup
var httpContext = context.HttpContext;//获取httpContext
//获取客户端信息
var client = App.GetService<IAppService>().ClientInfo;
var client = App.GetService<IAppService>().UserAgent;
// 获取控制器/操作描述器
var controllerActionDescriptor = context.ActionDescriptor as ControllerActionDescriptor;
//操作名称默认是控制器名加方法名,自定义操作名称要在action上加Description特性

View File

@@ -1,6 +1,8 @@
using System.Buffers;
using System.Runtime.CompilerServices;
using ThingsGateway.NewLife.Collections;
namespace ThingsGateway.NewLife.Buffers;
internal sealed class BufferSegment : ReadOnlySequenceSegment<Byte>
@@ -81,7 +83,7 @@ internal sealed class BufferSegment : ReadOnlySequenceSegment<Byte>
}
else if (_array != null)
{
ArrayPool<Byte>.Shared.Return(_array);
Pool.Shared.Return(_array);
_array = null;
}
base.Memory = default;

View File

@@ -1,5 +1,8 @@
using System.Buffers;
using ThingsGateway.NewLife.Collections;
#if NETFRAMEWORK || NETSTANDARD2_0
using ValueTask = System.Threading.Tasks.Task;
#endif
@@ -25,7 +28,7 @@ public sealed class PooledByteBufferWriter : IBufferWriter<Byte>, IDisposable
/// <param name="initialCapacity"></param>
public PooledByteBufferWriter(Int32 initialCapacity)
{
_rentedBuffer = ArrayPool<Byte>.Shared.Rent(initialCapacity);
_rentedBuffer = Pool.Shared.Rent(initialCapacity);
_index = 0;
}
@@ -42,7 +45,7 @@ public sealed class PooledByteBufferWriter : IBufferWriter<Byte>, IDisposable
/// <param name="initialCapacity"></param>
public void InitializeEmptyInstance(Int32 initialCapacity)
{
_rentedBuffer = ArrayPool<Byte>.Shared.Rent(initialCapacity);
_rentedBuffer = Pool.Shared.Rent(initialCapacity);
_index = 0;
}
@@ -60,7 +63,7 @@ public sealed class PooledByteBufferWriter : IBufferWriter<Byte>, IDisposable
var rentedBuffer = _rentedBuffer;
_rentedBuffer = null!;
ArrayPool<Byte>.Shared.Return(rentedBuffer);
Pool.Shared.Return(rentedBuffer);
}
/// <summary>通知 IBufferWriter已向输出写入 count 数据项。</summary>
@@ -116,11 +119,11 @@ public sealed class PooledByteBufferWriter : IBufferWriter<Byte>, IDisposable
}
}
var rentedBuffer = _rentedBuffer;
_rentedBuffer = ArrayPool<Byte>.Shared.Rent(num4);
_rentedBuffer = Pool.Shared.Rent(num4);
var span = rentedBuffer.AsSpan(0, _index);
span.CopyTo(_rentedBuffer);
span.Clear();
ArrayPool<Byte>.Shared.Return(rentedBuffer);
Pool.Shared.Return(rentedBuffer);
}
#endregion
}

View File

@@ -242,7 +242,7 @@ public static class SpanHelper
return;
}
var array = ArrayPool<Byte>.Shared.Rent(buffer.Length);
var array = Pool.Shared.Rent(buffer.Length);
try
{
@@ -252,7 +252,7 @@ public static class SpanHelper
}
finally
{
ArrayPool<Byte>.Shared.Return(array);
Pool.Shared.Return(array);
}
}
@@ -266,7 +266,7 @@ public static class SpanHelper
if (MemoryMarshal.TryGetArray(buffer, out var segment))
return stream.WriteAsync(segment.Array!, segment.Offset, segment.Count, cancellationToken);
var array = ArrayPool<Byte>.Shared.Rent(buffer.Length);
var array = Pool.Shared.Rent(buffer.Length);
buffer.Span.CopyTo(array);
var writeTask = stream.WriteAsync(array, 0, buffer.Length, cancellationToken);
@@ -278,7 +278,7 @@ public static class SpanHelper
}
finally
{
ArrayPool<Byte>.Shared.Return(array);
Pool.Shared.Return(array);
}
}, cancellationToken);
}

View File

@@ -157,7 +157,7 @@ public class Binary : FormatterBase, IBinary
#if NETCOREAPP || NETSTANDARD2_1_OR_GREATER
Stream.Write(buffer);
#else
var array = ArrayPool<Byte>.Shared.Rent(buffer.Length);
var array = Pool.Shared.Rent(buffer.Length);
try
{
buffer.CopyTo(array);
@@ -166,7 +166,7 @@ public class Binary : FormatterBase, IBinary
}
finally
{
ArrayPool<Byte>.Shared.Return(array);
Pool.Shared.Return(array);
}
#endif
}

View File

@@ -1,8 +1,8 @@
<Project>
<PropertyGroup>
<PluginVersion>10.6.7</PluginVersion>
<ProPluginVersion>10.6.7</ProPluginVersion>
<PluginVersion>10.6.11</PluginVersion>
<ProPluginVersion>10.6.11</ProPluginVersion>
<AuthenticationVersion>2.1.7</AuthenticationVersion>
</PropertyGroup>

View File

@@ -17,7 +17,7 @@ using TouchSocket.Sockets;
namespace ThingsGateway.Management;
internal partial class ReverseCallbackServer : SingletonRpcServer
internal sealed partial class ReverseCallbackServer : SingletonRpcServer
{
RedundancyHostedService RedundancyHostedService;
public ReverseCallbackServer(RedundancyHostedService redundancyHostedService)

View File

@@ -52,9 +52,8 @@ public class Startup : AppStartup
public void AddWebSiteServices(IServiceCollection services)
{
services.AddSingleton<IAuthRazorService, HybridAuthRazorService>();
var appService = new HybridAppService();
services.AddSingleton<IAppService, HybridAppService>(a => appService);
services.AddSingleton<HybridAppService>(a => appService);
services.AddSingleton<HybridAppService>();
services.AddSingleton<IAppService, HybridAppService>(a => a.GetService<HybridAppService>());
services.AddScoped<IPlatformService, HybridPlatformService>();
services.AddScoped<IGatewayExportService, HybridGatewayExportService>();
@@ -198,7 +197,7 @@ public class Startup : AppStartup
var httpContext = context.HttpContext;//获取httpContext
//获取客户端信息
var client = App.GetService<IAppService>().ClientInfo;
var client = App.GetService<IAppService>().UserAgent;
// 获取控制器/操作描述器
var controllerActionDescriptor = context.ActionDescriptor as ControllerActionDescriptor;
//操作名称默认是控制器名加方法名,自定义操作名称要在action上加Description特性

View File

@@ -220,7 +220,7 @@ public class Startup : AppStartup
var httpContext = context.HttpContext;//获取httpContext
//获取客户端信息
var client = App.GetService<IAppService>().ClientInfo;
var userAgent = App.GetService<IAppService>().UserAgent;
// 获取控制器/操作描述器
var controllerActionDescriptor = context.ActionDescriptor as ControllerActionDescriptor;
//操作名称默认是控制器名加方法名,自定义操作名称要在action上加Description特性
@@ -232,7 +232,7 @@ public class Startup : AppStartup
logContext.Set(LoggingConst.CateGory, option);//传操作名称
logContext.Set(LoggingConst.Operation, option);//传操作名称
logContext.Set(LoggingConst.Client, client);//客户端信息
logContext.Set(LoggingConst.Client, userAgent);//客户端信息
logContext.Set(LoggingConst.Path, httpContext.Request.Path.Value);//请求地址
logContext.Set(LoggingConst.Method, httpContext.Request.Method);//请求方法
});

View File

@@ -226,7 +226,7 @@ public class Startup : AppStartup
var httpContext = context.HttpContext;//获取httpContext
//获取客户端信息
var client = App.GetService<IAppService>().ClientInfo;
var client = App.GetService<IAppService>().UserAgent;
// 获取控制器/操作描述器
var controllerActionDescriptor = context.ActionDescriptor as ControllerActionDescriptor;
//操作名称默认是控制器名加方法名,自定义操作名称要在action上加Description特性

View File

@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>10.6.7</Version>
<Version>10.6.11</Version>
</PropertyGroup>
<ItemGroup>