Compare commits

...

3 Commits

Author SHA1 Message Date
Diego
cb0276f273 fix: opcuamaster插件属性UI未正确显示 2025-05-20 15:20:14 +08:00
Diego
562b3f17c9 10.6.11 2025-05-19 23:16:49 +08:00
Diego
0f78f81c1c 10.6.7 2025-05-19 18:43:03 +08:00
30 changed files with 511 additions and 101 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.6</PluginVersion>
<ProPluginVersion>10.6.6</ProPluginVersion>
<PluginVersion>10.6.12</PluginVersion>
<ProPluginVersion>10.6.12</ProPluginVersion>
<AuthenticationVersion>2.1.7</AuthenticationVersion>
</PropertyGroup>

View File

@@ -130,7 +130,7 @@ public class ControlController : ControllerBase
/// </summary>
[HttpPost("writeVariables")]
[DisplayName("写入变量")]
public async Task<Dictionary<string, Dictionary<string, IOperResult>>> WriteVariablesAsync([FromBody] Dictionary<string, Dictionary<string, string>> deviceDatas)
public async Task<Dictionary<string, Dictionary<string, OperResult>>> WriteVariablesAsync([FromBody] Dictionary<string, Dictionary<string, string>> deviceDatas)
{
foreach (var deviceData in deviceDatas)
{
@@ -141,7 +141,7 @@ public class ControlController : ControllerBase
}
}
return await GlobalData.RpcService.InvokeDeviceMethodAsync($"WebApi-{UserManager.UserAccount}-{App.HttpContext?.GetRemoteIpAddressToIPv4()}", deviceDatas).ConfigureAwait(false);
return (await GlobalData.RpcService.InvokeDeviceMethodAsync($"WebApi-{UserManager.UserAccount}-{App.HttpContext?.GetRemoteIpAddressToIPv4()}", deviceDatas).ConfigureAwait(false)).ToDictionary(a => a.Key, a => a.Value.ToDictionary(b => b.Key, b => (OperResult)b.Value));
}

View File

@@ -120,10 +120,7 @@ public class ChannelRuntime : Channel, IChannelOptions, IDisposable
// 通过插件名称获取插件信息
PluginInfo = GlobalData.PluginService.GetList().FirstOrDefault(A => A.FullName == PluginName);
if (PluginInfo == null)
{
//throw new Exception($"Plugin {PluginName} not found");
}
GlobalData.Channels.TryRemove(Id, out _);
GlobalData.Channels.TryAdd(Id, this);

View File

@@ -386,7 +386,7 @@ internal sealed class ChannelService : BaseService<Channel>, IChannelService
if (channel == null)
{
importPreviewOutput.HasError = true;
importPreviewOutput.Results.Add((row++, false, Localizer["ImportNullError"]));
importPreviewOutput.Results.Add((Interlocked.Increment(ref row), false, Localizer["ImportNullError"]));
return;
}
@@ -409,7 +409,7 @@ internal sealed class ChannelService : BaseService<Channel>, IChannelService
if (stringBuilder.Length > 0)
{
importPreviewOutput.HasError = true;
importPreviewOutput.Results.Add((row++, false, stringBuilder.ToString()));
importPreviewOutput.Results.Add((Interlocked.Increment(ref row), false, stringBuilder.ToString()));
return;
}
@@ -430,19 +430,19 @@ internal sealed class ChannelService : BaseService<Channel>, IChannelService
if (channel.IsUp && ((dataScope != null && dataScope?.Count > 0 && !dataScope.Contains(channel.CreateOrgId)) || dataScope?.Count == 0 && channel.CreateUserId != UserManager.UserId))
{
importPreviewOutput.Results.Add((row++, false, "Operation not permitted"));
importPreviewOutput.Results.Add((Interlocked.Increment(ref row), false, "Operation not permitted"));
}
else
{
channels.Add(channel);
importPreviewOutput.Results.Add((row++, true, null));
importPreviewOutput.Results.Add((Interlocked.Increment(ref row), true, null));
}
return;
}
catch (Exception ex)
{
importPreviewOutput.HasError = true;
importPreviewOutput.Results.Add((row++, false, ex.Message));
importPreviewOutput.Results.Add((Interlocked.Increment(ref row), false, ex.Message));
return;
}
});

View File

@@ -432,7 +432,7 @@ internal sealed class DeviceService : BaseService<Device>, IDeviceService
if (device == null)
{
importPreviewOutput.HasError = true;
importPreviewOutput.Results.Add((row++, false, Localizer["ImportNullError"]));
importPreviewOutput.Results.Add((Interlocked.Increment(ref row), false, Localizer["ImportNullError"]));
return;
}
@@ -449,7 +449,7 @@ internal sealed class DeviceService : BaseService<Device>, IDeviceService
{
// 如果找不到对应的冗余设备,则添加错误信息到导入预览结果并返回
importPreviewOutput.HasError = true;
importPreviewOutput.Results.Add((row++, false, Localizer["RedundantDeviceError"]));
importPreviewOutput.Results.Add((Interlocked.Increment(ref row), false, Localizer["RedundantDeviceError"]));
return;
}
}
@@ -459,7 +459,7 @@ internal sealed class DeviceService : BaseService<Device>, IDeviceService
if (device.RedundantEnable)
{
importPreviewOutput.HasError = true;
importPreviewOutput.Results.Add((row++, false, Localizer["RedundantDeviceError"]));
importPreviewOutput.Results.Add((Interlocked.Increment(ref row), false, Localizer["RedundantDeviceError"]));
return;
}
}
@@ -473,7 +473,7 @@ internal sealed class DeviceService : BaseService<Device>, IDeviceService
{
// 如果找不到对应的通道信息,则添加错误信息到导入预览结果并返回
importPreviewOutput.HasError = true;
importPreviewOutput.Results.Add((row++, false, Localizer["ChannelError"]));
importPreviewOutput.Results.Add((Interlocked.Increment(ref row), false, Localizer["ChannelError"]));
return;
}
}
@@ -481,7 +481,7 @@ internal sealed class DeviceService : BaseService<Device>, IDeviceService
{
// 如果未提供通道信息,则添加错误信息到导入预览结果并返回
importPreviewOutput.HasError = true;
importPreviewOutput.Results.Add((row++, false, Localizer["ChannelError"]));
importPreviewOutput.Results.Add((Interlocked.Increment(ref row), false, Localizer["ChannelError"]));
return;
}
@@ -504,7 +504,7 @@ internal sealed class DeviceService : BaseService<Device>, IDeviceService
if (stringBuilder.Length > 0)
{
importPreviewOutput.HasError = true;
importPreviewOutput.Results.Add((row++, false, stringBuilder.ToString()));
importPreviewOutput.Results.Add((Interlocked.Increment(ref row), false, stringBuilder.ToString()));
return;
}
@@ -527,12 +527,12 @@ internal sealed class DeviceService : BaseService<Device>, IDeviceService
// 将设备添加到设备列表中,并添加成功信息到导入预览结果
if (device.IsUp && ((dataScope != null && dataScope?.Count > 0 && !dataScope.Contains(device.CreateOrgId)) || dataScope?.Count == 0 && device.CreateUserId != UserManager.UserId))
{
importPreviewOutput.Results.Add((row++, false, "Operation not permitted"));
importPreviewOutput.Results.Add((Interlocked.Increment(ref row), false, "Operation not permitted"));
}
else
{
devices.Add(device);
importPreviewOutput.Results.Add((row++, true, null));
importPreviewOutput.Results.Add((Interlocked.Increment(ref row), true, null));
}
return;
}
@@ -540,7 +540,7 @@ internal sealed class DeviceService : BaseService<Device>, IDeviceService
{
// 捕获异常并添加错误信息到导入预览结果
importPreviewOutput.HasError = true;
importPreviewOutput.Results.Add((row++, false, ex.Message));
importPreviewOutput.Results.Add((Interlocked.Increment(ref row), false, ex.Message));
return;
}
});
@@ -573,7 +573,7 @@ internal sealed class DeviceService : BaseService<Device>, IDeviceService
if (driverPluginType == null)
{
importPreviewOutput.HasError = true;
importPreviewOutput.Results.Add((row++, false, Localizer["NotNull", sheetName]));
importPreviewOutput.Results.Add((Interlocked.Increment(ref row), false, Localizer["NotNull", sheetName]));
return;
}
@@ -617,7 +617,7 @@ internal sealed class DeviceService : BaseService<Device>, IDeviceService
if (propertys.Item1 == null)
{
importPreviewOutput.HasError = true;
importPreviewOutput.Results.Add((row++, false, Localizer["PluginNotNull"]));
importPreviewOutput.Results.Add((Interlocked.Increment(ref row), false, Localizer["PluginNotNull"]));
continue;
}
@@ -625,7 +625,7 @@ internal sealed class DeviceService : BaseService<Device>, IDeviceService
if (!item.TryGetValue(ExportString.DeviceName, out var deviceName))
{
importPreviewOutput.HasError = true;
importPreviewOutput.Results.Add((row++, false, Localizer["DeviceNotNull"]));
importPreviewOutput.Results.Add((Interlocked.Increment(ref row), false, Localizer["DeviceNotNull"]));
continue;
}
@@ -637,7 +637,7 @@ internal sealed class DeviceService : BaseService<Device>, IDeviceService
if (!hasDevice)
{
importPreviewOutput.HasError = true;
importPreviewOutput.Results.Add((row++, false, Localizer["NotNull", value]));
importPreviewOutput.Results.Add((Interlocked.Increment(ref row), false, Localizer["NotNull", value]));
continue;
}
@@ -648,7 +648,7 @@ internal sealed class DeviceService : BaseService<Device>, IDeviceService
if (pluginProp == null)
{
importPreviewOutput.HasError = true;
importPreviewOutput.Results.Add((row++, false, Localizer["ImportNullError"]));
importPreviewOutput.Results.Add((Interlocked.Increment(ref row), false, Localizer["ImportNullError"]));
return;
}
@@ -671,7 +671,7 @@ internal sealed class DeviceService : BaseService<Device>, IDeviceService
if (stringBuilder.Length > 0)
{
importPreviewOutput.HasError = true;
importPreviewOutput.Results.Add((row++, false, stringBuilder.ToString()));
importPreviewOutput.Results.Add((Interlocked.Increment(ref row), false, stringBuilder.ToString()));
return;
}
@@ -687,14 +687,14 @@ internal sealed class DeviceService : BaseService<Device>, IDeviceService
// 更新设备导入预览数据中对应设备的属性信息,并添加成功信息到导入预览结果
deviceImportPreview.Data[value].DevicePropertys = devices;
importPreviewOutput.Results.Add((row++, true, null));
importPreviewOutput.Results.Add((Interlocked.Increment(ref row), true, null));
continue;
}
catch (Exception ex)
{
// 捕获异常并添加错误信息到导入预览结果并返回
importPreviewOutput.HasError = true;
importPreviewOutput.Results.Add((row++, false, ex.Message));
importPreviewOutput.Results.Add((Interlocked.Increment(ref row), false, ex.Message));
return;
}
}

View File

@@ -619,7 +619,7 @@ internal sealed class VariableService : BaseService<Variable>, IVariableService
if (deviceId == null)
{
importPreviewOutput.HasError = true;
importPreviewOutput.Results.Add((Interlocked.Add(ref row, 1), false, Localizer["NotNull", deviceName]));
importPreviewOutput.Results.Add((Interlocked.Increment(ref row), false, Localizer["NotNull", deviceName]));
return;
}
// 手动补录变量ID和设备ID
@@ -642,7 +642,7 @@ internal sealed class VariableService : BaseService<Variable>, IVariableService
if (stringBuilder.Length > 0)
{
importPreviewOutput.HasError = true;
importPreviewOutput.Results.Add((Interlocked.Add(ref row, 1), false, stringBuilder.ToString()));
importPreviewOutput.Results.Add((Interlocked.Increment(ref row), false, stringBuilder.ToString()));
return;
}
@@ -661,19 +661,19 @@ internal sealed class VariableService : BaseService<Variable>, IVariableService
}
if (device.IsUp && ((dataScope != null && dataScope?.Count > 0 && !dataScope.Contains(variable.CreateOrgId)) || dataScope?.Count == 0 && variable.CreateUserId != UserManager.UserId))
{
importPreviewOutput.Results.Add((row++, false, "Operation not permitted"));
importPreviewOutput.Results.Add((Interlocked.Increment(ref row), false, "Operation not permitted"));
}
else
{
variables.Add(variable);
importPreviewOutput.Results.Add((Interlocked.Add(ref row, 1), true, null));
importPreviewOutput.Results.Add((Interlocked.Increment(ref row), true, null));
}
}
catch (Exception ex)
{
// 捕获异常并添加错误信息到导入预览结果
importPreviewOutput.HasError = true;
importPreviewOutput.Results.Add((Interlocked.Add(ref row, 1), false, ex.Message));
importPreviewOutput.Results.Add((Interlocked.Increment(ref row), false, ex.Message));
}
});
@@ -702,7 +702,7 @@ internal sealed class VariableService : BaseService<Variable>, IVariableService
if (driverPluginType == null)
{
importPreviewOutput.HasError = true;
importPreviewOutput.Results.Add((Interlocked.Add(ref row, 1), false, Localizer["NotNull", sheetName]));
importPreviewOutput.Results.Add((Interlocked.Increment(ref row), false, Localizer["NotNull", sheetName]));
return deviceImportPreview;
}
@@ -742,7 +742,7 @@ internal sealed class VariableService : BaseService<Variable>, IVariableService
if (propertys.Item3?.Count == null || propertys.Item1 == null)
{
importPreviewOutput.HasError = true;
importPreviewOutput.Results.Add((Interlocked.Add(ref row, 1), false, Localizer["ImportNullError"]));
importPreviewOutput.Results.Add((Interlocked.Increment(ref row), false, Localizer["ImportNullError"]));
return;
}
@@ -753,7 +753,7 @@ internal sealed class VariableService : BaseService<Variable>, IVariableService
if (pluginProp == null)
{
importPreviewOutput.HasError = true;
importPreviewOutput.Results.Add((Interlocked.Add(ref row, 1), false, Localizer["ImportNullError"]));
importPreviewOutput.Results.Add((Interlocked.Increment(ref row), false, Localizer["ImportNullError"]));
return;
}
@@ -768,13 +768,13 @@ internal sealed class VariableService : BaseService<Variable>, IVariableService
if (businessDevName == null || businessDevice == null || collectDevName == null || collectDevice == null)
{
importPreviewOutput.HasError = true;
importPreviewOutput.Results.Add((Interlocked.Add(ref row, 1), false, Localizer["DeviceNotNull"]));
importPreviewOutput.Results.Add((Interlocked.Increment(ref row), false, Localizer["DeviceNotNull"]));
return;
}
if (variableNameObj == null)
{
importPreviewOutput.HasError = true;
importPreviewOutput.Results.Add((Interlocked.Add(ref row, 1), false, Localizer["VariableNotNull"]));
importPreviewOutput.Results.Add((Interlocked.Increment(ref row), false, Localizer["VariableNotNull"]));
return;
}
@@ -797,7 +797,7 @@ internal sealed class VariableService : BaseService<Variable>, IVariableService
if (stringBuilder.Length > 0)
{
importPreviewOutput.HasError = true;
importPreviewOutput.Results.Add((Interlocked.Add(ref row, 1), false, stringBuilder.ToString()));
importPreviewOutput.Results.Add((Interlocked.Increment(ref row), false, stringBuilder.ToString()));
return;
}
@@ -818,12 +818,12 @@ internal sealed class VariableService : BaseService<Variable>, IVariableService
{
deviceVariable.VariablePropertys ??= new();
deviceVariable.VariablePropertys?.AddOrUpdate(businessDevice.Id, dependencyProperties);
importPreviewOutput.Results.Add((Interlocked.Add(ref row, 1), true, null));
importPreviewOutput.Results.Add((Interlocked.Increment(ref row), true, null));
}
else
{
importPreviewOutput.HasError = true;
importPreviewOutput.Results.Add((Interlocked.Add(ref row, 1), false, Localizer["VariableNotNull"]));
importPreviewOutput.Results.Add((Interlocked.Increment(ref row), false, Localizer["VariableNotNull"]));
return;
}
}
@@ -831,7 +831,7 @@ internal sealed class VariableService : BaseService<Variable>, IVariableService
{
// 捕获异常并添加错误信息到导入预览结果
importPreviewOutput.HasError = true;
importPreviewOutput.Results.Add((Interlocked.Add(ref row, 1), false, ex.Message));
importPreviewOutput.Results.Add((Interlocked.Increment(ref row), false, ex.Message));
}
});
}
@@ -839,7 +839,7 @@ internal sealed class VariableService : BaseService<Variable>, IVariableService
{
// 捕获异常并添加错误信息到导入预览结果
importPreviewOutput.HasError = true;
importPreviewOutput.Results.Add((Interlocked.Add(ref row, 1), false, ex.Message));
importPreviewOutput.Results.Add((Interlocked.Increment(ref row), false, ex.Message));
}
}

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

@@ -42,8 +42,6 @@ public class OpcUaMaster : CollectBase
/// <inheritdoc/>
public override Type DriverDebugUIType => typeof(ThingsGateway.Debug.OpcUaMaster);
public override Type DriverPropertyUIType => typeof(OpcUaMasterRuntimeRazor);
public override Type DriverUIType => typeof(OpcUaMasterRuntimeRazor);
protected override async Task InitChannelAsync(IChannel? channel, CancellationToken cancellationToken)

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.6</Version>
<Version>10.6.12</Version>
</PropertyGroup>
<ItemGroup>