This commit is contained in:
Diego
2025-08-28 01:39:39 +08:00
parent 2078b4a60b
commit df067c91eb
38 changed files with 349 additions and 3180 deletions

View File

@@ -183,19 +183,22 @@ public class Startup : AppStartup
services.AddScoped<IAuthorizationHandler, BlazorServerAuthenticationHandler>();
services.AddScoped<AuthenticationStateProvider, BlazorServerAuthenticationStateProvider>();
if (!NewLife.Runtime.IsLegacyWindows)
{
#if NET9_0_OR_GREATER
var certificate = X509CertificateLoader.LoadPkcs12FromFile("ThingsGateway.pfx", "ThingsGateway", X509KeyStorageFlags.EphemeralKeySet);
var certificate = X509CertificateLoader.LoadPkcs12FromFile("ThingsGateway.pfx", "ThingsGateway", X509KeyStorageFlags.EphemeralKeySet);
#else
var certificate = new X509Certificate2("ThingsGateway.pfx", "ThingsGateway", X509KeyStorageFlags.EphemeralKeySet);
var certificate = new X509Certificate2("ThingsGateway.pfx", "ThingsGateway", X509KeyStorageFlags.EphemeralKeySet);
#endif
services.AddDataProtection()
.PersistKeysToFileSystem(new DirectoryInfo("Keys"))
.ProtectKeysWithCertificate(certificate)
.UseCryptographicAlgorithms(new AuthenticatedEncryptorConfiguration
{
EncryptionAlgorithm = EncryptionAlgorithm.AES_256_CBC,
ValidationAlgorithm = ValidationAlgorithm.HMACSHA256
});
services.AddDataProtection()
.PersistKeysToFileSystem(new DirectoryInfo("Keys"))
.ProtectKeysWithCertificate(certificate)
.UseCryptographicAlgorithms(new AuthenticatedEncryptorConfiguration
{
EncryptionAlgorithm = EncryptionAlgorithm.AES_256_CBC,
ValidationAlgorithm = ValidationAlgorithm.HMACSHA256
});
}
}
public void Use(IApplicationBuilder applicationBuilder, IWebHostEnvironment env)

View File

@@ -31,7 +31,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.4" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="$(NET9Version)" />
</ItemGroup>

View File

@@ -103,6 +103,54 @@ public static class Runtime
/// <summary>是否OSX环境</summary>
public static Boolean OSX => RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
#if NET6_0_OR_GREATER
public static Boolean? isLegacyWindows;
/// <summary>
/// 判断是否老系统 (Vista/2008/7/2008R2)
/// </summary>
public static Boolean IsLegacyWindows
{
get
{
if (isLegacyWindows != null) return isLegacyWindows.Value;
if (Windows == false)
{
isLegacyWindows = false;
return isLegacyWindows.Value;
}
var version = Environment.OSVersion.Version;
// 如果能拿到真实的 6.x 就直接判断
if (version.Major == 6 && version.Minor <= 1)
{
isLegacyWindows = true;
return isLegacyWindows.Value;
}
if (version.Major < 6)
{
isLegacyWindows = true;
return isLegacyWindows.Value;
}
// 如果拿到的是 10.0Win8.1 之后有虚拟化问题),用 OSDescription 来兜底
var desc = RuntimeInformation.OSDescription;
// desc 示例: "Microsoft Windows 6.1.7601" (Win7/2008R2)
if (desc.Contains("Windows 6.0") || desc.Contains("Windows 6.1"))
{
isLegacyWindows = true;
return isLegacyWindows.Value;
}
isLegacyWindows = false;
return isLegacyWindows.Value;
}
}
#endif
#else
/// <summary>是否Web环境</summary>
public static Boolean IsWeb => !String.IsNullOrEmpty(System.Web.HttpRuntime.AppDomainAppId);
@@ -115,6 +163,8 @@ public static class Runtime
/// <summary>是否OSX环境</summary>
public static Boolean OSX { get; } = Environment.OSVersion.Platform == PlatformID.MacOSX;
#endif
#endregion

View File

@@ -168,12 +168,13 @@ public class TimerScheduler : ILogFeature
_period = 60_000;
foreach (var timer in arr)
{
if (!timer.Calling && CheckTime(timer, now))
if ((timer.Reentrant || !timer.Calling) && CheckTime(timer, now))
{
// 必须在主线程设置状态,否则可能异步线程还没来得及设置开始状态,主线程又开始了新的一轮调度
timer.Calling = true;
if (timer.IsAsyncTask)
Task.Factory.StartNew(ExecuteAsync, timer, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default);
ExecuteAsync(timer);
//Task.Factory.StartNew(ExecuteAsync, timer, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default);
else if (!timer.Async)
Execute(timer);
else

View File

@@ -72,7 +72,8 @@ public class TimerX : ITimer, ITimerx, IDisposable
/// <summary>调用中</summary>
public Boolean Calling { get; internal set; }
/// <summary>可重入</summary>
public Boolean Reentrant { get; set; } = false;
/// <summary>平均耗时。毫秒</summary>
public Int32 Cost { get; internal set; }

View File

@@ -1,9 +1,9 @@
<Project>
<PropertyGroup>
<PluginVersion>10.11.10</PluginVersion>
<ProPluginVersion>10.11.10</ProPluginVersion>
<DefaultVersion>10.11.10</DefaultVersion>
<PluginVersion>10.11.12</PluginVersion>
<ProPluginVersion>10.11.12</ProPluginVersion>
<DefaultVersion>10.11.12</DefaultVersion>
<AuthenticationVersion>10.11.2</AuthenticationVersion>
<SourceGeneratorVersion>10.11.2</SourceGeneratorVersion>
<NET8Version>8.0.19</NET8Version>

File diff suppressed because it is too large Load Diff

View File

@@ -31,7 +31,7 @@ public class OtherChannel : SetupConfigObject, IClientChannel
public override TouchSocketConfig Config => base.Config ?? ChannelOptions.Config;
public void SetDataHandlingAdapterLogger(ILog log)
{
if (_deviceDataHandleAdapter == null && ReadOnlyDataHandlingAdapter is IDeviceDataHandleAdapter handleAdapter)
if (_deviceDataHandleAdapter != ReadOnlyDataHandlingAdapter && ReadOnlyDataHandlingAdapter is IDeviceDataHandleAdapter handleAdapter)
{
_deviceDataHandleAdapter = handleAdapter;
}

View File

@@ -50,7 +50,7 @@ public class SerialPortChannel : SerialPortClient, IClientChannel
private IDeviceDataHandleAdapter _deviceDataHandleAdapter;
public void SetDataHandlingAdapterLogger(ILog log)
{
if (_deviceDataHandleAdapter == null && ProtectedDataHandlingAdapter is IDeviceDataHandleAdapter handleAdapter)
if (_deviceDataHandleAdapter != ProtectedDataHandlingAdapter && ProtectedDataHandlingAdapter is IDeviceDataHandleAdapter handleAdapter)
{
_deviceDataHandleAdapter = handleAdapter;
}

View File

@@ -33,7 +33,7 @@ public class TcpClientChannel : TcpClient, IClientChannel
private IDeviceDataHandleAdapter _deviceDataHandleAdapter;
public void SetDataHandlingAdapterLogger(ILog log)
{
if (_deviceDataHandleAdapter == null && DataHandlingAdapter is IDeviceDataHandleAdapter handleAdapter)
if (_deviceDataHandleAdapter != DataHandlingAdapter && DataHandlingAdapter is IDeviceDataHandleAdapter handleAdapter)
{
_deviceDataHandleAdapter = handleAdapter;
}

View File

@@ -24,7 +24,7 @@ public class TcpSessionClientChannel : TcpSessionClient, IClientChannel
private IDeviceDataHandleAdapter _deviceDataHandleAdapter;
public void SetDataHandlingAdapterLogger(ILog log)
{
if (_deviceDataHandleAdapter == null && DataHandlingAdapter is IDeviceDataHandleAdapter handleAdapter)
if (_deviceDataHandleAdapter != DataHandlingAdapter && DataHandlingAdapter is IDeviceDataHandleAdapter handleAdapter)
{
_deviceDataHandleAdapter = handleAdapter;
}

View File

@@ -29,7 +29,7 @@ public class UdpSessionChannel : UdpSession, IClientChannel
private IDeviceDataHandleAdapter _deviceDataHandleAdapter;
public void SetDataHandlingAdapterLogger(ILog log)
{
if (_deviceDataHandleAdapter == null && DataHandlingAdapter is IDeviceDataHandleAdapter handleAdapter)
if (_deviceDataHandleAdapter != DataHandlingAdapter && DataHandlingAdapter is IDeviceDataHandleAdapter handleAdapter)
{
_deviceDataHandleAdapter = handleAdapter;
}

View File

@@ -17,7 +17,19 @@ namespace ThingsGateway.Foundation;
/// </summary>
public class DeviceSingleStreamDataHandleAdapter<TRequest> : CustomDataHandlingAdapter<TRequest>, IDeviceDataHandleAdapter where TRequest : MessageBase, new()
{
public new ILog Logger { get; set; }
private ILog logger;
public new ILog Logger
{
get => logger;
set
{
if (value != logger && value != null)
{
logger = value;
}
}
}
/// <inheritdoc cref="DeviceSingleStreamDataHandleAdapter{TRequest}"/>

View File

@@ -18,7 +18,19 @@ namespace ThingsGateway.Foundation;
/// </summary>
public class DeviceUdpDataHandleAdapter<TRequest> : UdpDataHandlingAdapter, IDeviceDataHandleAdapter where TRequest : MessageBase, new()
{
public new ILog Logger { get; set; }
private ILog logger;
public new ILog Logger
{
get => logger;
set
{
if (value != logger && value != null)
{
logger = value;
}
}
}
/// <inheritdoc/>
public override bool CanSendRequestInfo => true;

View File

@@ -11,8 +11,8 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="$(NET9Version)" />
<PackageReference Include="TouchSocket" Version="4.0.0-beta.3" />
<PackageReference Include="TouchSocket.SerialPorts" Version="4.0.0-beta.3" />
<PackageReference Include="TouchSocket" Version="4.0.0-beta.4" />
<PackageReference Include="TouchSocket.SerialPorts" Version="4.0.0-beta.4" />
</ItemGroup>
<ItemGroup>

View File

@@ -7,7 +7,7 @@ namespace ThingsGateway.Gateway.Application;
public class CronScheduledTask : DisposeBase, IScheduledTask
{
private int _interval10MS = 10;
private int next = -1;
private string _interval;
private readonly Func<object?, CancellationToken, Task> _taskFunc;
private readonly Func<object?, CancellationToken, ValueTask> _valueTaskFunc;
@@ -62,9 +62,9 @@ public class CronScheduledTask : DisposeBase, IScheduledTask
_timer?.Dispose();
if (Check()) return;
if (_taskAction != null)
_timer = new TimerX(TimerCallback, _state, _interval, nameof(IScheduledTask)) { Async = true };
_timer = new TimerX(TimerCallback, _state, _interval, nameof(CronScheduledTask)) { Async = true, Reentrant = true };
else if (_taskFunc != null || _valueTaskFunc != null)
_timer = new TimerX(TimerCallbackAsync, _state, _interval, nameof(IScheduledTask)) { Async = true };
_timer = new TimerX(TimerCallbackAsync, _state, _interval, nameof(CronScheduledTask)) { Async = true, Reentrant = true };
}
private async ValueTask TimerCallbackAsync(object? state)
@@ -107,7 +107,7 @@ public class CronScheduledTask : DisposeBase, IScheduledTask
{
if (!Check())
{
SetNext(_interval10MS);
SetNext(next);
}
}
}
@@ -149,7 +149,7 @@ public class CronScheduledTask : DisposeBase, IScheduledTask
{
if (!Check())
{
SetNext(_interval10MS);
SetNext(next);
}
}
}

View File

@@ -7,7 +7,7 @@ namespace ThingsGateway.Gateway.Application;
public class ScheduledAsyncTask : DisposeBase, IScheduledTask, IScheduledIntIntervalTask
{
private int _interval10MS = 10;
private int next = -1;
public int IntervalMS { get; }
private readonly Func<object?, CancellationToken, Task> _taskFunc;
private readonly Func<object?, CancellationToken, ValueTask> _valueTaskFunc;
@@ -48,7 +48,7 @@ public class ScheduledAsyncTask : DisposeBase, IScheduledTask, IScheduledIntInte
{
_timer?.Dispose();
if (!Check())
_timer = new TimerX(DoAsync, _state, IntervalMS, IntervalMS, nameof(IScheduledTask)) { Async = true };
_timer = new TimerX(DoAsync, _state, IntervalMS, IntervalMS, nameof(ScheduledAsyncTask)) { Async = true, Reentrant = true };
}
private async ValueTask DoAsync(object? state)
@@ -70,7 +70,6 @@ public class ScheduledAsyncTask : DisposeBase, IScheduledTask, IScheduledIntInte
// 减少一个触发次数
Interlocked.Decrement(ref _pendingTriggers);
try
{
if (_taskFunc != null)
@@ -92,9 +91,9 @@ public class ScheduledAsyncTask : DisposeBase, IScheduledTask, IScheduledIntInte
if (Interlocked.Exchange(ref _pendingTriggers, 0) >= 1)
{
if (!Check())
if (!Check() && IntervalMS > 8)
{
SetNext(_interval10MS);
SetNext(next);
}
}
}

View File

@@ -7,7 +7,7 @@ namespace ThingsGateway.Gateway.Application;
public class ScheduledSyncTask : DisposeBase, IScheduledTask, IScheduledIntIntervalTask
{
private int _interval10MS = 10;
private int next = -1;
public int IntervalMS { get; }
private readonly Action<object?, CancellationToken> _taskAction;
private readonly CancellationToken _token;
@@ -40,7 +40,7 @@ public class ScheduledSyncTask : DisposeBase, IScheduledTask, IScheduledIntInter
{
_timer?.Dispose();
if (!Check())
_timer = new TimerX(TimerCallback, _state, IntervalMS, IntervalMS, nameof(IScheduledTask)) { Async = true };
_timer = new TimerX(TimerCallback, _state, IntervalMS, IntervalMS, nameof(ScheduledSyncTask)) { Async = true, Reentrant = true };
}
private void TimerCallback(object? state)
@@ -78,9 +78,9 @@ public class ScheduledSyncTask : DisposeBase, IScheduledTask, IScheduledIntInter
if (Interlocked.Exchange(ref _pendingTriggers, 0) >= 1)
{
if (!Check())
if (!Check() && IntervalMS > 8)
{
SetNext(_interval10MS);
SetNext(next);
}
}
}

View File

@@ -31,7 +31,7 @@ namespace ThingsGateway.Gateway.Application;
[RequestAudit]
[ApiController]
[Authorize(AuthenticationSchemes = "Bearer")]
[TouchSocket.WebApi.Router("/miniapi/[api]/[action]")]
[TouchSocket.WebApi.Router("/miniapi/control/[action]")]
[TouchSocket.WebApi.EnableCors("cors")]
public class ControlController : ControllerBase, IRpcServer
{

View File

@@ -27,7 +27,7 @@ namespace ThingsGateway.Gateway.Application;
[ApiController]
[RolePermission]
[Authorize(AuthenticationSchemes = "Bearer")]
[TouchSocket.WebApi.Router("/miniapi/[api]/[action]")]
[TouchSocket.WebApi.Router("/miniapi/runtimeinfo/[action]")]
[TouchSocket.WebApi.EnableCors("cors")]
public class RuntimeInfoController : ControllerBase, IRpcServer
{

View File

@@ -18,7 +18,7 @@ namespace ThingsGateway.Gateway.Application;
[Route("api/[controller]/[action]")]
[AllowAnonymous]
[ApiController]
[TouchSocket.WebApi.Router("/miniapi/[api]/[action]")]
[TouchSocket.WebApi.Router("/miniapi/test/[action]")]
[TouchSocket.WebApi.EnableCors("cors")]
public class TestController : ControllerBase, IRpcServer
{

View File

@@ -87,6 +87,12 @@ public class ChannelRuntimeService : IChannelRuntimeService
}
public async Task RestartChannelsAsync()
{
var data = await GlobalData.GetCurrentUserChannels().ConfigureAwait(false);
await RestartChannelAsync(data.ToList()).ConfigureAwait(false);
}
public async Task SetChannelLogLevelAsync(long id, TouchSocket.Core.LogLevel logLevel)
{
if (GlobalData.IdChannels.TryGetValue(id, out var ChannelRuntime))

View File

@@ -20,6 +20,7 @@ namespace ThingsGateway.Gateway.Application
Task<string> GetPluginNameAsync(long channelId);
Task RestartChannelAsync(long channelId);
Task RestartChannelsAsync();
Task<TouchSocket.Core.LogLevel> ChannelLogLevelAsync(long id);
Task SetChannelLogLevelAsync(long id, TouchSocket.Core.LogLevel logLevel);

View File

@@ -34,12 +34,15 @@ public class DeviceRuntimeService : IDeviceRuntimeService
return Task.FromResult(GlobalData.ReadOnlyIdDevices.ToDictionary(a => a.Key, a => Tuple.Create(a.Value.Name, a.Value.PluginName)));
}
public async Task<List<SelectedItem>> GetDeviceItemsAsync(bool isCollect)
public async Task<QueryData<SelectedItem>> OnDeviceSelectedItemQueryAsync(VirtualizeQueryOption option, bool isCollect)
{
var devices = await GlobalData.GetCurrentUserDevices().ConfigureAwait(false);
return devices.Where(a => a.IsCollect == isCollect).BuildDeviceSelectList().ToList();
return devices.Where(a => a.IsCollect == isCollect).WhereIf(!option.SearchText.IsNullOrWhiteSpace(), a => a.Name.Contains(option.SearchText)).GetQueryData(option, GatewayResourceUtil.BuildDeviceSelectList);
}
public Task<string> GetDevicePluginNameAsync(long id)
{
return Task.FromResult(GlobalData.ReadOnlyIdDevices.TryGetValue(id, out var deviceRuntime) ? deviceRuntime.PluginName : string.Empty);

View File

@@ -42,7 +42,7 @@ namespace ThingsGateway.Gateway.Application
Task<bool> ClearDeviceAsync(bool restart);
Task<bool> IsRedundantDeviceAsync(long id);
Task<string> GetDeviceNameAsync(long redundantDeviceId);
Task<List<SelectedItem>> GetDeviceItemsAsync(bool isCollect);
Task<QueryData<SelectedItem>> OnDeviceSelectedItemQueryAsync(VirtualizeQueryOption option, bool isCollect);
Task<string> GetDevicePluginNameAsync(long id);
Task<Dictionary<long, Tuple<string, string>>> GetDeviceIdNamesAsync();

View File

@@ -14,25 +14,32 @@ using ThingsGateway.Authentication;
using TouchSocket.Dmtp.Rpc;
using TouchSocket.Rpc;
using TouchSocket.WebApi;
namespace ThingsGateway.Gateway.Application;
#if Management
[GeneratorRpcProxy(GeneratorFlag = GeneratorFlag.ExtensionAsync)]
#endif
[TouchSocket.WebApi.Router("/miniapi/managementrpc/[action]")]
public interface IManagementRpcServer : IRpcServer
{
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task<Dictionary<string, Dictionary<string, OperResult<object>>>> RpcAsync(ICallContext callContext, Dictionary<string, Dictionary<string, string>> deviceDatas);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task DeleteBackendLogAsync();
[DmtpRpc]
[WebApi(Method = HttpMethodType.Get)]
Task<List<BackendLog>> GetNewBackendLogAsync();
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task<QueryData<BackendLog>> BackendLogPageAsync(QueryPageOptions option);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Get)]
Task<List<BackendLogDayStatisticsOutput>> BackendLogStatisticsByDayAsync(int day);
@@ -43,6 +50,7 @@ public interface IManagementRpcServer : IRpcServer
/// 调用此方法会删除 RpcLog 表中的所有记录。
/// </remarks>
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task DeleteRpcLogAsync();
/// <summary>
@@ -50,6 +58,7 @@ public interface IManagementRpcServer : IRpcServer
/// </summary>
/// <returns>最新的十条记录</returns>
[DmtpRpc]
[WebApi(Method = HttpMethodType.Get)]
Task<List<RpcLog>> GetNewRpcLogAsync();
/// <summary>
@@ -58,6 +67,7 @@ public interface IManagementRpcServer : IRpcServer
/// <param name="option">查询选项</param>
/// <returns>查询到的数据</returns>
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task<QueryData<RpcLog>> RpcLogPageAsync(QueryPageOptions option);
/// <summary>
@@ -66,38 +76,52 @@ public interface IManagementRpcServer : IRpcServer
/// <param name="day">统计的天数</param>
/// <returns>按天统计的结果列表</returns>
[DmtpRpc]
[WebApi(Method = HttpMethodType.Get)]
Task<List<RpcLogDayStatisticsOutput>> RpcLogStatisticsByDayAsync(int day);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task RestartServerAsync();
[DmtpRpc]
[WebApi(Method = HttpMethodType.Get)]
Task<string> UUIDAsync();
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task<AuthorizeInfo> TryAuthorizeAsync(string password);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Get)]
Task<AuthorizeInfo> TryGetAuthorizeInfoAsync();
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task UnAuthorizeAsync();
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task<bool> StartBusinessChannelEnableAsync();
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task<bool> StartCollectChannelEnableAsync();
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task StartRedundancyTaskAsync();
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task StopRedundancyTaskAsync();
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task RedundancyForcedSync();
[DmtpRpc]
[WebApi(Method = HttpMethodType.Get)]
Task<TouchSocket.Core.LogLevel> RedundancyLogLevelAsync();
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task SetRedundancyLogLevelAsync(TouchSocket.Core.LogLevel logLevel);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Get)]
Task<string> RedundancyLogPathAsync();
/// <summary>
@@ -105,15 +129,19 @@ public interface IManagementRpcServer : IRpcServer
/// </summary>
/// <param name="input"></param>
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task EditRedundancyOptionAsync(RedundancyOptions input);
/// <summary>
/// 获取冗余设置
/// </summary>
[DmtpRpc]
[WebApi(Method = HttpMethodType.Get)]
Task<RedundancyOptions> GetRedundancyAsync();
[DmtpRpc]
[WebApi(Method = HttpMethodType.Get)]
Task<OperResult<List<string>>> GetLogFilesAsync(string directoryPath);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Get)]
Task<OperResult<List<LogData>>> LastLogDataAsync(string file, int lineCount = 200);
@@ -127,18 +155,21 @@ public interface IManagementRpcServer : IRpcServer
/// <param name="pluginType"></param>
/// <returns></returns>
[DmtpRpc]
[WebApi(Method = HttpMethodType.Get)]
Task<List<PluginInfo>> GetPluginsAsync(PluginTypeEnum? pluginType = null);
/// <summary>
/// 分页显示插件
/// </summary>
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task<QueryData<PluginInfo>> PluginPageAsync(QueryPageOptions options, PluginTypeEnum? pluginTypeEnum = null);
/// <summary>
/// 重载插件
/// </summary>
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task ReloadPluginAsync();
@@ -148,31 +179,41 @@ public interface IManagementRpcServer : IRpcServer
/// <param name="plugin"></param>
/// <returns></returns>
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task SavePluginByPathAsync(PluginAddPathInput plugin);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Get)]
Task<IEnumerable<AlarmVariable>> GetCurrentUserRealAlarmVariablesAsync();
[DmtpRpc]
[WebApi(Method = HttpMethodType.Get)]
Task<IEnumerable<SelectedItem>> GetCurrentUserDeviceSelectedItemsAsync(string searchText, int startIndex, int count);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Get)]
Task<QueryData<SelectedItem>> GetCurrentUserDeviceVariableSelectedItemsAsync(string deviceText, string searchText, int startIndex, int count);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Get)]
Task<TouchSocket.Core.LogLevel> RulesLogLevelAsync(long rulesId);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task SetRulesLogLevelAsync(long rulesId, TouchSocket.Core.LogLevel logLevel);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Get)]
Task<string> RulesLogPathAsync(long rulesId);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Get)]
Task<Rules> GetRuleRuntimesAsync(long rulesId);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task DeleteRuleRuntimesAsync(List<long> ids);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task EditRuleRuntimesAsync(Rules rules);
@@ -181,6 +222,7 @@ public interface IManagementRpcServer : IRpcServer
/// 清除所有规则
/// </summary>
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task ClearRulesAsync();
/// <summary>
@@ -188,6 +230,7 @@ public interface IManagementRpcServer : IRpcServer
/// </summary>
/// <param name="ids">待删除规则的ID列表</param>
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task<bool> DeleteRulesAsync(List<long> ids);
/// <summary>
@@ -195,6 +238,7 @@ public interface IManagementRpcServer : IRpcServer
/// </summary>
/// <returns>规则列表</returns>
[DmtpRpc]
[WebApi(Method = HttpMethodType.Get)]
Task<List<Rules>> GetAllAsync();
/// <summary>
@@ -203,6 +247,7 @@ public interface IManagementRpcServer : IRpcServer
/// <param name="option">查询条件</param>
/// <param name="filterKeyValueAction">查询条件</param>
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task<QueryData<Rules>> RulesPageAsync(QueryPageOptions option, FilterKeyValueAction filterKeyValueAction = null);
/// <summary>
@@ -211,61 +256,83 @@ public interface IManagementRpcServer : IRpcServer
/// <param name="input">规则对象</param>
/// <param name="type">保存类型</param>
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task<bool> SaveRulesAsync(Rules input, ItemChangedType type);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Get)]
Task<string> GetPluginNameAsync(long channelId);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task RestartChannelAsync(long channelId);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task RestartChannelsAsync();
[DmtpRpc]
[WebApi(Method = HttpMethodType.Get)]
Task<TouchSocket.Core.LogLevel> ChannelLogLevelAsync(long id);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task SetChannelLogLevelAsync(long id, TouchSocket.Core.LogLevel logLevel);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task CopyChannelAsync(int CopyCount, string CopyChannelNamePrefix, int CopyChannelNameSuffixNumber, string CopyDeviceNamePrefix, int CopyDeviceNameSuffixNumber, long channelId, bool AutoRestartThread);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task<QueryData<ChannelRuntime>> OnChannelQueryAsync(QueryPageOptions options);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task<List<Channel>> GetChannelListAsync(QueryPageOptions options, int max = 0);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task<bool> SaveChannelAsync(Channel input, ItemChangedType type, bool restart);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task<bool> BatchEditChannelAsync(List<Channel> models, Channel oldModel, Channel model, bool restart);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task<bool> DeleteChannelAsync(List<long> ids, bool restart);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task<bool> ClearChannelAsync(bool restart);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task ImportChannelAsync(List<Channel> upData, List<Channel> insertData, bool restart);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task<Dictionary<string, ImportPreviewOutputBase>> ImportChannelUSheetDatasAsync(USheetDatas input, bool restart);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task<Dictionary<string, ImportPreviewOutputBase>> ImportChannelFileAsync(string filePath, bool restart);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task<USheetDatas> ExportChannelAsync(List<Channel> channels);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task<string> ExportChannelFileAsync(GatewayExportFilter exportFilter);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task<QueryData<SelectedItem>> OnChannelSelectedItemQueryAsync(VirtualizeQueryOption option);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Get)]
Task<string> GetChannelNameAsync(long channelId);
@@ -273,98 +340,133 @@ public interface IManagementRpcServer : IRpcServer
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task SetDeviceLogLevelAsync(long id, TouchSocket.Core.LogLevel logLevel);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task CopyDeviceAsync(int CopyCount, string CopyDeviceNamePrefix, int CopyDeviceNameSuffixNumber, long deviceId, bool AutoRestartThread);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Get)]
Task<TouchSocket.Core.LogLevel> DeviceLogLevelAsync(long id);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task<bool> BatchEditDeviceAsync(List<Device> models, Device oldModel, Device model, bool restart);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task<bool> SaveDeviceAsync(Device input, ItemChangedType type, bool restart);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task<bool> DeleteDeviceAsync(List<long> ids, bool restart);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task<Dictionary<string, ImportPreviewOutputBase>> ImportDeviceUSheetDatasAsync(USheetDatas input, bool restart);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task<USheetDatas> ExportDeviceAsync(List<Device> devices);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task<string> ExportDeviceFileAsync(GatewayExportFilter exportFilter);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task<QueryData<SelectedItem>> OnRedundantDevicesQueryAsync(VirtualizeQueryOption option, long deviceId, long channelId);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task<Dictionary<string, ImportPreviewOutputBase>> ImportDeviceFileAsync(string filePath, bool restart);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task DeviceRedundantThreadAsync(long id);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task RestartDeviceAsync(long id, bool deleteCache);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task PauseThreadAsync(long id);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task<QueryData<DeviceRuntime>> OnDeviceQueryAsync(QueryPageOptions options);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task<List<Device>> GetDeviceListAsync(QueryPageOptions option, int v);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task<bool> ClearDeviceAsync(bool restart);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Get)]
Task<bool> IsRedundantDeviceAsync(long id);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Get)]
Task<string> GetDeviceNameAsync(long redundantDeviceId);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task<QueryData<SelectedItem>> OnDeviceSelectedItemQueryAsync(VirtualizeQueryOption option, bool isCollect);
[DmtpRpc]
Task<List<SelectedItem>> GetDeviceItemsAsync(bool isCollect);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Get)]
Task<string> GetDevicePluginNameAsync(long id);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task<bool> BatchEditVariableAsync(List<Variable> models, Variable oldModel, Variable model, bool restart);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task<bool> DeleteVariableAsync(List<long> ids, bool restart);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task<bool> ClearVariableAsync(bool restart);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task InsertTestDataAsync(int testVariableCount, int testDeviceCount, string slaveUrl, bool businessEnable, bool restart);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task<bool> BatchSaveVariableAsync(List<Variable> input, ItemChangedType type, bool restart);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task<bool> SaveVariableAsync(Variable input, ItemChangedType type, bool restart);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task CopyVariableAsync(List<Variable> Model, int CopyCount, string CopyVariableNamePrefix, int CopyVariableNameSuffixNumber, bool AutoRestartThread);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task<QueryData<VariableRuntime>> OnVariableQueryAsync(QueryPageOptions options);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task<string> ExportVariableFileAsync(GatewayExportFilter exportFilter);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task<List<Variable>> GetVariableListAsync(QueryPageOptions option, int v);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task<USheetDatas> ExportVariableAsync(List<Variable> models, string? sortName, SortOrder sortOrder);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task<Dictionary<string, ImportPreviewOutputBase>> ImportVariableUSheetDatasAsync(USheetDatas data, bool restart);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task<OperResult<object>> OnWriteVariableAsync(long id, string writeData);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task<Dictionary<string, ImportPreviewOutputBase>> ImportVariableFileAsync(string filePath, bool restart);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Get)]
Task<Dictionary<long, Tuple<string, string>>> GetDeviceIdNamesAsync();
}

View File

@@ -0,0 +1,18 @@
//------------------------------------------------------------------------------
// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
// 此代码版权除特别声明外的代码归作者本人Diego所有
// 源代码使用协议遵循本仓库的开源协议及附加协议
// Gitee源代码仓库https://gitee.com/diego2098/ThingsGateway
// Github源代码仓库https://github.com/kimdiego2098/ThingsGateway
// 使用文档https://thingsgateway.cn/
// QQ群605534569
//------------------------------------------------------------------------------
using TouchSocket.Rpc;
namespace ThingsGateway.Gateway.Application;
public interface IPluginRpcServer : IRpcServer
{
}

View File

@@ -132,7 +132,8 @@ public partial class ManagementRpcServer : IRpcServer, IManagementRpcServer, IBa
public Task RestartChannelAsync(long channelId) =>
App.GetService<IChannelPageService>().RestartChannelAsync(channelId);
public Task RestartChannelsAsync() =>
App.GetService<IChannelPageService>().RestartChannelsAsync();
public Task<LogLevel> ChannelLogLevelAsync(long id) =>
App.GetService<IChannelPageService>().ChannelLogLevelAsync(id);
@@ -246,8 +247,8 @@ public partial class ManagementRpcServer : IRpcServer, IManagementRpcServer, IBa
public Task<Dictionary<string, ImportPreviewOutputBase>> ImportDeviceAsync(IBrowserFile file, bool restart) =>
App.GetService<IDevicePageService>().ImportDeviceAsync(file, restart);
public Task<List<SelectedItem>> GetDeviceItemsAsync(bool isCollect) =>
App.GetService<IDevicePageService>().GetDeviceItemsAsync(isCollect);
public Task<QueryData<SelectedItem>> OnDeviceSelectedItemQueryAsync(VirtualizeQueryOption option, bool isCollect) =>
App.GetService<IDevicePageService>().OnDeviceSelectedItemQueryAsync(option, isCollect);
public Task<string> GetDevicePluginNameAsync(long id) =>
App.GetService<IDevicePageService>().GetDevicePluginNameAsync(id);

View File

@@ -103,6 +103,10 @@ public partial class ManagementTask : AsyncDisposableObject
store.RegisterServer<IManagementRpcServer>(new ManagementRpcServer());
store.RegisterServer<IUpgradeRpcServer>(new UpgradeRpcServer());
foreach (var type in App.EffectiveTypes.Where(p => typeof(IPluginRpcServer).IsAssignableFrom(p) && !p.IsAbstract && p.IsClass))
{
store.RegisterServer(type);
}
});
})
@@ -162,7 +166,10 @@ public partial class ManagementTask : AsyncDisposableObject
{
store.RegisterServer<IManagementRpcServer>(new ManagementRpcServer());
store.RegisterServer<IUpgradeRpcServer>(new UpgradeRpcServer());
foreach (var type in App.EffectiveTypes.Where(p => typeof(IPluginRpcServer).IsAssignableFrom(p) && !p.IsAbstract && p.IsClass))
{
store.RegisterServer(type);
}
});
})

View File

@@ -11,18 +11,22 @@
using TouchSocket.Dmtp.Rpc;
using TouchSocket.Rpc;
using TouchSocket.WebApi;
namespace ThingsGateway.Gateway.Application;
#if Management
[GeneratorRpcProxy(GeneratorFlag = GeneratorFlag.ExtensionAsync)]
#endif
[TouchSocket.WebApi.Router("/miniapi/upgrade/[action]")]
public interface IUpgradeRpcServer : IRpcServer
{
[DmtpRpc]
[WebApi(Method = HttpMethodType.Post)]
Task UpgradeAsync(ICallContext callContext, UpdateZipFile updateZipFile);
[DmtpRpc]
[WebApi(Method = HttpMethodType.Get)]
Task<UpdateZipFileInput> GetUpdateZipFileInputAsync(ICallContext callContext);
}

View File

@@ -11,7 +11,6 @@
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System.Diagnostics;
using System.Text;
using TouchSocket.Core;
@@ -89,6 +88,14 @@ public partial class WebApiTask : AsyncDisposableObject
store.RegisterServer<ControlController>();
store.RegisterServer<RuntimeInfoController>();
store.RegisterServer<TestController>();
store.RegisterServer<IManagementRpcServer>(new ManagementRpcServer());
store.RegisterServer<IUpgradeRpcServer>(new UpgradeRpcServer());
foreach (var type in App.EffectiveTypes.Where(p => typeof(IPluginRpcServer).IsAssignableFrom(p) && !p.IsAbstract && p.IsClass))
{
store.RegisterServer(type);
}
});
//添加跨域服务
@@ -112,9 +119,12 @@ public partial class WebApiTask : AsyncDisposableObject
a.UseWebApi();
if (App.WebHostEnvironment.IsDevelopment() || Debugger.IsAttached)
a.UseSwagger();
#if DEBUG
a.UseSwagger().SetPrefix("api");
#else
if (App.WebHostEnvironment.IsDevelopment())
a.UseSwagger().SetPrefix("api");
#endif
a.UseDefaultHttpServicePlugin();
});

View File

@@ -11,8 +11,8 @@
<PackageReference Include="Riok.Mapperly" Version="4.2.1" ExcludeAssets="runtime" PrivateAssets="all" />
<PackageReference Include="Rougamo.Fody" Version="5.0.1" />
<PackageReference Include="System.Linq.Async" Version="6.0.3" />
<PackageReference Include="TouchSocket.Dmtp" Version="4.0.0-beta.3" />
<PackageReference Include="TouchSocket.WebApi.Swagger" Version="4.0.0-beta.3" />
<PackageReference Include="TouchSocket.Dmtp" Version="4.0.0-beta.4" />
<PackageReference Include="TouchSocket.WebApi.Swagger" Version="4.0.0-beta.4" />
<PackageReference Include="ThingsGateway.Authentication" Version="$(AuthenticationVersion)" />
<!--<ProjectReference Include="..\..\PluginPro\ThingsGateway.Authentication\ThingsGateway.Authentication.csproj" />-->

View File

@@ -73,12 +73,22 @@ public partial class QuickActions
private List<SelectedItem> AutoRestartThreadBoolItems;
private static async Task Restart()
[Inject]
IChannelPageService ChannelPageService { get; set; }
#if Management
[Inject]
Management.Application.DmtpActorContext DmtpActorContext { get; set; }
#endif
private async Task Restart()
{
#if Management
if (DmtpActorContext.Current == null)
return;
#endif
await Task.Run(async () =>
{
var data = await GlobalData.GetCurrentUserChannels().ConfigureAwait(false);
await GlobalData.ChannelRuntimeService.RestartChannelAsync(data.ToList());
await ChannelPageService.RestartChannelsAsync();
});
}

View File

@@ -77,7 +77,7 @@
<EditTemplate Context="value">
<div class="col-12 col-md-6 ">
<BootstrapInputGroup>
<Select IsVirtualize @bind-Value="@value.DeviceId" DefaultVirtualizeItemText=@DeviceName IsDisabled=BatchEditEnable Items="@CollectDeviceItems" OnSelectedItemChanged=OnDeviceChanged ShowSearch="true" ShowLabel="true" />
<Select IsVirtualize @bind-Value="@value.DeviceId" DefaultVirtualizeItemText=@DeviceName IsDisabled=BatchEditEnable OnQueryAsync=OnCollectDeviceSelectedItemQueryAsync OnSelectedItemChanged=OnDeviceChanged ShowSearch="true" ShowLabel="true" />
<Button class="text-end" Icon="fa-solid fa-plus" OnClick="AddDevice" IsDisabled=BatchEditEnable></Button>
</BootstrapInputGroup>
</div>
@@ -198,7 +198,7 @@
<div class="row g-2 mx-1 form-inline">
<div class="col-12 col-md-8">
<Select SkipValidate IsVirtualize DefaultVirtualizeItemText=@(ChoiceBusinessDeviceName) @bind-Value="@ChoiceBusinessDeviceId" Items="@BusinessDeviceItems" ShowSearch="true" ShowLabel="true" />
<Select SkipValidate IsVirtualize @bind-Value="@ChoiceBusinessDeviceId" DefaultVirtualizeItemText=@ChoiceBusinessDeviceName IsDisabled=BatchEditEnable OnQueryAsync=OnBusinessDeviceSelectedItemQueryAsync ShowSearch="true" ShowLabel="true" />
</div>
<div class="col-12 col-md-4">
<Button OnClick="async() =>{

View File

@@ -41,9 +41,9 @@ public partial class VariableEditComponent
[Parameter]
public bool BatchEditEnable { get; set; }
private IEnumerable<SelectedItem> BusinessDeviceItems { get; set; }
//private IEnumerable<SelectedItem> BusinessDeviceItems { get; set; }
private IEnumerable<SelectedItem> CollectDeviceItems { get; set; }
//private IEnumerable<SelectedItem> CollectDeviceItems { get; set; }
[Inject]
IDevicePageService DevicePageService { get; set; }
private string DeviceName;
@@ -59,10 +59,14 @@ public partial class VariableEditComponent
OnInitialized();
await OnInitializedAsync();
OnParametersSet();
StateHasChanged();
ChoiceBusinessDeviceId = ChoiceBusinessDeviceId > 0 ? ChoiceBusinessDeviceId : (await DevicePageService.OnDeviceSelectedItemQueryAsync(new VirtualizeQueryOption() { Count = 1 }, false).ConfigureAwait(false)).Items.FirstOrDefault()?.Value?.ToLong() ?? 0;
ChoiceBusinessDeviceName = (await DevicePageService.GetDeviceNameAsync(ChoiceBusinessDeviceId)) ?? string.Empty;
await InvokeAsync(StateHasChanged);
await OnParametersSetAsync();
ChoiceBusinessDeviceId = ChoiceBusinessDeviceId > 0 ? ChoiceBusinessDeviceId : BusinessDeviceItems.FirstOrDefault()?.Value?.ToLong() ?? 0;
ChoiceBusinessDeviceName = await DevicePageService.GetDeviceNameAsync(ChoiceBusinessDeviceId);
}
else
{
@@ -72,8 +76,6 @@ public partial class VariableEditComponent
protected override async Task OnParametersSetAsync()
{
CollectDeviceItems = await DevicePageService.GetDeviceItemsAsync(true);
BusinessDeviceItems = await DevicePageService.GetDeviceItemsAsync(false);
if (Model.DeviceId > 0 && AddressUIType == null)
{
@@ -82,6 +84,14 @@ public partial class VariableEditComponent
await base.OnParametersSetAsync();
}
private Task<QueryData<SelectedItem>> OnCollectDeviceSelectedItemQueryAsync(VirtualizeQueryOption option)
{
return DevicePageService.OnDeviceSelectedItemQueryAsync(option, true);
}
private Task<QueryData<SelectedItem>> OnBusinessDeviceSelectedItemQueryAsync(VirtualizeQueryOption option)
{
return DevicePageService.OnDeviceSelectedItemQueryAsync(option, false);
}
[Parameter]
[EditorRequired]

View File

@@ -166,19 +166,22 @@ public class Startup : AppStartup
services.AddSignalR();
#endregion
if (!NewLife.Runtime.IsLegacyWindows)
{
#if NET9_0_OR_GREATER
var certificate = X509CertificateLoader.LoadPkcs12FromFile("ThingsGateway.pfx", "ThingsGateway", X509KeyStorageFlags.EphemeralKeySet);
var certificate = X509CertificateLoader.LoadPkcs12FromFile("ThingsGateway.pfx", "ThingsGateway", X509KeyStorageFlags.EphemeralKeySet);
#else
var certificate = new X509Certificate2("ThingsGateway.pfx", "ThingsGateway", X509KeyStorageFlags.EphemeralKeySet);
var certificate = new X509Certificate2("ThingsGateway.pfx", "ThingsGateway", X509KeyStorageFlags.EphemeralKeySet);
#endif
services.AddDataProtection()
.PersistKeysToFileSystem(new DirectoryInfo("Keys"))
.ProtectKeysWithCertificate(certificate)
.UseCryptographicAlgorithms(new AuthenticatedEncryptorConfiguration
{
EncryptionAlgorithm = EncryptionAlgorithm.AES_256_CBC,
ValidationAlgorithm = ValidationAlgorithm.HMACSHA256
});
services.AddDataProtection()
.PersistKeysToFileSystem(new DirectoryInfo("Keys"))
.ProtectKeysWithCertificate(certificate)
.UseCryptographicAlgorithms(new AuthenticatedEncryptorConfiguration
{
EncryptionAlgorithm = EncryptionAlgorithm.AES_256_CBC,
ValidationAlgorithm = ValidationAlgorithm.HMACSHA256
});
}
}
public void Use(IApplicationBuilder applicationBuilder, IWebHostEnvironment env)

View File

@@ -235,19 +235,23 @@ public class Startup : AppStartup
services.AddScoped<IAuthorizationHandler, BlazorServerAuthenticationHandler>();
services.AddScoped<AuthenticationStateProvider, BlazorServerAuthenticationStateProvider>();
if (!NewLife.Runtime.IsLegacyWindows)
{
#if NET9_0_OR_GREATER
var certificate = X509CertificateLoader.LoadPkcs12FromFile("ThingsGateway.pfx", "ThingsGateway", X509KeyStorageFlags.EphemeralKeySet);
var certificate = X509CertificateLoader.LoadPkcs12FromFile("ThingsGateway.pfx", "ThingsGateway", X509KeyStorageFlags.EphemeralKeySet);
#else
var certificate = new X509Certificate2("ThingsGateway.pfx", "ThingsGateway", X509KeyStorageFlags.EphemeralKeySet);
var certificate = new X509Certificate2("ThingsGateway.pfx", "ThingsGateway", X509KeyStorageFlags.EphemeralKeySet);
#endif
services.AddDataProtection()
.PersistKeysToFileSystem(new DirectoryInfo("Keys"))
.ProtectKeysWithCertificate(certificate)
.UseCryptographicAlgorithms(new AuthenticatedEncryptorConfiguration
{
EncryptionAlgorithm = EncryptionAlgorithm.AES_256_CBC,
ValidationAlgorithm = ValidationAlgorithm.HMACSHA256
});
services.AddDataProtection()
.PersistKeysToFileSystem(new DirectoryInfo("Keys"))
.ProtectKeysWithCertificate(certificate)
.UseCryptographicAlgorithms(new AuthenticatedEncryptorConfiguration
{
EncryptionAlgorithm = EncryptionAlgorithm.AES_256_CBC,
ValidationAlgorithm = ValidationAlgorithm.HMACSHA256
});
}
}
}