From 22c2e01b8055ab5bd2ba7f6fd6ca39c5da66d765 Mon Sep 17 00:00:00 2001 From: cKey <35512826+colinin@users.noreply.github.com> Date: Wed, 16 Jun 2021 14:29:33 +0800 Subject: [PATCH] using System.Text.Json --- aspnet-core/LINGYUN.MicroService.All.sln | 21 ++-- aspnet-core/LINGYUN.MicroService.Common.sln | 14 +-- ...bp.AspNetCore.SignalR.Protocol.Json.csproj | 2 +- .../AbpAspNetCoreSignalRProtocolJsonModule.cs | 16 ++- .../Json/JsonHubProtocolOptionsSetup.cs | 23 ++++ ...AspNetCoreSignalRJwtTokenMapPathOptions.cs | 6 +- .../LINGYUN.Abp.EventBus.CAP.csproj | 3 +- .../LINGYUN.Abp.EventBus.CAP.xml | 6 +- .../CAP/AbpCAPExecutionFailedException.cs | 18 +-- .../EventBus/CAP/AbpCAPSubscribeInvoker.cs | 45 ++++++- .../Abp/EventBus/CAP/AbpCapSerializer.cs | 78 ++++++++++++ .../ServiceCollectionExtensions.cs | 2 + .../LINGYUN.Abp.EventBus.CAP.xml | 6 +- .../Messages/SignalRMessageSenderProvider.cs | 15 ++- .../LINGYUN.Abp.IM/LINGYUN.Abp.IM.csproj | 4 + .../LINGYUN/Abp/IM/Messages/ChatMessage.cs | 3 + .../LINGYUN/Abp/IM/Messages/IMessageSender.cs | 2 +- .../LINGYUN/Abp/IM/Messages/MessageSender.cs | 18 ++- .../SignalRNotificationPublishProvider.cs | 2 +- .../LINGYUN.Abp.Notifications.csproj | 4 + .../Notifications/AbpNotificationOptions.cs | 5 - .../Abp/Notifications/INotificationSender.cs | 6 +- .../Internal/NotificationSender.cs | 46 ++++--- .../Abp/Notifications/NotificationData.cs | 3 + .../Abp/Notifications/NotificationEto.cs | 51 ++++++++ .../LINGYUN.Abp.RealTime.csproj | 1 + .../LINGYUN/Abp/RealTime/AbpRealTimeModule.cs | 13 +- .../Abp/RealTime/ISnowflakeIdrGenerator.cs | 7 ++ .../LINGYUN/Abp/RealTime/RealTimeEto.cs | 21 ++++ .../Abp/RealTime}/SnowflakeIdOptions.cs | 2 +- .../Abp/RealTime/SnowflakeIdrGenerator.cs} | 6 +- .../Abp/MessageService/Chat/ChatAppService.cs | 4 +- .../AbpMessageServiceDomainModule.cs | 11 -- .../Abp/MessageService/Chat/MessageStore.cs | 27 ++-- .../Notifications/NotificationStore.cs | 14 +-- .../Utils/ISnowflakeIdGenerator.cs | 7 -- .../AuthIdentityServerModule.cs | 15 +-- .../BackendAdminHostModule.cs | 15 +-- .../AbpApiGatewayHostModule.cs | 15 +-- .../ApiGatewayHostModule.cs | 15 +-- .../ApiGatewayHttpApiHostModule.cs | 15 +-- ...AbpIdentityServerAdminHttpApiHostModule.cs | 28 +---- ...LocalizationManagementHttpApiHostModule.cs | 12 +- .../AbpMessageServiceHttpApiHostModule.cs | 15 +-- .../Distributed/ChatMessageEventHandler.cs | 9 +- .../Distributed/NotificationEventHandler.cs | 24 ++-- .../AppPlatformHttpApiHostModule.cs | 15 +-- .../DomainTenantResolveContributor.cs | 40 ------ .../HeaderTenantResolveContributor.cs | 50 -------- .../TenantConfigurationProvider.cs | 66 ---------- .../TenantResolver.cs | 48 -------- build/build-aspnetcore-release.ps1 | 1 + docker-compose.override.windows.yml | 84 +++++++++++++ docker-compose.override.yml | 116 +++++++++++------- docker-compose.yml | 116 +++++++----------- 55 files changed, 650 insertions(+), 561 deletions(-) create mode 100644 aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.SignalR.Protocol.Json/LINGYUN/Abp/AspNetCore/SignalR/Protocol/Json/JsonHubProtocolOptionsSetup.cs create mode 100644 aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN/Abp/EventBus/CAP/AbpCapSerializer.cs create mode 100644 aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationEto.cs create mode 100644 aspnet-core/modules/common/LINGYUN.Abp.RealTime/LINGYUN/Abp/RealTime/ISnowflakeIdrGenerator.cs create mode 100644 aspnet-core/modules/common/LINGYUN.Abp.RealTime/LINGYUN/Abp/RealTime/RealTimeEto.cs rename aspnet-core/modules/{message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Utils => common/LINGYUN.Abp.RealTime/LINGYUN/Abp/RealTime}/SnowflakeIdOptions.cs (92%) rename aspnet-core/modules/{message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Utils/SnowflakeIdGenerator.cs => common/LINGYUN.Abp.RealTime/LINGYUN/Abp/RealTime/SnowflakeIdrGenerator.cs} (94%) delete mode 100644 aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Utils/ISnowflakeIdGenerator.cs delete mode 100644 aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/DomainTenantResolveContributor.cs delete mode 100644 aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/HeaderTenantResolveContributor.cs delete mode 100644 aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/TenantConfigurationProvider.cs delete mode 100644 aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/TenantResolver.cs create mode 100644 docker-compose.override.windows.yml diff --git a/aspnet-core/LINGYUN.MicroService.All.sln b/aspnet-core/LINGYUN.MicroService.All.sln index 12644c928..01b61ee50 100644 --- a/aspnet-core/LINGYUN.MicroService.All.sln +++ b/aspnet-core/LINGYUN.MicroService.All.sln @@ -115,8 +115,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Hangfire.Storag EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.BackgroundJobs.Hangfire", "modules\common\LINGYUN.Abp.BackgroundJobs.Hangfire\LINGYUN.Abp.BackgroundJobs.Hangfire.csproj", "{5CF403B2-47C9-4E4E-8856-0294BDD64884}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.BackgroundJobs", "modules\common\LINGYUN.Abp.BackgroundJobs\LINGYUN.Abp.BackgroundJobs.csproj", "{8A22674D-151D-474E-8C99-9D991C0D8297}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.BlobStoring.Aliyun", "modules\common\LINGYUN.Abp.BlobStoring.Aliyun\LINGYUN.Abp.BlobStoring.Aliyun.csproj", "{059473BA-FAF9-405F-9985-33DDCA2E9F0D}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{370D7CD5-1E17-4F3D-BBFA-03429F6D4F2F}" @@ -331,6 +329,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.AspNetCore.Http EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.ApiGateway.Host", "services\apigateway\LINGYUN.Abp.ApiGateway.Host\LINGYUN.Abp.ApiGateway.Host.csproj", "{A320E23E-792D-4736-B963-381F9D7AF605}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.BackgroundWorkers.Hangfire", "modules\common\LINGYUN.Abp.BackgroundWorkers.Hangfire\LINGYUN.Abp.BackgroundWorkers.Hangfire.csproj", "{60D0BEF2-FEAF-4066-8377-6C873CB24858}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Hangfire.Dashboard", "modules\common\LINGYUN.Abp.Hangfire.Dashboard\LINGYUN.Abp.Hangfire.Dashboard.csproj", "{340BE5AC-68EC-41A5-9D0D-266037C58F13}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -509,10 +511,6 @@ Global {5CF403B2-47C9-4E4E-8856-0294BDD64884}.Debug|Any CPU.Build.0 = Debug|Any CPU {5CF403B2-47C9-4E4E-8856-0294BDD64884}.Release|Any CPU.ActiveCfg = Release|Any CPU {5CF403B2-47C9-4E4E-8856-0294BDD64884}.Release|Any CPU.Build.0 = Release|Any CPU - {8A22674D-151D-474E-8C99-9D991C0D8297}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8A22674D-151D-474E-8C99-9D991C0D8297}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8A22674D-151D-474E-8C99-9D991C0D8297}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8A22674D-151D-474E-8C99-9D991C0D8297}.Release|Any CPU.Build.0 = Release|Any CPU {059473BA-FAF9-405F-9985-33DDCA2E9F0D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {059473BA-FAF9-405F-9985-33DDCA2E9F0D}.Debug|Any CPU.Build.0 = Debug|Any CPU {059473BA-FAF9-405F-9985-33DDCA2E9F0D}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -865,6 +863,14 @@ Global {A320E23E-792D-4736-B963-381F9D7AF605}.Debug|Any CPU.Build.0 = Debug|Any CPU {A320E23E-792D-4736-B963-381F9D7AF605}.Release|Any CPU.ActiveCfg = Release|Any CPU {A320E23E-792D-4736-B963-381F9D7AF605}.Release|Any CPU.Build.0 = Release|Any CPU + {60D0BEF2-FEAF-4066-8377-6C873CB24858}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {60D0BEF2-FEAF-4066-8377-6C873CB24858}.Debug|Any CPU.Build.0 = Debug|Any CPU + {60D0BEF2-FEAF-4066-8377-6C873CB24858}.Release|Any CPU.ActiveCfg = Release|Any CPU + {60D0BEF2-FEAF-4066-8377-6C873CB24858}.Release|Any CPU.Build.0 = Release|Any CPU + {340BE5AC-68EC-41A5-9D0D-266037C58F13}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {340BE5AC-68EC-41A5-9D0D-266037C58F13}.Debug|Any CPU.Build.0 = Debug|Any CPU + {340BE5AC-68EC-41A5-9D0D-266037C58F13}.Release|Any CPU.ActiveCfg = Release|Any CPU + {340BE5AC-68EC-41A5-9D0D-266037C58F13}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -924,7 +930,6 @@ Global {47CC8F7A-681D-42B9-AE04-78453782C1B6} = {8AC72641-30D3-4ACF-89FA-808FADC55C2E} {F595CB9F-B117-4D62-A1AE-48599927DB36} = {8AC72641-30D3-4ACF-89FA-808FADC55C2E} {5CF403B2-47C9-4E4E-8856-0294BDD64884} = {8AC72641-30D3-4ACF-89FA-808FADC55C2E} - {8A22674D-151D-474E-8C99-9D991C0D8297} = {8AC72641-30D3-4ACF-89FA-808FADC55C2E} {059473BA-FAF9-405F-9985-33DDCA2E9F0D} = {14CDBAD1-10C8-464A-B445-1F727C988010} {B39B5FB6-E7B9-4A13-8FFA-FC7FEED4371B} = {370D7CD5-1E17-4F3D-BBFA-03429F6D4F2F} {C8A00439-5B8D-4923-8FAA-AB75E2A786ED} = {370D7CD5-1E17-4F3D-BBFA-03429F6D4F2F} @@ -1028,6 +1033,8 @@ Global {8EF31071-3521-409D-9740-BBFBFC04C50E} = {370D7CD5-1E17-4F3D-BBFA-03429F6D4F2F} {13219C1C-23E1-4EBA-93FB-86830C93A800} = {8AC72641-30D3-4ACF-89FA-808FADC55C2E} {A320E23E-792D-4736-B963-381F9D7AF605} = {19E6BD61-062B-4FAD-A51A-B55F5CE88B7A} + {60D0BEF2-FEAF-4066-8377-6C873CB24858} = {8AC72641-30D3-4ACF-89FA-808FADC55C2E} + {340BE5AC-68EC-41A5-9D0D-266037C58F13} = {8AC72641-30D3-4ACF-89FA-808FADC55C2E} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {C95FDF91-16F2-4A8B-A4BE-0E62D1B66718} diff --git a/aspnet-core/LINGYUN.MicroService.Common.sln b/aspnet-core/LINGYUN.MicroService.Common.sln index e824abd97..d3706cecd 100644 --- a/aspnet-core/LINGYUN.MicroService.Common.sln +++ b/aspnet-core/LINGYUN.MicroService.Common.sln @@ -17,8 +17,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.AspNetCore.Sign EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.AspNetCore.SignalR.JwtToken", "modules\common\LINGYUN.Abp.AspNetCore.SignalR\LINGYUN.Abp.AspNetCore.SignalR.JwtToken.csproj", "{304D06E6-41EC-4DCB-AEAE-DBEEC75F9ADC}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.BackgroundJobs", "modules\common\LINGYUN.Abp.BackgroundJobs\LINGYUN.Abp.BackgroundJobs.csproj", "{FFC21AA5-8DCF-4514-95F0-9A1D428095F8}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.BackgroundJobs.Hangfire", "modules\common\LINGYUN.Abp.BackgroundJobs.Hangfire\LINGYUN.Abp.BackgroundJobs.Hangfire.csproj", "{492710E6-EEF5-4390-A474-8FB2412ECBE5}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.BlobStoring.Aliyun", "modules\common\LINGYUN.Abp.BlobStoring.Aliyun\LINGYUN.Abp.BlobStoring.Aliyun.csproj", "{CCF1EB86-29BD-4531-BB27-C9111CC67570}" @@ -156,6 +154,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Dapr.Actors.Tes EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.AspNetCore.HttpOverrides", "modules\common\LINGYUN.Abp.AspNetCore.HttpOverrides\LINGYUN.Abp.AspNetCore.HttpOverrides.csproj", "{191BB108-546E-4E70-978E-D6A8149C319C}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.IM.SignalR", "modules\common\LINGYUN.Abp.IM.SignalR\LINGYUN.Abp.IM.SignalR.csproj", "{DEB98AD7-9630-4F32-89E6-C1A118D1D18C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -182,10 +182,6 @@ Global {304D06E6-41EC-4DCB-AEAE-DBEEC75F9ADC}.Debug|Any CPU.Build.0 = Debug|Any CPU {304D06E6-41EC-4DCB-AEAE-DBEEC75F9ADC}.Release|Any CPU.ActiveCfg = Release|Any CPU {304D06E6-41EC-4DCB-AEAE-DBEEC75F9ADC}.Release|Any CPU.Build.0 = Release|Any CPU - {FFC21AA5-8DCF-4514-95F0-9A1D428095F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {FFC21AA5-8DCF-4514-95F0-9A1D428095F8}.Debug|Any CPU.Build.0 = Debug|Any CPU - {FFC21AA5-8DCF-4514-95F0-9A1D428095F8}.Release|Any CPU.ActiveCfg = Release|Any CPU - {FFC21AA5-8DCF-4514-95F0-9A1D428095F8}.Release|Any CPU.Build.0 = Release|Any CPU {492710E6-EEF5-4390-A474-8FB2412ECBE5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {492710E6-EEF5-4390-A474-8FB2412ECBE5}.Debug|Any CPU.Build.0 = Debug|Any CPU {492710E6-EEF5-4390-A474-8FB2412ECBE5}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -406,6 +402,10 @@ Global {191BB108-546E-4E70-978E-D6A8149C319C}.Debug|Any CPU.Build.0 = Debug|Any CPU {191BB108-546E-4E70-978E-D6A8149C319C}.Release|Any CPU.ActiveCfg = Release|Any CPU {191BB108-546E-4E70-978E-D6A8149C319C}.Release|Any CPU.Build.0 = Release|Any CPU + {DEB98AD7-9630-4F32-89E6-C1A118D1D18C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DEB98AD7-9630-4F32-89E6-C1A118D1D18C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DEB98AD7-9630-4F32-89E6-C1A118D1D18C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DEB98AD7-9630-4F32-89E6-C1A118D1D18C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -417,7 +417,6 @@ Global {824CB367-383B-48B2-972D-33923438A9A0} = {B91F26C5-B148-4094-B5F1-71E5F945DBED} {E9AEC9D6-1FE7-4B00-BAC5-2C3D4B63CCA2} = {E2E7A062-0ABB-41B4-8220-60228446D2C2} {304D06E6-41EC-4DCB-AEAE-DBEEC75F9ADC} = {E2E7A062-0ABB-41B4-8220-60228446D2C2} - {FFC21AA5-8DCF-4514-95F0-9A1D428095F8} = {086BE5BE-8594-4DA7-8819-935FEF76DABD} {492710E6-EEF5-4390-A474-8FB2412ECBE5} = {086BE5BE-8594-4DA7-8819-935FEF76DABD} {CCF1EB86-29BD-4531-BB27-C9111CC67570} = {7F18BCA5-35BD-41FB-8EFF-801B56E5E414} {4BD715F2-D117-45FB-B26C-F92D912144C7} = {086BE5BE-8594-4DA7-8819-935FEF76DABD} @@ -484,6 +483,7 @@ Global {8968EDAF-9F5C-4786-AF2A-D3928B70C3EC} = {B86C21A4-73B7-471E-B73A-B4B905EC9435} {CF30221B-CA7A-42CD-B91A-B7224AB2F38B} = {B86C21A4-73B7-471E-B73A-B4B905EC9435} {191BB108-546E-4E70-978E-D6A8149C319C} = {086BE5BE-8594-4DA7-8819-935FEF76DABD} + {DEB98AD7-9630-4F32-89E6-C1A118D1D18C} = {B91F26C5-B148-4094-B5F1-71E5F945DBED} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {06C707C6-02C0-411A-AD3B-2D0E13787CB8} diff --git a/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.SignalR.Protocol.Json/LINGYUN.Abp.AspNetCore.SignalR.Protocol.Json.csproj b/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.SignalR.Protocol.Json/LINGYUN.Abp.AspNetCore.SignalR.Protocol.Json.csproj index 0ec9a99bd..c014271b0 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.SignalR.Protocol.Json/LINGYUN.Abp.AspNetCore.SignalR.Protocol.Json.csproj +++ b/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.SignalR.Protocol.Json/LINGYUN.Abp.AspNetCore.SignalR.Protocol.Json.csproj @@ -8,7 +8,7 @@ - + diff --git a/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.SignalR.Protocol.Json/LINGYUN/Abp/AspNetCore/SignalR/Protocol/Json/AbpAspNetCoreSignalRProtocolJsonModule.cs b/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.SignalR.Protocol.Json/LINGYUN/Abp/AspNetCore/SignalR/Protocol/Json/AbpAspNetCoreSignalRProtocolJsonModule.cs index 8fe7468cb..7a9b68d4d 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.SignalR.Protocol.Json/LINGYUN/Abp/AspNetCore/SignalR/Protocol/Json/AbpAspNetCoreSignalRProtocolJsonModule.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.SignalR.Protocol.Json/LINGYUN/Abp/AspNetCore/SignalR/Protocol/Json/AbpAspNetCoreSignalRProtocolJsonModule.cs @@ -1,7 +1,7 @@ using Microsoft.AspNetCore.SignalR; -using Microsoft.AspNetCore.SignalR.Protocol; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; +using Microsoft.Extensions.Options; using Volo.Abp.AspNetCore.SignalR; using Volo.Abp.Modularity; @@ -11,12 +11,18 @@ namespace LINGYUN.Abp.AspNetCore.SignalR.Protocol.Json typeof(AbpAspNetCoreSignalRModule))] public class AbpAspNetCoreSignalRProtocolJsonModule : AbpModule { - public override void ConfigureServices(ServiceConfigurationContext context) + public override void PreConfigureServices(ServiceConfigurationContext context) { - var newtonsoftJsonOptions = new NewtonsoftJsonHubProtocolOptions(); - context.Services.ExecutePreConfiguredActions(newtonsoftJsonOptions); + PreConfigure(builder => + { + builder.AddJsonProtocol(); + }); + } - context.Services.TryAddEnumerable(ServiceDescriptor.Singleton()); + public override void ConfigureServices(ServiceConfigurationContext context) + { + context.Services.TryAddEnumerable(ServiceDescriptor + .Transient, JsonHubProtocolOptionsSetup>()); } } } diff --git a/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.SignalR.Protocol.Json/LINGYUN/Abp/AspNetCore/SignalR/Protocol/Json/JsonHubProtocolOptionsSetup.cs b/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.SignalR.Protocol.Json/LINGYUN/Abp/AspNetCore/SignalR/Protocol/Json/JsonHubProtocolOptionsSetup.cs new file mode 100644 index 000000000..4226f3d76 --- /dev/null +++ b/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.SignalR.Protocol.Json/LINGYUN/Abp/AspNetCore/SignalR/Protocol/Json/JsonHubProtocolOptionsSetup.cs @@ -0,0 +1,23 @@ +using Microsoft.AspNetCore.SignalR; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; +using System; +using Volo.Abp.Json.SystemTextJson; + +namespace LINGYUN.Abp.AspNetCore.SignalR.Protocol.Json +{ + public class JsonHubProtocolOptionsSetup : IConfigureOptions + { + protected IServiceProvider ServiceProvider { get; } + + public JsonHubProtocolOptionsSetup(IServiceProvider serviceProvider) + { + ServiceProvider = serviceProvider; + } + + public void Configure(JsonHubProtocolOptions options) + { + options.PayloadSerializerOptions = ServiceProvider.GetRequiredService>().Value.JsonSerializerOptions; + } + } +} diff --git a/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.SignalR/LINGYUN/Abp/AspNetCore/SignalR/JwtToken/AbpAspNetCoreSignalRJwtTokenMapPathOptions.cs b/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.SignalR/LINGYUN/Abp/AspNetCore/SignalR/JwtToken/AbpAspNetCoreSignalRJwtTokenMapPathOptions.cs index 76c4ec29d..0b7ae5741 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.SignalR/LINGYUN/Abp/AspNetCore/SignalR/JwtToken/AbpAspNetCoreSignalRJwtTokenMapPathOptions.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.SignalR/LINGYUN/Abp/AspNetCore/SignalR/JwtToken/AbpAspNetCoreSignalRJwtTokenMapPathOptions.cs @@ -4,21 +4,23 @@ namespace LINGYUN.Abp.AspNetCore.SignalR.JwtToken { public class AbpAspNetCoreSignalRJwtTokenMapPathOptions { + public string PrefixHubPath { get; set; } public List MapJwtTokenPaths { get; set; } public AbpAspNetCoreSignalRJwtTokenMapPathOptions() { + PrefixHubPath = "/signalr-hubs/"; MapJwtTokenPaths = new List(); } public void MapPath(string path) { - if (path.StartsWith("/signalr-hubs/")) + if (path.StartsWith(PrefixHubPath)) { MapJwtTokenPaths.AddIfNotContains(path); } else { - MapJwtTokenPaths.AddIfNotContains($"/signalr-hubs/{path}"); + MapJwtTokenPaths.AddIfNotContains($"{PrefixHubPath}{path}"); } } } diff --git a/aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN.Abp.EventBus.CAP.csproj b/aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN.Abp.EventBus.CAP.csproj index 646d362cc..5072841b5 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN.Abp.EventBus.CAP.csproj +++ b/aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN.Abp.EventBus.CAP.csproj @@ -11,9 +11,10 @@ - + + diff --git a/aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN.Abp.EventBus.CAP.xml b/aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN.Abp.EventBus.CAP.xml index a045ed68c..a0a7a85fd 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN.Abp.EventBus.CAP.xml +++ b/aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN.Abp.EventBus.CAP.xml @@ -169,14 +169,14 @@ constructor - + constructor - + @@ -184,7 +184,7 @@ constructor - + diff --git a/aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN/Abp/EventBus/CAP/AbpCAPExecutionFailedException.cs b/aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN/Abp/EventBus/CAP/AbpCAPExecutionFailedException.cs index f8931ceda..fa48a0a92 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN/Abp/EventBus/CAP/AbpCAPExecutionFailedException.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN/Abp/EventBus/CAP/AbpCAPExecutionFailedException.cs @@ -21,36 +21,36 @@ namespace LINGYUN.Abp.EventBus.CAP /// constructor /// /// - /// - public AbpCAPExecutionFailedException(MessageType messageType, Message prigin) + /// + public AbpCAPExecutionFailedException(MessageType messageType, Message origin) { MessageType = messageType; - Origin = prigin; + Origin = origin; } /// /// constructor /// /// - /// + /// /// - public AbpCAPExecutionFailedException(MessageType messageType, Message prigin, string message) : base(message) + public AbpCAPExecutionFailedException(MessageType messageType, Message origin, string message) : base(message) { MessageType = messageType; - Origin = prigin; + Origin = origin; } /// /// constructor /// /// - /// + /// /// /// - public AbpCAPExecutionFailedException(MessageType messageType, Message prigin, string message, Exception innerException) : base(message, innerException) + public AbpCAPExecutionFailedException(MessageType messageType, Message origin, string message, Exception innerException) : base(message, innerException) { MessageType = messageType; - Origin = prigin; + Origin = origin; } } } diff --git a/aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN/Abp/EventBus/CAP/AbpCAPSubscribeInvoker.cs b/aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN/Abp/EventBus/CAP/AbpCAPSubscribeInvoker.cs index b0bbf1069..327cbce46 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN/Abp/EventBus/CAP/AbpCAPSubscribeInvoker.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN/Abp/EventBus/CAP/AbpCAPSubscribeInvoker.cs @@ -1,4 +1,5 @@ using DotNetCore.CAP; +using DotNetCore.CAP.Filter; using DotNetCore.CAP.Internal; using DotNetCore.CAP.Messages; using DotNetCore.CAP.Serialization; @@ -137,7 +138,49 @@ namespace LINGYUN.Abp.EventBus.CAP // 改变租户 using (_currentTenant.Change(tenantId)) { - var resultObj = await ExecuteWithParameterAsync(executor, obj, executeParameters); + var filter = provider.GetService(); + object resultObj = null; + + try + { + if (filter != null) + { + var etContext = new ExecutingContext(context, executeParameters); + filter.OnSubscribeExecuting(etContext); + executeParameters = etContext.Arguments; + } + + resultObj = await ExecuteWithParameterAsync(executor, obj, executeParameters); + + if (filter != null) + { + var edContext = new ExecutedContext(context, resultObj); + filter.OnSubscribeExecuted(edContext); + resultObj = edContext.Result; + } + } + catch (Exception e) + { + if (filter != null) + { + var exContext = new ExceptionContext(context, e); + filter.OnSubscribeException(exContext); + if (!exContext.ExceptionHandled) + { + throw exContext.Exception; + } + + if (exContext.Result != null) + { + resultObj = exContext.Result; + } + } + else + { + throw; + } + } + return new ConsumerExecutedResult(resultObj, message.GetId(), message.GetCallbackName()); } } diff --git a/aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN/Abp/EventBus/CAP/AbpCapSerializer.cs b/aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN/Abp/EventBus/CAP/AbpCapSerializer.cs new file mode 100644 index 000000000..7f3c11370 --- /dev/null +++ b/aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN/Abp/EventBus/CAP/AbpCapSerializer.cs @@ -0,0 +1,78 @@ +using DotNetCore.CAP.Messages; +using DotNetCore.CAP.Serialization; +using Microsoft.Extensions.Options; +using System; +using System.Buffers; +using System.Text.Json; +using System.Threading.Tasks; +using Volo.Abp.Json.SystemTextJson; + +namespace LINGYUN.Abp.EventBus.CAP +{ + public class AbpCapSerializer : ISerializer + { + private readonly AbpSystemTextJsonSerializerOptions _jsonSerializerOptions; + + public AbpCapSerializer(IOptions options) + { + _jsonSerializerOptions = options.Value; + } + + public Task SerializeAsync(Message message) + { + if (message == null) + { + throw new ArgumentNullException(nameof(message)); + } + + if (message.Value == null) + { + return Task.FromResult(new TransportMessage(message.Headers, null)); + } + + var jsonBytes = JsonSerializer.SerializeToUtf8Bytes(message.Value, _jsonSerializerOptions.JsonSerializerOptions); + return Task.FromResult(new TransportMessage(message.Headers, jsonBytes)); + } + + public Task DeserializeAsync(TransportMessage transportMessage, Type valueType) + { + if (valueType == null || transportMessage.Body == null) + { + return Task.FromResult(new Message(transportMessage.Headers, null)); + } + + var obj = JsonSerializer.Deserialize(transportMessage.Body, valueType, _jsonSerializerOptions.JsonSerializerOptions); + + return Task.FromResult(new Message(transportMessage.Headers, obj)); + } + + public string Serialize(Message message) + { + return JsonSerializer.Serialize(message, _jsonSerializerOptions.JsonSerializerOptions); + } + + public Message Deserialize(string json) + { + return JsonSerializer.Deserialize(json, _jsonSerializerOptions.JsonSerializerOptions); + } + + public object Deserialize(object value, Type valueType) + { + if (value is JsonElement jToken) + { + var bufferWriter = new ArrayBufferWriter(); + using (var writer = new Utf8JsonWriter(bufferWriter)) + { + jToken.WriteTo(writer); + } + return JsonSerializer.Deserialize(bufferWriter.WrittenSpan, valueType, _jsonSerializerOptions.JsonSerializerOptions); + } + throw new NotSupportedException("Type is not of type JToken"); + } + + public bool IsJsonType(object jsonObject) + { + return jsonObject is JsonElement; + } + } +} diff --git a/aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/Microsoft/Extensions/DependencyInjection/ServiceCollectionExtensions.cs b/aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/Microsoft/Extensions/DependencyInjection/ServiceCollectionExtensions.cs index 5e59f3bfd..9b8b488ee 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/Microsoft/Extensions/DependencyInjection/ServiceCollectionExtensions.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/Microsoft/Extensions/DependencyInjection/ServiceCollectionExtensions.cs @@ -1,6 +1,7 @@ using DotNetCore.CAP; using DotNetCore.CAP.Internal; using DotNetCore.CAP.Processor; +using DotNetCore.CAP.Serialization; using LINGYUN.Abp.EventBus.CAP; using Microsoft.Extensions.DependencyInjection.Extensions; using System; @@ -34,6 +35,7 @@ namespace Microsoft.Extensions.DependencyInjection services.TryAddEnumerable(ServiceDescriptor.Singleton()); // 替换为自己的实现 services.AddSingleton(); + services.AddSingleton(); return services; } } diff --git a/aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN.Abp.EventBus.CAP.xml b/aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN.Abp.EventBus.CAP.xml index a045ed68c..a0a7a85fd 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN.Abp.EventBus.CAP.xml +++ b/aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN.Abp.EventBus.CAP.xml @@ -169,14 +169,14 @@ constructor - + constructor - + @@ -184,7 +184,7 @@ constructor - + diff --git a/aspnet-core/modules/common/LINGYUN.Abp.IM.SignalR/LINGYUN/Abp/IM/SignalR/Messages/SignalRMessageSenderProvider.cs b/aspnet-core/modules/common/LINGYUN.Abp.IM.SignalR/LINGYUN/Abp/IM/SignalR/Messages/SignalRMessageSenderProvider.cs index 923a3b211..4b7ab5cd5 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.IM.SignalR/LINGYUN/Abp/IM/SignalR/Messages/SignalRMessageSenderProvider.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.IM.SignalR/LINGYUN/Abp/IM/SignalR/Messages/SignalRMessageSenderProvider.cs @@ -3,6 +3,7 @@ using LINGYUN.Abp.IM.SignalR.Hubs; using LINGYUN.Abp.RealTime.Client; using Microsoft.AspNetCore.SignalR; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; using System; using System.Collections.Immutable; using System.Linq; @@ -13,6 +14,7 @@ namespace LINGYUN.Abp.IM.SignalR.Messages public class SignalRMessageSenderProvider : MessageSenderProviderBase { public override string Name => "SignalR"; + private readonly AbpIMSignalROptions _options; private readonly IOnlineClientManager _onlineClientManager; @@ -21,9 +23,11 @@ namespace LINGYUN.Abp.IM.SignalR.Messages public SignalRMessageSenderProvider( IOnlineClientManager onlineClientManager, IHubContext hubContext, - IServiceProvider serviceProvider) + IServiceProvider serviceProvider, + IOptions options) : base(serviceProvider) { + _options = options.Value; _hubContext = hubContext; _onlineClientManager = onlineClientManager; } @@ -37,15 +41,16 @@ namespace LINGYUN.Abp.IM.SignalR.Messages return; } - await signalRClient.SendAsync("getChatMessage", chatMessage); + await signalRClient.SendAsync(_options.GetChatMessageMethod, chatMessage); } protected override async Task SendMessageToUserAsync(ChatMessage chatMessage) { - var onlineClientContext = new OnlineClientContext(chatMessage.TenantId, chatMessage.ToUserId.Value); - var onlineClients = _onlineClientManager.GetAllByContext(onlineClientContext); try { + var onlineClientContext = new OnlineClientContext(chatMessage.TenantId, chatMessage.ToUserId.Value); + var onlineClients = _onlineClientManager.GetAllByContext(onlineClientContext); + var onlineClientConnectionIds = onlineClients.Select(client => client.ConnectionId).ToImmutableArray(); var signalRClients = _hubContext.Clients.Clients(onlineClientConnectionIds); if (signalRClients == null) @@ -53,7 +58,7 @@ namespace LINGYUN.Abp.IM.SignalR.Messages Logger.LogDebug("Can not get user " + onlineClientContext.UserId + " connection from SignalR hub!"); return; } - await signalRClients.SendAsync("getChatMessage", chatMessage); + await signalRClients.SendAsync(_options.GetChatMessageMethod, chatMessage); } catch (Exception ex) { diff --git a/aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN.Abp.IM.csproj b/aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN.Abp.IM.csproj index 010c126f4..34f93ae40 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN.Abp.IM.csproj +++ b/aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN.Abp.IM.csproj @@ -12,4 +12,8 @@ + + + + diff --git a/aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/Messages/ChatMessage.cs b/aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/Messages/ChatMessage.cs index d3bae7b7e..2c9a1004b 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/Messages/ChatMessage.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/Messages/ChatMessage.cs @@ -2,10 +2,13 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using Volo.Abp.Auditing; +using Volo.Abp.EventBus; using Volo.Abp.ObjectExtending; namespace LINGYUN.Abp.IM.Messages { + [Serializable] + [EventName("im.message")] public class ChatMessage : ExtensibleObject { /// diff --git a/aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/Messages/IMessageSender.cs b/aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/Messages/IMessageSender.cs index caea95cb9..89d952c56 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/Messages/IMessageSender.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/Messages/IMessageSender.cs @@ -4,6 +4,6 @@ namespace LINGYUN.Abp.IM.Messages { public interface IMessageSender { - Task SendMessageAsync(ChatMessage chatMessage); + Task SendMessageAsync(ChatMessage chatMessage); } } diff --git a/aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/Messages/MessageSender.cs b/aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/Messages/MessageSender.cs index 1197b62f0..cfc0c1e23 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/Messages/MessageSender.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/Messages/MessageSender.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +using LINGYUN.Abp.RealTime; +using System.Threading.Tasks; using Volo.Abp.Data; using Volo.Abp.DependencyInjection; using Volo.Abp.EventBus.Distributed; @@ -8,19 +9,26 @@ namespace LINGYUN.Abp.IM.Messages public class MessageSender : IMessageSender, ITransientDependency { protected IDistributedEventBus EventBus { get; } - public MessageSender(IDistributedEventBus eventBus) + protected ISnowflakeIdrGenerator SnowflakeIdrGenerator { get; } + public MessageSender( + IDistributedEventBus eventBus, + ISnowflakeIdrGenerator snowflakeIdrGenerator) { EventBus = eventBus; + SnowflakeIdrGenerator = snowflakeIdrGenerator; } - public virtual async Task SendMessageAsync(ChatMessage chatMessage) + public virtual async Task SendMessageAsync(ChatMessage chatMessage) { chatMessage.SetProperty(nameof(ChatMessage.IsAnonymous), chatMessage.IsAnonymous); - + chatMessage.MessageId = SnowflakeIdrGenerator.Create().ToString(); // 如果先存储的话,就紧耦合消息处理模块了 // await Store.StoreMessageAsync(chatMessage); + var eto = new RealTimeEto(chatMessage); + + await EventBus.PublishAsync(eto); - await EventBus.PublishAsync(chatMessage); + return chatMessage.MessageId; } } } diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications.SignalR/LINGYUN/Abp/Notifications/SignalR/SignalRNotificationPublishProvider.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications.SignalR/LINGYUN/Abp/Notifications/SignalR/SignalRNotificationPublishProvider.cs index e699cf913..2881a4b39 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Notifications.SignalR/LINGYUN/Abp/Notifications/SignalR/SignalRNotificationPublishProvider.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications.SignalR/LINGYUN/Abp/Notifications/SignalR/SignalRNotificationPublishProvider.cs @@ -63,7 +63,7 @@ namespace LINGYUN.Abp.Notifications.SignalR return; } Logger.LogDebug($"Found a singalr client, begin senging notifications"); - await signalRClients.SendAsync("getNotification", notification, cancellationToken); + await signalRClients.SendAsync(_options.MethodName, notification, cancellationToken); } catch (Exception ex) { diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN.Abp.Notifications.csproj b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN.Abp.Notifications.csproj index bb8312af4..a75de7818 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN.Abp.Notifications.csproj +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN.Abp.Notifications.csproj @@ -14,4 +14,8 @@ + + + + diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/AbpNotificationOptions.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/AbpNotificationOptions.cs index 8ed4c8ef2..6720bf3d6 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/AbpNotificationOptions.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/AbpNotificationOptions.cs @@ -5,10 +5,6 @@ namespace LINGYUN.Abp.Notifications // TODO: 需要重命名 AbpNotificationsOptions public class AbpNotificationOptions { - /// - /// 通知系统对于某个应用的定义 - /// - public string Application { get; set; } /// /// 自定义通知集合 /// @@ -23,7 +19,6 @@ namespace LINGYUN.Abp.Notifications public NotificationDataMappingDictionary NotificationDataMappings { get; } public AbpNotificationOptions() { - Application = "Abp"; PublishProviders = new TypeList(); DefinitionProviders = new TypeList(); NotificationDataMappings = new NotificationDataMappingDictionary(); diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/INotificationSender.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/INotificationSender.cs index 2ad50913a..9e9447359 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/INotificationSender.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/INotificationSender.cs @@ -17,7 +17,8 @@ namespace LINGYUN.Abp.Notifications /// 用户,为空标识发给所有订阅用户 /// 租户 /// 严重级别 - Task SendNofiterAsync( + /// 通知标识 + Task SendNofiterAsync( string name, NotificationData data, UserIdentifier user = null, @@ -31,7 +32,8 @@ namespace LINGYUN.Abp.Notifications /// 用户列表,为空标识发给所有订阅用户 /// 租户 /// 严重级别 - Task SendNofitersAsync( + /// 通知标识 + Task SendNofitersAsync( string name, NotificationData data, IEnumerable users = null, diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Internal/NotificationSender.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Internal/NotificationSender.cs index 82fc3575a..cc5e55902 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Internal/NotificationSender.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Internal/NotificationSender.cs @@ -1,4 +1,5 @@ -using Microsoft.Extensions.Logging; +using LINGYUN.Abp.RealTime; +using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; using System; @@ -24,18 +25,24 @@ namespace LINGYUN.Abp.Notifications /// Reference to . /// public IDistributedEventBus DistributedEventBus { get; } + /// + /// Reference to . + /// + protected ISnowflakeIdrGenerator SnowflakeIdGenerator { get; } protected AbpNotificationOptions Options { get; } public NotificationSender( IDistributedEventBus distributedEventBus, + ISnowflakeIdrGenerator snowflakeIdrGenerator, IOptions options) { Options = options.Value; DistributedEventBus = distributedEventBus; + SnowflakeIdGenerator = snowflakeIdrGenerator; Logger = NullLogger.Instance; } - public async Task SendNofiterAsync( + public async Task SendNofiterAsync( string name, NotificationData data, UserIdentifier user = null, @@ -44,44 +51,45 @@ namespace LINGYUN.Abp.Notifications { if (user == null) { - await PublishNofiterAsync(name, data, null, tenantId, severity); + return await PublishNofiterAsync(name, data, null, tenantId, severity); } else { - await PublishNofiterAsync(name, data, new List { user }, tenantId, severity); + return await PublishNofiterAsync(name, data, new List { user }, tenantId, severity); } } - public async Task SendNofitersAsync( + public async Task SendNofitersAsync( string name, NotificationData data, IEnumerable users = null, Guid? tenantId = null, NotificationSeverity severity = NotificationSeverity.Info) { - await PublishNofiterAsync(name, data, users, tenantId, severity); + return await PublishNofiterAsync(name, data, users, tenantId, severity); } - protected async Task PublishNofiterAsync( + protected async Task PublishNofiterAsync( string name, NotificationData data, IEnumerable users = null, Guid? tenantId = null, NotificationSeverity severity = NotificationSeverity.Info) { - await DistributedEventBus - .PublishAsync( - new NotificationEventData - { - Application = Options.Application, - TenantId = tenantId, - Users = users?.ToList(), - Name = name, - Data = data, - CreationTime = DateTime.Now, - Severity = severity - }); + var eto = new NotificationEto(data) + { + Id = SnowflakeIdGenerator.Create(), + TenantId = tenantId, + Users = users?.ToList(), + Name = name, + CreationTime = DateTime.Now, + Severity = severity + }; + + await DistributedEventBus.PublishAsync(eto); + + return eto.Id.ToString(); } } } diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationData.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationData.cs index ac2aab033..5c63d8506 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationData.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationData.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using Volo.Abp.EventBus; namespace LINGYUN.Abp.Notifications { @@ -10,6 +11,8 @@ namespace LINGYUN.Abp.Notifications /// TODO: 2020-10-29 针对不同语言的用户,如果在发布时期就本地化语言是错误的设计 /// 把通知的标题和内容设计为 让客户端自行本地化 /// + [Serializable] + [EventName("notifications")] public class NotificationData { /// diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationEto.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationEto.cs new file mode 100644 index 000000000..e778abcec --- /dev/null +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationEto.cs @@ -0,0 +1,51 @@ +using LINGYUN.Abp.RealTime; +using System; +using System.Collections.Generic; +using Volo.Abp.EventBus; +using Volo.Abp.MultiTenancy; + +namespace LINGYUN.Abp.Notifications +{ + [Serializable] + [GenericEventName(Prefix = "abp.realtime.")] + public class NotificationEto : RealTimeEto, IMultiTenant + { + /// + /// 通知标识 + /// 自动计算 + /// + public long Id { get; set; } + /// + /// 租户 + /// + public Guid? TenantId { get; set; } + /// + /// 通知名称 + /// + public string Name { get; set; } + /// + /// 创建时间 + /// + public DateTime CreationTime { get; set; } + /// + /// 紧急级别 + /// + public NotificationSeverity Severity { get; set; } + /// + /// 指定的接收用户信息集合 + /// + /// + /// 注:
+ /// 如果指定了用户列表,应该在事件订阅程序中通过此集合过滤订阅用户
+ /// 如果未指定用户列表,应该在事件订阅程序中过滤所有订阅此通知的用户 + ///
+ public List Users { get; set; } + public NotificationEto() : base() + { + } + + public NotificationEto(T data) : base(data) + { + } + } +} diff --git a/aspnet-core/modules/common/LINGYUN.Abp.RealTime/LINGYUN.Abp.RealTime.csproj b/aspnet-core/modules/common/LINGYUN.Abp.RealTime/LINGYUN.Abp.RealTime.csproj index c4e5932ab..d2849618d 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.RealTime/LINGYUN.Abp.RealTime.csproj +++ b/aspnet-core/modules/common/LINGYUN.Abp.RealTime/LINGYUN.Abp.RealTime.csproj @@ -9,6 +9,7 @@ + diff --git a/aspnet-core/modules/common/LINGYUN.Abp.RealTime/LINGYUN/Abp/RealTime/AbpRealTimeModule.cs b/aspnet-core/modules/common/LINGYUN.Abp.RealTime/LINGYUN/Abp/RealTime/AbpRealTimeModule.cs index f4282a301..4eb61246e 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.RealTime/LINGYUN/Abp/RealTime/AbpRealTimeModule.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.RealTime/LINGYUN/Abp/RealTime/AbpRealTimeModule.cs @@ -1,8 +1,19 @@ -using Volo.Abp.Modularity; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp; +using Volo.Abp.EventBus.Abstractions; +using Volo.Abp.Modularity; namespace LINGYUN.Abp.RealTime { + [DependsOn(typeof(AbpEventBusAbstractionsModule))] public class AbpRealTimeModule : AbpModule { + public override void OnApplicationInitialization(ApplicationInitializationContext context) + { + context + .ServiceProvider + .GetRequiredService() + .Initialize(); + } } } diff --git a/aspnet-core/modules/common/LINGYUN.Abp.RealTime/LINGYUN/Abp/RealTime/ISnowflakeIdrGenerator.cs b/aspnet-core/modules/common/LINGYUN.Abp.RealTime/LINGYUN/Abp/RealTime/ISnowflakeIdrGenerator.cs new file mode 100644 index 000000000..bc982928c --- /dev/null +++ b/aspnet-core/modules/common/LINGYUN.Abp.RealTime/LINGYUN/Abp/RealTime/ISnowflakeIdrGenerator.cs @@ -0,0 +1,7 @@ +namespace LINGYUN.Abp.RealTime +{ + public interface ISnowflakeIdrGenerator + { + long Create(); + } +} diff --git a/aspnet-core/modules/common/LINGYUN.Abp.RealTime/LINGYUN/Abp/RealTime/RealTimeEto.cs b/aspnet-core/modules/common/LINGYUN.Abp.RealTime/LINGYUN/Abp/RealTime/RealTimeEto.cs new file mode 100644 index 000000000..e713b8f19 --- /dev/null +++ b/aspnet-core/modules/common/LINGYUN.Abp.RealTime/LINGYUN/Abp/RealTime/RealTimeEto.cs @@ -0,0 +1,21 @@ +using System; +using Volo.Abp.Domain.Entities.Events.Distributed; +using Volo.Abp.EventBus; + +namespace LINGYUN.Abp.RealTime +{ + [Serializable] + [GenericEventName(Prefix = "abp.realtime.")] + public class RealTimeEto : EtoBase + { + public T Data { get; set; } + public RealTimeEto() : base() + { + } + + public RealTimeEto(T data) : base() + { + Data = data; + } + } +} diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Utils/SnowflakeIdOptions.cs b/aspnet-core/modules/common/LINGYUN.Abp.RealTime/LINGYUN/Abp/RealTime/SnowflakeIdOptions.cs similarity index 92% rename from aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Utils/SnowflakeIdOptions.cs rename to aspnet-core/modules/common/LINGYUN.Abp.RealTime/LINGYUN/Abp/RealTime/SnowflakeIdOptions.cs index ac594b900..62a63c53d 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Utils/SnowflakeIdOptions.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.RealTime/LINGYUN/Abp/RealTime/SnowflakeIdOptions.cs @@ -1,4 +1,4 @@ -namespace LINGYUN.Abp.MessageService.Utils +namespace LINGYUN.Abp.RealTime { public class SnowflakeIdOptions { diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Utils/SnowflakeIdGenerator.cs b/aspnet-core/modules/common/LINGYUN.Abp.RealTime/LINGYUN/Abp/RealTime/SnowflakeIdrGenerator.cs similarity index 94% rename from aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Utils/SnowflakeIdGenerator.cs rename to aspnet-core/modules/common/LINGYUN.Abp.RealTime/LINGYUN/Abp/RealTime/SnowflakeIdrGenerator.cs index 65a67ecc6..2f9eaab9f 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Utils/SnowflakeIdGenerator.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.RealTime/LINGYUN/Abp/RealTime/SnowflakeIdrGenerator.cs @@ -3,11 +3,11 @@ using System; using Volo.Abp; using Volo.Abp.DependencyInjection; -namespace LINGYUN.Abp.MessageService.Utils +namespace LINGYUN.Abp.RealTime { // reference: https://github.com/dotnetcore/CAP // reference: https://blog.csdn.net/lq18050010830/article/details/89845790 - public class SnowflakeIdGenerator : ISnowflakeIdGenerator, ISingletonDependency + public class SnowflakeIdrGenerator : ISnowflakeIdrGenerator, ISingletonDependency { public const long Twepoch = 1288834974657L; @@ -24,7 +24,7 @@ namespace LINGYUN.Abp.MessageService.Utils protected SnowflakeIdOptions Options { get; } - public SnowflakeIdGenerator(IOptions options) + public SnowflakeIdrGenerator(IOptions options) { Options = options.Value; diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN/Abp/MessageService/Chat/ChatAppService.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN/Abp/MessageService/Chat/ChatAppService.cs index c6933a947..191969f19 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN/Abp/MessageService/Chat/ChatAppService.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN/Abp/MessageService/Chat/ChatAppService.cs @@ -128,9 +128,9 @@ namespace LINGYUN.Abp.MessageService.Chat // TODO:向其他租户发送消息? input.TenantId ??= CurrentTenant.Id; - await MessageSender.SendMessageAsync(input); + var messageId = await MessageSender.SendMessageAsync(input); - return new ChatMessageSendResultDto(input.MessageId); + return new ChatMessageSendResultDto(messageId); } } } diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/AbpMessageServiceDomainModule.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/AbpMessageServiceDomainModule.cs index 53ec1d2bd..2f19e44ef 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/AbpMessageServiceDomainModule.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/AbpMessageServiceDomainModule.cs @@ -2,9 +2,6 @@ using LINGYUN.Abp.MessageService.Localization; using LINGYUN.Abp.MessageService.Mapper; using LINGYUN.Abp.MessageService.ObjectExtending; -using LINGYUN.Abp.MessageService.Utils; -using Microsoft.Extensions.DependencyInjection; -using Volo.Abp; using Volo.Abp.AutoMapper; using Volo.Abp.Caching; using Volo.Abp.Localization; @@ -54,13 +51,5 @@ namespace LINGYUN.Abp.MessageService typeof(Message) ); } - - public override void OnApplicationInitialization(ApplicationInitializationContext context) - { - context - .ServiceProvider - .GetRequiredService() - .Initialize(); - } } } diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/MessageStore.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/MessageStore.cs index fb42c9ddf..a9e128ef0 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/MessageStore.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/MessageStore.cs @@ -1,7 +1,6 @@ using LINGYUN.Abp.IM.Contract; using LINGYUN.Abp.IM.Messages; using LINGYUN.Abp.MessageService.Group; -using LINGYUN.Abp.MessageService.Utils; using System; using System.Collections.Generic; using System.Threading; @@ -29,8 +28,6 @@ namespace LINGYUN.Abp.MessageService.Chat private readonly IMessageRepository _messageRepository; - private readonly ISnowflakeIdGenerator _snowflakeIdGenerator; - private readonly IUserChatSettingRepository _userChatSettingRepository; public MessageStore( IFriendStore friendStore, @@ -39,7 +36,6 @@ namespace LINGYUN.Abp.MessageService.Chat IUnitOfWorkManager unitOfWorkManager, IGroupRepository groupRepository, IMessageRepository messageRepository, - ISnowflakeIdGenerator snowflakeIdGenerator, IUserChatSettingRepository userChatSettingRepository) { _friendStore = friendStore; @@ -48,7 +44,6 @@ namespace LINGYUN.Abp.MessageService.Chat _unitOfWorkManager = unitOfWorkManager; _groupRepository = groupRepository; _messageRepository = messageRepository; - _snowflakeIdGenerator = snowflakeIdGenerator; _userChatSettingRepository = userChatSettingRepository; } @@ -208,15 +203,18 @@ namespace LINGYUN.Abp.MessageService.Chat { throw new BusinessException(MessageServiceErrorCodes.UserHasBlack); } - var messageId = _snowflakeIdGenerator.Create(); - var message = new UserMessage(messageId, chatMessage.FormUserId, chatMessage.FormUserName, chatMessage.Content, chatMessage.MessageType); + + var message = new UserMessage( + long.Parse(chatMessage.MessageId), + chatMessage.FormUserId, + chatMessage.FormUserName, + chatMessage.Content, + chatMessage.MessageType); message.SendToUser(chatMessage.ToUserId.Value); message.SetProperty(nameof(ChatMessage.IsAnonymous), chatMessage.IsAnonymous); await _messageRepository.InsertUserMessageAsync(message, cancellationToken); - - chatMessage.MessageId = messageId.ToString(); } protected virtual async Task StoreGroupMessageAsync( @@ -242,15 +240,18 @@ namespace LINGYUN.Abp.MessageService.Chat // 当前群组不允许匿名发言 throw new BusinessException(MessageServiceErrorCodes.GroupNotAllowedToSpeakAnonymously); } - var messageId = _snowflakeIdGenerator.Create(); - var message = new GroupMessage(messageId, chatMessage.FormUserId, chatMessage.FormUserName, chatMessage.Content, chatMessage.MessageType); + + var message = new GroupMessage( + long.Parse(chatMessage.MessageId), + chatMessage.FormUserId, + chatMessage.FormUserName, + chatMessage.Content, + chatMessage.MessageType); message.SendToGroup(groupId); message.SetProperty(nameof(ChatMessage.IsAnonymous), chatMessage.IsAnonymous); await _messageRepository.InsertGroupMessageAsync(message, cancellationToken); - - chatMessage.MessageId = messageId.ToString(); } } } diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/NotificationStore.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/NotificationStore.cs index c02be6207..375f64dbf 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/NotificationStore.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/NotificationStore.cs @@ -1,5 +1,4 @@ using LINGYUN.Abp.MessageService.Subscriptions; -using LINGYUN.Abp.MessageService.Utils; using LINGYUN.Abp.Notifications; using Microsoft.Extensions.DependencyInjection; using System; @@ -30,8 +29,6 @@ namespace LINGYUN.Abp.MessageService.Notifications private readonly IUnitOfWorkManager _unitOfWorkManager; - private readonly ISnowflakeIdGenerator _snowflakeIdGenerator; - private readonly INotificationRepository _notificationRepository; private readonly IUserNotificationRepository _userNotificationRepository; @@ -44,7 +41,6 @@ namespace LINGYUN.Abp.MessageService.Notifications ICurrentTenant currentTenant, IJsonSerializer jsonSerializer, IUnitOfWorkManager unitOfWorkManager, - ISnowflakeIdGenerator snowflakeIdGenerator, INotificationRepository notificationRepository, IUserSubscribeRepository userSubscribeRepository, IUserNotificationRepository userNotificationRepository @@ -55,7 +51,6 @@ namespace LINGYUN.Abp.MessageService.Notifications _currentTenant = currentTenant; _jsonSerializer = jsonSerializer; _unitOfWorkManager = unitOfWorkManager; - _snowflakeIdGenerator = snowflakeIdGenerator; _notificationRepository = notificationRepository; _userSubscribeRepository = userSubscribeRepository; _userNotificationRepository = userNotificationRepository; @@ -322,12 +317,9 @@ namespace LINGYUN.Abp.MessageService.Notifications using (var unitOfWork = _unitOfWorkManager.Begin()) using (_currentTenant.Change(notification.TenantId)) { - // var notifyId = notification.GetId(); - var notifyId = _snowflakeIdGenerator.Create(); - // 保存主键,防止前端js long类型溢出 - // notification.Data["id"] = notifyId.ToString(); - - var notify = new Notification(notifyId, notification.Name, + var notify = new Notification( + notification.GetId(), + notification.Name, notification.Data.GetType().AssemblyQualifiedName, _jsonSerializer.Serialize(notification.Data), notification.Severity, notification.TenantId) diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Utils/ISnowflakeIdGenerator.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Utils/ISnowflakeIdGenerator.cs deleted file mode 100644 index 310f419de..000000000 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Utils/ISnowflakeIdGenerator.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace LINGYUN.Abp.MessageService.Utils -{ - public interface ISnowflakeIdGenerator - { - long Create(); - } -} diff --git a/aspnet-core/services/account/AuthServer.Host/AuthIdentityServerModule.cs b/aspnet-core/services/account/AuthServer.Host/AuthIdentityServerModule.cs index 0df1a0043..85a3d1399 100644 --- a/aspnet-core/services/account/AuthServer.Host/AuthIdentityServerModule.cs +++ b/aspnet-core/services/account/AuthServer.Host/AuthIdentityServerModule.cs @@ -23,6 +23,8 @@ using System.IO; using System.Linq; using System.Security.Cryptography.X509Certificates; using System.Text; +using System.Text.Encodings.Web; +using System.Text.Unicode; using Volo.Abp; using Volo.Abp.Account; using Volo.Abp.Account.Localization; @@ -43,6 +45,7 @@ using Volo.Abp.Identity; using Volo.Abp.IdentityServer; using Volo.Abp.IdentityServer.Jwt; using Volo.Abp.Json; +using Volo.Abp.Json.SystemTextJson; using Volo.Abp.Localization; using Volo.Abp.Modularity; using Volo.Abp.MultiTenancy; @@ -134,17 +137,11 @@ namespace AuthServer.Host options.UseMySQL(); }); - // 解决某些不支持类型的序列化 - Configure(options => + // 中文序列化的编码问题 + Configure(options => { - // See: https://docs.abp.io/en/abp/4.0/Migration-Guides/Abp-4_0#always-use-the-newtonsoft-json - options.UseHybridSerializer = false; + options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All); }); - // 中文序列化的编码问题 - //Configure(options => - //{ - // options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All); - //}); // 加解密 Configure(options => diff --git a/aspnet-core/services/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/BackendAdminHostModule.cs b/aspnet-core/services/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/BackendAdminHostModule.cs index 60226d991..0470feb3a 100644 --- a/aspnet-core/services/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/BackendAdminHostModule.cs +++ b/aspnet-core/services/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/BackendAdminHostModule.cs @@ -30,6 +30,8 @@ using Microsoft.OpenApi.Models; using StackExchange.Redis; using System; using System.Text; +using System.Text.Encodings.Web; +using System.Text.Unicode; using Volo.Abp; using Volo.Abp.AspNetCore.Authentication.JwtBearer; using Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy; @@ -50,6 +52,7 @@ using Volo.Abp.Identity.EntityFrameworkCore; using Volo.Abp.Identity.Localization; using Volo.Abp.IdentityServer.EntityFrameworkCore; using Volo.Abp.Json; +using Volo.Abp.Json.SystemTextJson; using Volo.Abp.Localization; using Volo.Abp.Modularity; using Volo.Abp.MultiTenancy; @@ -138,17 +141,11 @@ namespace LINGYUN.Abp.BackendAdmin options.UseMySQL(); }); - // 解决某些不支持类型的序列化 - Configure(options => + // 中文序列化的编码问题 + Configure(options => { - // See: https://docs.abp.io/en/abp/4.0/Migration-Guides/Abp-4_0#always-use-the-newtonsoft-json - options.UseHybridSerializer = false; + options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All); }); - // 中文序列化的编码问题 - //Configure(options => - //{ - // options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All); - //}); // 加解密 Configure(options => diff --git a/aspnet-core/services/apigateway/LINGYUN.Abp.ApiGateway.Host/AbpApiGatewayHostModule.cs b/aspnet-core/services/apigateway/LINGYUN.Abp.ApiGateway.Host/AbpApiGatewayHostModule.cs index 495fdfed7..1b1de98a4 100644 --- a/aspnet-core/services/apigateway/LINGYUN.Abp.ApiGateway.Host/AbpApiGatewayHostModule.cs +++ b/aspnet-core/services/apigateway/LINGYUN.Abp.ApiGateway.Host/AbpApiGatewayHostModule.cs @@ -17,6 +17,8 @@ using Ocelot.Provider.Polly; using StackExchange.Redis; using System; using System.Text; +using System.Text.Encodings.Web; +using System.Text.Unicode; using Volo.Abp; using Volo.Abp.AspNetCore; using Volo.Abp.Autofac; @@ -24,6 +26,7 @@ using Volo.Abp.Caching; using Volo.Abp.Caching.StackExchangeRedis; using Volo.Abp.Http.Client; using Volo.Abp.Json; +using Volo.Abp.Json.SystemTextJson; using Volo.Abp.Modularity; using Volo.Abp.Security.Encryption; using Volo.Abp.VirtualFileSystem; @@ -50,17 +53,11 @@ namespace LINGYUN.Abp.ApiGateway var hostingEnvironment = context.Services.GetHostingEnvironment(); var configuration = context.Services.GetConfiguration(); - // 解决某些不支持类型的序列化 - Configure(options => + // 中文序列化的编码问题 + Configure(options => { - // See: https://docs.abp.io/en/abp/4.0/Migration-Guides/Abp-4_0#always-use-the-newtonsoft-json - options.UseHybridSerializer = false; + options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All); }); - // 中文序列化的编码问题 - //Configure(options => - //{ - // options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All); - //}); Configure(configuration.GetSection("ApiGateway")); diff --git a/aspnet-core/services/apigateway/LINGYUN.ApiGateway.Host/ApiGatewayHostModule.cs b/aspnet-core/services/apigateway/LINGYUN.ApiGateway.Host/ApiGatewayHostModule.cs index 78e2fda64..7cbd9a378 100644 --- a/aspnet-core/services/apigateway/LINGYUN.ApiGateway.Host/ApiGatewayHostModule.cs +++ b/aspnet-core/services/apigateway/LINGYUN.ApiGateway.Host/ApiGatewayHostModule.cs @@ -20,6 +20,8 @@ using Ocelot.Provider.Polly; using StackExchange.Redis; using System; using System.Text; +using System.Text.Encodings.Web; +using System.Text.Unicode; using Volo.Abp; using Volo.Abp.AspNetCore; using Volo.Abp.Autofac; @@ -28,6 +30,7 @@ using Volo.Abp.Caching; using Volo.Abp.Caching.StackExchangeRedis; using Volo.Abp.Http.Client.IdentityModel; using Volo.Abp.Json; +using Volo.Abp.Json.SystemTextJson; using Volo.Abp.Localization; using Volo.Abp.Modularity; using Volo.Abp.Security.Encryption; @@ -81,17 +84,11 @@ namespace LINGYUN.ApiGateway Configure(configuration.GetSection("ApiGateway")); - // 解决某些不支持类型的序列化 - Configure(options => + // 中文序列化的编码问题 + Configure(options => { - // See: https://docs.abp.io/en/abp/4.0/Migration-Guides/Abp-4_0#always-use-the-newtonsoft-json - options.UseHybridSerializer = false; + options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All); }); - // 中文序列化的编码问题 - //Configure(options => - //{ - // options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All); - //}); context.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => diff --git a/aspnet-core/services/apigateway/LINGYUN.ApiGateway.HttpApi.Host/ApiGatewayHttpApiHostModule.cs b/aspnet-core/services/apigateway/LINGYUN.ApiGateway.HttpApi.Host/ApiGatewayHttpApiHostModule.cs index 1632c3034..05726bba1 100644 --- a/aspnet-core/services/apigateway/LINGYUN.ApiGateway.HttpApi.Host/ApiGatewayHttpApiHostModule.cs +++ b/aspnet-core/services/apigateway/LINGYUN.ApiGateway.HttpApi.Host/ApiGatewayHttpApiHostModule.cs @@ -15,6 +15,8 @@ using Microsoft.OpenApi.Models; using StackExchange.Redis; using System; using System.Text; +using System.Text.Encodings.Web; +using System.Text.Unicode; using Volo.Abp; using Volo.Abp.AspNetCore.Security.Claims; using Volo.Abp.Auditing; @@ -27,6 +29,7 @@ using Volo.Abp.Data; using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore.MySQL; using Volo.Abp.Json; +using Volo.Abp.Json.SystemTextJson; using Volo.Abp.Localization; using Volo.Abp.Modularity; using Volo.Abp.MultiTenancy; @@ -82,17 +85,11 @@ namespace LINGYUN.ApiGateway options.UseMySQL(); }); - // 解决某些不支持类型的序列化 - Configure(options => + // 中文序列化的编码问题 + Configure(options => { - // See: https://docs.abp.io/en/abp/4.0/Migration-Guides/Abp-4_0#always-use-the-newtonsoft-json - options.UseHybridSerializer = false; + options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All); }); - // 中文序列化的编码问题 - //Configure(options => - //{ - // options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All); - //}); // 加解密 Configure(options => diff --git a/aspnet-core/services/identity-server/LINGYUN.Abp.IdentityServer4.HttpApi.Host/AbpIdentityServerAdminHttpApiHostModule.cs b/aspnet-core/services/identity-server/LINGYUN.Abp.IdentityServer4.HttpApi.Host/AbpIdentityServerAdminHttpApiHostModule.cs index 6c9eef45c..5ffbd2140 100644 --- a/aspnet-core/services/identity-server/LINGYUN.Abp.IdentityServer4.HttpApi.Host/AbpIdentityServerAdminHttpApiHostModule.cs +++ b/aspnet-core/services/identity-server/LINGYUN.Abp.IdentityServer4.HttpApi.Host/AbpIdentityServerAdminHttpApiHostModule.cs @@ -19,6 +19,8 @@ using Microsoft.OpenApi.Models; using StackExchange.Redis; using System; using System.Text; +using System.Text.Encodings.Web; +using System.Text.Unicode; using Volo.Abp; using Volo.Abp.AspNetCore.Authentication.JwtBearer; using Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy; @@ -34,6 +36,7 @@ using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore.MySQL; using Volo.Abp.Identity.Localization; using Volo.Abp.Json; +using Volo.Abp.Json.SystemTextJson; using Volo.Abp.Localization; using Volo.Abp.Modularity; using Volo.Abp.MultiTenancy; @@ -104,27 +107,13 @@ namespace LINGYUN.Abp.IdentityServer4 Configure(options => { options.UseMySQL(); - //if (hostingEnvironment.IsDevelopment()) - //{ - // options.PreConfigure(ctx => - // { - // ctx.DbContextOptions.EnableDetailedErrors(); - // ctx.DbContextOptions.EnableSensitiveDataLogging(); - // }); - //} }); - // 解决某些不支持类型的序列化 - Configure(options => + // 中文序列化的编码问题 + Configure(options => { - // See: https://docs.abp.io/en/abp/4.0/Migration-Guides/Abp-4_0#always-use-the-newtonsoft-json - options.UseHybridSerializer = false; + options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All); }); - // 中文序列化的编码问题 - //Configure(options => - //{ - // options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All); - //}); // 加解密 Configure(options => @@ -271,11 +260,6 @@ namespace LINGYUN.Abp.IdentityServer4 options.Resources.AddDynamic(typeof(IdentityResource)); }); - Configure(options => - { - options.Maps.TryAdd("name", () => AbpClaimTypes.UserName); - }); - context.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { diff --git a/aspnet-core/services/localization/LINGYUN.Abp.LocalizationManagement.HttpApi.Host/AbpLocalizationManagementHttpApiHostModule.cs b/aspnet-core/services/localization/LINGYUN.Abp.LocalizationManagement.HttpApi.Host/AbpLocalizationManagementHttpApiHostModule.cs index 9b4a52d95..bd646b9b1 100644 --- a/aspnet-core/services/localization/LINGYUN.Abp.LocalizationManagement.HttpApi.Host/AbpLocalizationManagementHttpApiHostModule.cs +++ b/aspnet-core/services/localization/LINGYUN.Abp.LocalizationManagement.HttpApi.Host/AbpLocalizationManagementHttpApiHostModule.cs @@ -88,17 +88,11 @@ namespace LINGYUN.Abp.LocalizationManagement options.UseMySQL(); }); - // 解决某些不支持类型的序列化 - Configure(options => + // 中文序列化的编码问题 + Configure(options => { - // See: https://docs.abp.io/en/abp/4.0/Migration-Guides/Abp-4_0#always-use-the-newtonsoft-json - options.UseHybridSerializer = false; + options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All); }); - // 中文序列化的编码问题 - //Configure(options => - //{ - // options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All); - //}); // 加解密 Configure(options => diff --git a/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/AbpMessageServiceHttpApiHostModule.cs b/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/AbpMessageServiceHttpApiHostModule.cs index afea4572c..343b0c48f 100644 --- a/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/AbpMessageServiceHttpApiHostModule.cs +++ b/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/AbpMessageServiceHttpApiHostModule.cs @@ -29,6 +29,8 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; +using System.Text.Encodings.Web; +using System.Text.Unicode; using Volo.Abp; using Volo.Abp.AspNetCore.Auditing; using Volo.Abp.AspNetCore.Authentication.JwtBearer; @@ -41,6 +43,7 @@ using Volo.Abp.Caching; using Volo.Abp.Caching.StackExchangeRedis; using Volo.Abp.EntityFrameworkCore; using Volo.Abp.Json; +using Volo.Abp.Json.SystemTextJson; using Volo.Abp.Localization; using Volo.Abp.Modularity; using Volo.Abp.MultiTenancy; @@ -113,17 +116,11 @@ namespace LINGYUN.Abp.MessageService options.IgnoredUrls.AddIfNotContains("/hangfire"); }); - // 解决某些不支持类型的序列化 - Configure(options => + // 中文序列化的编码问题 + Configure(options => { - // See: https://docs.abp.io/en/abp/4.0/Migration-Guides/Abp-4_0#always-use-the-newtonsoft-json - options.UseHybridSerializer = false; + options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All); }); - // 中文序列化的编码问题 - //Configure(options => - //{ - // options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All); - //}); // 加解密 Configure(options => diff --git a/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/EventBus/Distributed/ChatMessageEventHandler.cs b/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/EventBus/Distributed/ChatMessageEventHandler.cs index eeafa90a0..a9247aa97 100644 --- a/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/EventBus/Distributed/ChatMessageEventHandler.cs +++ b/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/EventBus/Distributed/ChatMessageEventHandler.cs @@ -1,5 +1,6 @@ using LINGYUN.Abp.IM; using LINGYUN.Abp.IM.Messages; +using LINGYUN.Abp.RealTime; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; @@ -9,7 +10,7 @@ using Volo.Abp.EventBus.Distributed; namespace LINGYUN.Abp.MessageService.EventBus.Distributed { - public class ChatMessageEventHandler : IDistributedEventHandler, ITransientDependency + public class ChatMessageEventHandler : IDistributedEventHandler>, ITransientDependency { /// /// Reference to . @@ -35,17 +36,17 @@ namespace LINGYUN.Abp.MessageService.EventBus.Distributed Logger = NullLogger.Instance; } - public virtual async Task HandleEventAsync(ChatMessage eventData) + public virtual async Task HandleEventAsync(RealTimeEto eventData) { Logger.LogDebug($"Persistent chat message."); - await MessageStore.StoreMessageAsync(eventData); + await MessageStore.StoreMessageAsync(eventData.Data); // 发送消息 foreach (var provider in MessageSenderProviderManager.Providers) { Logger.LogDebug($"Sending message with provider {provider.Name}"); - await provider.SendMessageAsync(eventData); + await provider.SendMessageAsync(eventData.Data); } } } diff --git a/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/EventBus/Distributed/NotificationEventHandler.cs b/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/EventBus/Distributed/NotificationEventHandler.cs index 8152d17dd..64150a86c 100644 --- a/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/EventBus/Distributed/NotificationEventHandler.cs +++ b/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/EventBus/Distributed/NotificationEventHandler.cs @@ -1,5 +1,6 @@ using LINGYUN.Abp.MessageService.Utils; using LINGYUN.Abp.Notifications; +using LINGYUN.Abp.RealTime; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; @@ -22,7 +23,7 @@ namespace LINGYUN.Abp.MessageService.EventBus.Distributed /// 作用在于SignalR客户端只会与一台服务器建立连接, /// 只有启用了SignlR服务端的才能真正将消息发布到客户端 /// - public class NotificationEventHandler : IDistributedEventHandler, ITransientDependency + public class NotificationEventHandler : IDistributedEventHandler>, ITransientDependency { /// /// Reference to . @@ -37,10 +38,6 @@ namespace LINGYUN.Abp.MessageService.EventBus.Distributed /// protected IJsonSerializer JsonSerializer { get; } /// - /// Reference to . - /// - protected ISnowflakeIdGenerator SnowflakeIdGenerator { get; } - /// /// Reference to . /// protected IBackgroundJobManager BackgroundJobManager { get; } @@ -69,7 +66,6 @@ namespace LINGYUN.Abp.MessageService.EventBus.Distributed IBackgroundJobManager backgroundJobManager, IOptions options, INotificationStore notificationStore, - ISnowflakeIdGenerator snowflakeIdGenerator, INotificationDefinitionManager notificationDefinitionManager, INotificationSubscriptionManager notificationSubscriptionManager, INotificationPublishProviderManager notificationPublishProviderManager) @@ -78,7 +74,6 @@ namespace LINGYUN.Abp.MessageService.EventBus.Distributed JsonSerializer = jsonSerializer; BackgroundJobManager = backgroundJobManager; NotificationStore = notificationStore; - SnowflakeIdGenerator = snowflakeIdGenerator; NotificationDefinitionManager = notificationDefinitionManager; NotificationSubscriptionManager = notificationSubscriptionManager; NotificationPublishProviderManager = notificationPublishProviderManager; @@ -87,19 +82,14 @@ namespace LINGYUN.Abp.MessageService.EventBus.Distributed } [UnitOfWork] - public virtual async Task HandleEventAsync(NotificationEventData eventData) + public virtual async Task HandleEventAsync(NotificationEto eventData) { - // 这样做的话就要注意了 - // 当只有一个消费者订阅时,事件总线会认为消息已经处理,从而发布Ack指令,从消息队列中移除此消息 - // 可能造成通知数据丢失 - var application = Options.Application ?? "Abp"; - if (!string.Equals(application, eventData.Application, StringComparison.InvariantCultureIgnoreCase)) + // 如果上面过滤了应用程序,这里可以使用Get方法,否则,最好使用GetOrNull加以判断 + var notification = NotificationDefinitionManager.GetOrNull(eventData.Name); + if (notification == null) { - // 不是当前监听应用的消息不做处理 return; } - // 如果上面过滤了应用程序,这里可以使用Get方法,否则,最好使用GetOrNull加以判断 - var notification = NotificationDefinitionManager.Get(eventData.Name); var notificationInfo = new NotificationInfo { @@ -111,7 +101,7 @@ namespace LINGYUN.Abp.MessageService.EventBus.Distributed TenantId = eventData.TenantId, Type = notification.NotificationType }; - notificationInfo.SetId(SnowflakeIdGenerator.Create()); + notificationInfo.SetId(eventData.Id); // TODO: 可以做成一个接口来序列化消息 notificationInfo.Data = NotificationDataConverter.Convert(notificationInfo.Data); diff --git a/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/AppPlatformHttpApiHostModule.cs b/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/AppPlatformHttpApiHostModule.cs index 74eb29088..eea1836db 100644 --- a/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/AppPlatformHttpApiHostModule.cs +++ b/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/AppPlatformHttpApiHostModule.cs @@ -27,6 +27,8 @@ using StackExchange.Redis; using System; using System.IO; using System.Text; +using System.Text.Encodings.Web; +using System.Text.Unicode; using Volo.Abp; using Volo.Abp.AspNetCore.Authentication.JwtBearer; using Volo.Abp.AspNetCore.MultiTenancy; @@ -44,6 +46,7 @@ using Volo.Abp.FeatureManagement.EntityFrameworkCore; using Volo.Abp.Http.Client.IdentityModel.Web; using Volo.Abp.Identity; using Volo.Abp.Json; +using Volo.Abp.Json.SystemTextJson; using Volo.Abp.Localization; using Volo.Abp.Modularity; using Volo.Abp.MultiTenancy; @@ -117,17 +120,11 @@ namespace LINGYUN.Platform options.UseMySQL(); }); - // 解决某些不支持类型的序列化 - Configure(options => + //// 中文序列化的编码问题 + Configure(options => { - // See: https://docs.abp.io/en/abp/4.0/Migration-Guides/Abp-4_0#always-use-the-newtonsoft-json - options.UseHybridSerializer = false; + options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All); }); - //// 中文序列化的编码问题 - //Configure(options => - //{ - // options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All); - //}); Configure(options => { diff --git a/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/DomainTenantResolveContributor.cs b/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/DomainTenantResolveContributor.cs deleted file mode 100644 index aad2cda78..000000000 --- a/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/DomainTenantResolveContributor.cs +++ /dev/null @@ -1,40 +0,0 @@ -using Microsoft.AspNetCore.Http; -using System; -using System.Threading.Tasks; -using Volo.Abp.AspNetCore.MultiTenancy; -using Volo.Abp.MultiTenancy; -using Volo.Abp.Text.Formatting; - -namespace LINGYUN.Platform -{ - public class DomainTenantResolveContributor : HttpTenantResolveContributorBase - { - public const string ContributorName = "Domain"; - - public override string Name => ContributorName; - - private static readonly string[] ProtocolPrefixes = { "http://", "https://" }; - - private readonly string _domainFormat; - - public DomainTenantResolveContributor(string domainFormat) - { - _domainFormat = domainFormat.RemovePreFix(ProtocolPrefixes); - } - - protected override Task GetTenantIdOrNameFromHttpContextOrNullAsync(ITenantResolveContext context, HttpContext httpContext) - { - if (!httpContext.Request.Host.HasValue) - { - return Task.FromResult(null); - } - - var hostName = httpContext.Request.Host.Value.RemovePreFix(ProtocolPrefixes); - var extractResult = FormattedStringValueExtracter.Extract(hostName, _domainFormat, ignoreCase: true); - - context.Handled = true; - - return Task.FromResult(extractResult.IsMatch ? extractResult.Matches[0].Value : null); - } - } -} diff --git a/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/HeaderTenantResolveContributor.cs b/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/HeaderTenantResolveContributor.cs deleted file mode 100644 index 51e73802c..000000000 --- a/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/HeaderTenantResolveContributor.cs +++ /dev/null @@ -1,50 +0,0 @@ -using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Volo.Abp.AspNetCore.MultiTenancy; -using Volo.Abp.MultiTenancy; - -namespace LINGYUN.Platform -{ - public class HeaderTenantResolveContributor : HttpTenantResolveContributorBase - { - public const string ContributorName = "Header"; - - public override string Name => ContributorName; - - protected override Task GetTenantIdOrNameFromHttpContextOrNullAsync(ITenantResolveContext context, HttpContext httpContext) - { - if (httpContext.Request.Headers.IsNullOrEmpty()) - { - return Task.FromResult((string)null); - } - - var tenantIdKey = context.GetAbpAspNetCoreMultiTenancyOptions().TenantKey; - - var tenantIdHeader = httpContext.Request.Headers[tenantIdKey]; - if (tenantIdHeader == string.Empty || tenantIdHeader.Count < 1) - { - return Task.FromResult((string)null); - } - - if (tenantIdHeader.Count > 1) - { - Log(context, $"HTTP request includes more than one {tenantIdKey} header value. First one will be used. All of them: {tenantIdHeader.JoinAsString(", ")}"); - } - - return Task.FromResult(tenantIdHeader.First()); - } - - protected virtual void Log(ITenantResolveContext context, string text) - { - context - .ServiceProvider - .GetRequiredService>() - .LogWarning(text); - } - } -} diff --git a/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/TenantConfigurationProvider.cs b/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/TenantConfigurationProvider.cs deleted file mode 100644 index a4c25c5b1..000000000 --- a/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/TenantConfigurationProvider.cs +++ /dev/null @@ -1,66 +0,0 @@ -using System; -using System.Threading.Tasks; -using Volo.Abp; -using Volo.Abp.DependencyInjection; -using Volo.Abp.MultiTenancy; - -namespace LINGYUN.Platform -{ - [Dependency(Microsoft.Extensions.DependencyInjection.ServiceLifetime.Transient, ReplaceServices = true)] - [ExposeServices(typeof(ITenantConfigurationProvider))] - public class TenantConfigurationProvider : ITenantConfigurationProvider - { - protected virtual ITenantResolver TenantResolver { get; } - protected virtual ITenantStore TenantStore { get; } - protected virtual ITenantResolveResultAccessor TenantResolveResultAccessor { get; } - - public TenantConfigurationProvider( - ITenantResolver tenantResolver, - ITenantStore tenantStore, - ITenantResolveResultAccessor tenantResolveResultAccessor) - { - TenantResolver = tenantResolver; - TenantStore = tenantStore; - TenantResolveResultAccessor = tenantResolveResultAccessor; - } - - public virtual async Task GetAsync(bool saveResolveResult = false) - { - var resolveResult = await TenantResolver.ResolveTenantIdOrNameAsync(); - - if (saveResolveResult) - { - TenantResolveResultAccessor.Result = resolveResult; - } - - TenantConfiguration tenant = null; - if (resolveResult.TenantIdOrName != null) - { - tenant = await FindTenantAsync(resolveResult.TenantIdOrName); - - if (tenant == null) - { - throw new BusinessException( - code: "Volo.AbpIo.MultiTenancy:010001", - message: "Tenant not found!", - details: "There is no tenant with the tenant id or name: " + resolveResult.TenantIdOrName - ); - } - } - - return tenant; - } - - protected virtual async Task FindTenantAsync(string tenantIdOrName) - { - if (Guid.TryParse(tenantIdOrName, out var parsedTenantId)) - { - return await TenantStore.FindAsync(parsedTenantId); - } - else - { - return await TenantStore.FindAsync(tenantIdOrName); - } - } - } -} diff --git a/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/TenantResolver.cs b/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/TenantResolver.cs deleted file mode 100644 index 26ed3c1d4..000000000 --- a/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/TenantResolver.cs +++ /dev/null @@ -1,48 +0,0 @@ -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Options; -using System; -using System.Threading.Tasks; -using Volo.Abp.DependencyInjection; -using Volo.Abp.MultiTenancy; - -namespace LINGYUN.Platform -{ - [Dependency(Microsoft.Extensions.DependencyInjection.ServiceLifetime.Transient, ReplaceServices = true)] - [ExposeServices(typeof(ITenantResolver))] - public class TenantResolver : ITenantResolver - { - private readonly IServiceProvider _serviceProvider; - private readonly AbpTenantResolveOptions _options; - - public TenantResolver(IOptions options, IServiceProvider serviceProvider) - { - _serviceProvider = serviceProvider; - _options = options.Value; - } - - public virtual async Task ResolveTenantIdOrNameAsync() - { - var result = new TenantResolveResult(); - - using (var serviceScope = _serviceProvider.CreateScope()) - { - var context = new TenantResolveContext(serviceScope.ServiceProvider); - - foreach (var tenantResolver in _options.TenantResolvers) - { - await tenantResolver.ResolveAsync(context); - - result.AppliedResolvers.Add(tenantResolver.Name); - - if (context.Handled || context.TenantIdOrName != null) - { - result.TenantIdOrName = context.TenantIdOrName; - break; - } - } - } - - return result; - } - } -} diff --git a/build/build-aspnetcore-release.ps1 b/build/build-aspnetcore-release.ps1 index 5c25845f8..933039d9f 100644 --- a/build/build-aspnetcore-release.ps1 +++ b/build/build-aspnetcore-release.ps1 @@ -5,6 +5,7 @@ foreach ($service in $serviceArray) { Set-Location $service.Path $publishPath = $service.Path + "/../../Publish/" + $service.Service dotnet publish -c Release -o $publishPath --no-cache --no-restore + Copy-Item (Join-Path $service.Path "Dockerfile") -Destination $publishPath -Recurse } Set-Location $rootFolder \ No newline at end of file diff --git a/docker-compose.override.windows.yml b/docker-compose.override.windows.yml new file mode 100644 index 000000000..ebd7bb75a --- /dev/null +++ b/docker-compose.override.windows.yml @@ -0,0 +1,84 @@ +version: '3.4' + +services: + identity-server-sts: + build: + context: ./aspnet-core/services/Publish/identityserver + volumes: + - D:\Projects\Development\Abp\Application\logs\ids-sts:/app/Logs + restart: always + + identity-server-admin: + build: + context: ./aspnet-core/services/Publish/identityserver4-admin + volumes: + - D:\Projects\Development\Abp\Application\logs\ids-admin:/app/Logs + depends_on: + - identity-server-sts + restart: always + + admin-service: + build: + context: ./aspnet-core/services/Publish/admin + volumes: + - D:\Projects\Development\Abp\Application\logs\backend-admin:/app/Logs + depends_on: + - identity-server-sts + restart: always + + localization-service: + build: + context: ./aspnet-core/services/Publish/localization + volumes: + - D:\Projects\Development\Abp\Application\logs\localization:/app/Logs + restart: always + + platform-service: + build: + context: ./aspnet-core/services/Publish/platform + volumes: + - D:\Projects\Development\Abp\Application\logs\platform:/app/Logs + - D:\Projects\Development\Abp\Application\data\platform:/app/file-blob-storing + depends_on: + - identity-server-sts + restart: always + + messages-service: + build: + context: ./aspnet-core/services/Publish/messages + volumes: + - D:\Projects\Development\Abp\Application\logs\messages:/app/Logs + depends_on: + - identity-server-sts + restart: always + + apigateway-admin-service: + build: + context: ./aspnet-core/services/Publish/apigateway-admin + volumes: + - D:\Projects\Development\Abp\Application\logs\apigateway-admin:/app/Logs + depends_on: + - identity-server-sts + - admin-service + restart: always + + apigateway-host-service: + build: + context: ./aspnet-core/services/Publish/apigateway-host + volumes: + - D:\Projects\Development\Abp\Application\logs\apigateway-host:/app/Logs + depends_on: + - identity-server-sts + - apigateway-admin-service + restart: always + + abp-vue-admin-client: + build: + context: ./aspnet-core/services/Publish/client + restart: always + +volumes: + dbdata: + +networks: + linyun-abp: diff --git a/docker-compose.override.yml b/docker-compose.override.yml index d234b7484..5d31ac5c7 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -1,62 +1,84 @@ version: '3.4' services: - admin-service: - environment: - - ASPNETCORE_ENVIRONMENT=Production - - ASPNETCORE_URLS=http://0.0.0.0:80 - ports: - - "30010:80" + identity-server-sts: + build: + context: ./aspnet-core/services/Publish/identityserver + volumes: + - /var/opt/abp/logs/ids-sts:/app/Logs + restart: always identity-server-admin: - environment: - - ASPNETCORE_ENVIRONMENT=Production - - ASPNETCORE_URLS=http://0.0.0.0:80 - ports: - - "30015:80" + build: + context: ./aspnet-core/services/Publish/identityserver4-admin + volumes: + - /var/opt/abp/logs/ids-admin:/app/Logs + depends_on: + - identity-server-sts + restart: always + + admin-service: + build: + context: ./aspnet-core/services/Publish/admin + volumes: + - /var/opt/abp/logs/backend-admin:/app/Logs + depends_on: + - identity-server-sts + restart: always localization-service: - environment: - - ASPNETCORE_ENVIRONMENT=Production - - ASPNETCORE_URLS=http://0.0.0.0:80 - ports: - - "30030:80" + build: + context: ./aspnet-core/services/Publish/localization + volumes: + - /var/opt/abp/logs/localization:/app/Logs + restart: always platform-service: - environment: - - ASPNETCORE_ENVIRONMENT=Production - - ASPNETCORE_URLS=http://0.0.0.0:80 - ports: - - "30025:80" - - messages-service: - environment: - - ASPNETCORE_ENVIRONMENT=Production - - ASPNETCORE_URLS=http://0.0.0.0:80 - ports: - - "30020:80" - - identity-server-sts: - environment: - - ASPNETCORE_ENVIRONMENT=Production - - ASPNETCORE_URLS=http://0.0.0.0:80 - ports: - - "44385:80" + build: + context: ./aspnet-core/services/Publish/platform + volumes: + - /var/opt/abp/logs/platform:/app/Logs + - /var/opt/abp/data/platform:/app/file-blob-storing + depends_on: + - identity-server-sts + restart: always + messages-service: + build: + context: ./aspnet-core/services/Publish/messages + volumes: + - /var/opt/abp/logs/messages:/app/Logs + depends_on: + - identity-server-sts + restart: always + apigateway-admin-service: - environment: - - ASPNETCORE_ENVIRONMENT=Production - - ASPNETCORE_URLS=http://0.0.0.0:80 - ports: - - "30001:80" + build: + context: ./aspnet-core/services/Publish/apigateway-admin + volumes: + - /var/opt/abp/logs/apigateway-admin:/app/Logs + depends_on: + - identity-server-sts + - admin-service + restart: always apigateway-host-service: - environment: - - ASPNETCORE_ENVIRONMENT=Production - - ASPNETCORE_URLS=http://0.0.0.0:80 - ports: - - "30000:80" + build: + context: ./aspnet-core/services/Publish/apigateway-host + volumes: + - /var/opt/abp/logs/apigateway-host:/app/Logs + depends_on: + - identity-server-sts + - apigateway-admin-service + restart: always abp-vue-admin-client: - ports: - - "40000:80" + build: + context: ./aspnet-core/services/Publish/client + restart: always + +volumes: + dbdata: + +networks: + linyun-abp: diff --git a/docker-compose.yml b/docker-compose.yml index 5d31ac5c7..d234b7484 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,84 +1,62 @@ version: '3.4' services: - identity-server-sts: - build: - context: ./aspnet-core/services/Publish/identityserver - volumes: - - /var/opt/abp/logs/ids-sts:/app/Logs - restart: always + admin-service: + environment: + - ASPNETCORE_ENVIRONMENT=Production + - ASPNETCORE_URLS=http://0.0.0.0:80 + ports: + - "30010:80" identity-server-admin: - build: - context: ./aspnet-core/services/Publish/identityserver4-admin - volumes: - - /var/opt/abp/logs/ids-admin:/app/Logs - depends_on: - - identity-server-sts - restart: always - - admin-service: - build: - context: ./aspnet-core/services/Publish/admin - volumes: - - /var/opt/abp/logs/backend-admin:/app/Logs - depends_on: - - identity-server-sts - restart: always + environment: + - ASPNETCORE_ENVIRONMENT=Production + - ASPNETCORE_URLS=http://0.0.0.0:80 + ports: + - "30015:80" localization-service: - build: - context: ./aspnet-core/services/Publish/localization - volumes: - - /var/opt/abp/logs/localization:/app/Logs - restart: always + environment: + - ASPNETCORE_ENVIRONMENT=Production + - ASPNETCORE_URLS=http://0.0.0.0:80 + ports: + - "30030:80" platform-service: - build: - context: ./aspnet-core/services/Publish/platform - volumes: - - /var/opt/abp/logs/platform:/app/Logs - - /var/opt/abp/data/platform:/app/file-blob-storing - depends_on: - - identity-server-sts - restart: always - - messages-service: - build: - context: ./aspnet-core/services/Publish/messages - volumes: - - /var/opt/abp/logs/messages:/app/Logs - depends_on: - - identity-server-sts - restart: always + environment: + - ASPNETCORE_ENVIRONMENT=Production + - ASPNETCORE_URLS=http://0.0.0.0:80 + ports: + - "30025:80" + messages-service: + environment: + - ASPNETCORE_ENVIRONMENT=Production + - ASPNETCORE_URLS=http://0.0.0.0:80 + ports: + - "30020:80" + + identity-server-sts: + environment: + - ASPNETCORE_ENVIRONMENT=Production + - ASPNETCORE_URLS=http://0.0.0.0:80 + ports: + - "44385:80" + apigateway-admin-service: - build: - context: ./aspnet-core/services/Publish/apigateway-admin - volumes: - - /var/opt/abp/logs/apigateway-admin:/app/Logs - depends_on: - - identity-server-sts - - admin-service - restart: always + environment: + - ASPNETCORE_ENVIRONMENT=Production + - ASPNETCORE_URLS=http://0.0.0.0:80 + ports: + - "30001:80" apigateway-host-service: - build: - context: ./aspnet-core/services/Publish/apigateway-host - volumes: - - /var/opt/abp/logs/apigateway-host:/app/Logs - depends_on: - - identity-server-sts - - apigateway-admin-service - restart: always + environment: + - ASPNETCORE_ENVIRONMENT=Production + - ASPNETCORE_URLS=http://0.0.0.0:80 + ports: + - "30000:80" abp-vue-admin-client: - build: - context: ./aspnet-core/services/Publish/client - restart: always - -volumes: - dbdata: - -networks: - linyun-abp: + ports: + - "40000:80"