更新项目配置,新增设备同步模块,优化WebSocket和Swagger配置,增强SCADA系统的免登录接口,支持数据字典项和登录日志的免登录查询与记录。调整Java编译设置,确保更好的开发体验。
This commit is contained in:
69
yy-admin-master/YY.Admin/Module/SyncModule.cs
Normal file
69
yy-admin-master/YY.Admin/Module/SyncModule.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Polly;
|
||||
using Polly.Extensions.Http;
|
||||
using Prism.Ioc;
|
||||
using Prism.Modularity;
|
||||
using System.Net.Http;
|
||||
using YY.Admin.Core.Services;
|
||||
using YY.Admin.Infrastructure.Hubs;
|
||||
using YY.Admin.Infrastructure.Network;
|
||||
using YY.Admin.Infrastructure.Storage;
|
||||
using YY.Admin.Infrastructure.Sync;
|
||||
|
||||
namespace YY.Admin.Module;
|
||||
|
||||
public class SyncModule : IModule
|
||||
{
|
||||
public void RegisterTypes(IContainerRegistry containerRegistry)
|
||||
{
|
||||
containerRegistry.RegisterSingleton<TokenStore>();
|
||||
containerRegistry.RegisterSingleton<HttpSyncClient>();
|
||||
containerRegistry.RegisterSingleton<OutboxProcessor>();
|
||||
containerRegistry.RegisterSingleton<IJeecgUserMirrorPullOutbox, JeecgUserMirrorPullOutbox>();
|
||||
containerRegistry.RegisterSingleton<INetworkMonitor, NetworkMonitor>();
|
||||
containerRegistry.RegisterSingleton<ISignalRService, StompWebSocketService>();
|
||||
|
||||
var serviceCollection = new ServiceCollection();
|
||||
serviceCollection.AddHttpClient("JeecgApi", (sp, client) =>
|
||||
{
|
||||
var config = containerRegistry.GetContainer().Resolve<IConfiguration>();
|
||||
var baseUrl = config.GetValue<string>("JeecgIntegration:BaseUrl")?.TrimEnd('/');
|
||||
if (!string.IsNullOrWhiteSpace(baseUrl))
|
||||
{
|
||||
client.BaseAddress = new Uri(baseUrl);
|
||||
}
|
||||
|
||||
var tokenStore = containerRegistry.GetContainer().Resolve<TokenStore>();
|
||||
var token = tokenStore.GetTokenAsync(default).ConfigureAwait(false).GetAwaiter().GetResult();
|
||||
if (!string.IsNullOrWhiteSpace(token))
|
||||
{
|
||||
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
|
||||
}
|
||||
}).AddPolicyHandler(GetRetryPolicy());
|
||||
|
||||
var provider = serviceCollection.BuildServiceProvider();
|
||||
var httpClientFactory = provider.GetRequiredService<IHttpClientFactory>();
|
||||
containerRegistry.RegisterInstance(httpClientFactory);
|
||||
}
|
||||
|
||||
public void OnInitialized(IContainerProvider containerProvider)
|
||||
{
|
||||
var networkMonitor = containerProvider.Resolve<INetworkMonitor>();
|
||||
var outboxProcessor = containerProvider.Resolve<OutboxProcessor>();
|
||||
var signalService = containerProvider.Resolve<ISignalRService>();
|
||||
|
||||
_ = networkMonitor.StartAsync(CancellationToken.None);
|
||||
_ = outboxProcessor.StartConsumerAsync(CancellationToken.None);
|
||||
// 用户镜像 + 设备指令:统一 STOMP(/ws/device),免密与设备 Token 模式均启动
|
||||
_ = Task.Run(() => signalService.ConnectUnifiedDeviceChannelAsync(CancellationToken.None));
|
||||
}
|
||||
|
||||
private static IAsyncPolicy<HttpResponseMessage> GetRetryPolicy()
|
||||
{
|
||||
return HttpPolicyExtensions
|
||||
.HandleTransientHttpError()
|
||||
.WaitAndRetryAsync(3, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user