diff --git a/src/TrackCenter.Application/Services/TrackPull/TrackPullService.cs b/src/TrackCenter.Application/Services/TrackPull/TrackPullService.cs index 2ac04742..0a649eca 100644 --- a/src/TrackCenter.Application/Services/TrackPull/TrackPullService.cs +++ b/src/TrackCenter.Application/Services/TrackPull/TrackPullService.cs @@ -101,7 +101,7 @@ public class TrackPullService : ApplicationServiceBase if (input.Options == OptionTypeNoNull.修改) isAnyExp = isAnyExp.And(x => x.Id != input.Id); if (await _trackPullConfigRepository.IsAnyAsync(isAnyExp)) - throw new BusinessException("配置不存在"); + throw new BusinessException("配置已经存在"); } switch (input.Options) diff --git a/src/TrackCenter.Application/TrackCenterApplicationModule.cs b/src/TrackCenter.Application/TrackCenterApplicationModule.cs index 4e8e0cca..6556d9d3 100644 --- a/src/TrackCenter.Application/TrackCenterApplicationModule.cs +++ b/src/TrackCenter.Application/TrackCenterApplicationModule.cs @@ -1,11 +1,15 @@ +using System.Diagnostics; using System.Net; using DotNetCore.CAP; using DotNetCore.CAP.Internal; +using DotNetCore.CAP.Messages; +using Fake; using Fake.AspNetCore; using Fake.EventBus.RabbitMQ; using Fake.Modularity; using Fake.ObjectMapping.AutoMapper; using Fake.RabbitMQ; +using FreeRedis; using Hangfire; using Hangfire.Redis.StackExchange; using InterfaceForward.Domain.Shared.Helpers; @@ -39,9 +43,10 @@ public class TrackCenterApplicationModule : FakeModule var rabbitOptions = configuration.GetSection("RabbitMQ").Get()!.Default; - //CAP + #region CAP + context.Services.AddSingleton(); - if (!System.Diagnostics.Debugger.IsAttached) + if (!Debugger.IsAttached) { context.Services.AddCap(options => { @@ -71,7 +76,7 @@ public class TrackCenterApplicationModule : FakeModule { LogHelper.Error($@" |-CAP失败回调事件: - |-处理类型:{(faileCalback.MessageType == DotNetCore.CAP.Messages.MessageType.Subscribe ? "消费消息达到最大重试次数,需要开发人员介入" : "生产消息推送失败")} + |-处理类型:{(faileCalback.MessageType == MessageType.Subscribe ? "消费消息达到最大重试次数,需要开发人员介入" : "生产消息推送失败")} |-头部信息:{faileCalback.Message.Headers.ToJson()}"); } catch (Exception ex) @@ -93,6 +98,13 @@ public class TrackCenterApplicationModule : FakeModule LogHelper.Info("-- 当前为本地环境,用内存存储和内存队列"); } + #endregion + + var options = configuration.GetSection("Redis").Get(); + if (options == null) + throw new FakeException("未找到Redis相关配置,请检查配置文件中是否包含名为Redis的节点"); + RedisHelper.Init(options, showLogInfo: Debugger.IsAttached); + context.Services.AddHostedService(); context.Services.Configure(options => { @@ -151,7 +163,7 @@ public class TrackCenterApplicationModule : FakeModule $",defaultDatabase={configuration["Redis:Database"]}" + $",abortConnect=false"; - // todo:注册预警计算服务 + // 注册预警计算服务 context.Services.AddWarningCalcServices(configuration); // 注册预警任务后台服务 diff --git a/src/TrackCenter.Repository/Redis/RedisHelper.cs b/src/TrackCenter.Repository/Redis/RedisHelper.cs index 7bb2af08..8dcd93ef 100644 --- a/src/TrackCenter.Repository/Redis/RedisHelper.cs +++ b/src/TrackCenter.Repository/Redis/RedisHelper.cs @@ -12,7 +12,7 @@ public static class RedisHelper #region 初始化方法 - internal static void Init(ConnectionStringBuilder options, bool showLogInfo) + public static void Init(ConnectionStringBuilder options, bool showLogInfo) { Options = options;