diff --git a/aspnet-core/LINGYUN.MicroService.IdentityServer.sln b/aspnet-core/LINGYUN.MicroService.IdentityServer.sln index 28a924727..c77c2c1dc 100644 --- a/aspnet-core/LINGYUN.MicroService.IdentityServer.sln +++ b/aspnet-core/LINGYUN.MicroService.IdentityServer.sln @@ -57,8 +57,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.IdentityServer. EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "theming", "theming", "{1D7CE7E0-37AB-477B-919B-B1EB2899A17E}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.AspNetCore.Components.WebAssembly.AntDesign", "theming\Volo.Abp.AspNetCore.Components.WebAssembly.AntDesign\Volo.Abp.AspNetCore.Components.WebAssembly.AntDesign.csproj", "{596BB67C-7765-4481-9C8B-EAE0D9726B75}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Identity.WeChat", "modules\wechat\LINGYUN.Abp.Identity.WeChat\LINGYUN.Abp.Identity.WeChat.csproj", "{46C3E5D2-7738-4C0F-AC51-C61A024CAF23}" EndProject Global @@ -139,10 +137,6 @@ Global {79CAF2CA-E9E1-48A5-A21F-3786383C12E0}.Debug|Any CPU.Build.0 = Debug|Any CPU {79CAF2CA-E9E1-48A5-A21F-3786383C12E0}.Release|Any CPU.ActiveCfg = Release|Any CPU {79CAF2CA-E9E1-48A5-A21F-3786383C12E0}.Release|Any CPU.Build.0 = Release|Any CPU - {596BB67C-7765-4481-9C8B-EAE0D9726B75}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {596BB67C-7765-4481-9C8B-EAE0D9726B75}.Debug|Any CPU.Build.0 = Debug|Any CPU - {596BB67C-7765-4481-9C8B-EAE0D9726B75}.Release|Any CPU.ActiveCfg = Release|Any CPU - {596BB67C-7765-4481-9C8B-EAE0D9726B75}.Release|Any CPU.Build.0 = Release|Any CPU {46C3E5D2-7738-4C0F-AC51-C61A024CAF23}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {46C3E5D2-7738-4C0F-AC51-C61A024CAF23}.Debug|Any CPU.Build.0 = Debug|Any CPU {46C3E5D2-7738-4C0F-AC51-C61A024CAF23}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -176,7 +170,6 @@ Global {F762D1BB-66FB-421A-A917-D80B7DCC0DC0} = {AF8AECC8-0F42-4FC5-B3C0-00987BA8279F} {D63C0CA8-554D-43F2-8DB4-8B464E4C1CDA} = {98887A8F-7040-4FA1-842F-A4C77A61ED09} {79CAF2CA-E9E1-48A5-A21F-3786383C12E0} = {98887A8F-7040-4FA1-842F-A4C77A61ED09} - {596BB67C-7765-4481-9C8B-EAE0D9726B75} = {1D7CE7E0-37AB-477B-919B-B1EB2899A17E} {46C3E5D2-7738-4C0F-AC51-C61A024CAF23} = {AF8AECC8-0F42-4FC5-B3C0-00987BA8279F} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution diff --git a/aspnet-core/modules/tenants/LINGYUN.Abp.MultiTenancy.DbFinder/LINGYUN/Abp/MultiTenancy/DbFinder/EventBus/Distributed/ConnectionStringChangedEventHandler.cs b/aspnet-core/modules/tenants/LINGYUN.Abp.MultiTenancy.DbFinder/LINGYUN/Abp/MultiTenancy/DbFinder/EventBus/Distributed/ConnectionStringChangedEventHandler.cs new file mode 100644 index 000000000..e3a954400 --- /dev/null +++ b/aspnet-core/modules/tenants/LINGYUN.Abp.MultiTenancy.DbFinder/LINGYUN/Abp/MultiTenancy/DbFinder/EventBus/Distributed/ConnectionStringChangedEventHandler.cs @@ -0,0 +1,68 @@ +using LINGYUN.Abp.MultiTenancy.DbFinder; +using Microsoft.Extensions.Logging; +using System; +using System.Threading.Tasks; +using Volo.Abp.Caching; +using Volo.Abp.Data; +using Volo.Abp.DependencyInjection; +using Volo.Abp.EventBus.Distributed; +using Volo.Abp.MultiTenancy; +using Volo.Abp.TenantManagement; +using Volo.Abp.Uow; + +namespace LINGYUN.Abp.MultiTenancy.RemoteService.EventBus.Distributed +{ + public class ConnectionStringChangedEventHandler : IDistributedEventHandler, ITransientDependency + { + private readonly ILogger _logger; + private readonly ICurrentTenant _currentTenant; + private readonly ITenantRepository _tenantRepository; + private readonly IDistributedCache _cache; + + public ConnectionStringChangedEventHandler( + ICurrentTenant currentTenant, + ITenantRepository tenantRepository, + ILogger logger, + IDistributedCache cache) + { + _cache = cache; + _logger = logger; + _currentTenant = currentTenant; + _tenantRepository = tenantRepository; + } + + [UnitOfWork] + public virtual async Task HandleEventAsync(ConnectionStringChangedEventData eventData) + { + try + { + using (_currentTenant.Change(null)) + { + var tenant = await _tenantRepository.FindAsync(eventData.Id, true); + if (tenant == null) + { + return; + } + var connectionStrings = new ConnectionStrings(); + foreach (var tenantConnectionString in tenant.ConnectionStrings) + { + connectionStrings[tenantConnectionString.Name] = tenantConnectionString.Value; + } + var cacheItem = new TenantConfigurationCacheItem(tenant.Id, tenant.Name, connectionStrings); + + await _cache.SetAsync( + TenantConfigurationCacheItem.CalculateCacheKey(eventData.Id.ToString()), + cacheItem); + + await _cache.SetAsync( + TenantConfigurationCacheItem.CalculateCacheKey(eventData.Name), + cacheItem); + } + } + catch (Exception ex) + { + _logger.LogException(ex); + } + } + } +} diff --git a/aspnet-core/modules/tenants/LINGYUN.Abp.MultiTenancy.RemoteService/LINGYUN/Abp/MultiTenancy/RemoteService/EventBus/Distributed/ConnectionStringChangedEventHandler.cs b/aspnet-core/modules/tenants/LINGYUN.Abp.MultiTenancy.RemoteService/LINGYUN/Abp/MultiTenancy/RemoteService/EventBus/Distributed/ConnectionStringChangedEventHandler.cs new file mode 100644 index 000000000..73365afa0 --- /dev/null +++ b/aspnet-core/modules/tenants/LINGYUN.Abp.MultiTenancy.RemoteService/LINGYUN/Abp/MultiTenancy/RemoteService/EventBus/Distributed/ConnectionStringChangedEventHandler.cs @@ -0,0 +1,44 @@ +using LINGYUN.Abp.TenantManagement; +using System.Threading.Tasks; +using Volo.Abp.Caching; +using Volo.Abp.Data; +using Volo.Abp.DependencyInjection; +using Volo.Abp.EventBus.Distributed; + +namespace LINGYUN.Abp.MultiTenancy.RemoteService.EventBus.Distributed +{ + public class ConnectionStringChangedEventHandler : IDistributedEventHandler, ITransientDependency + { + private readonly ITenantAppService _tenantAppService; + private readonly IDistributedCache _cache; + + public ConnectionStringChangedEventHandler( + ITenantAppService tenantAppService, + IDistributedCache cache) + { + _cache = cache; + _tenantAppService = tenantAppService; + } + + + public virtual async Task HandleEventAsync(ConnectionStringChangedEventData eventData) + { + var tenantDto = await _tenantAppService.GetAsync(eventData.Id); + var tenantConnectionStringsDto = await _tenantAppService.GetConnectionStringAsync(eventData.Id); + var connectionStrings = new ConnectionStrings(); + foreach (var tenantConnectionString in tenantConnectionStringsDto.Items) + { + connectionStrings[tenantConnectionString.Name] = tenantConnectionString.Value; + } + var cacheItem = new TenantConfigurationCacheItem(tenantDto.Id, tenantDto.Name, connectionStrings); + + await _cache.SetAsync( + TenantConfigurationCacheItem.CalculateCacheKey(eventData.Id.ToString()), + cacheItem); + + await _cache.SetAsync( + TenantConfigurationCacheItem.CalculateCacheKey(tenantDto.Name), + cacheItem); + } + } +} diff --git a/aspnet-core/modules/tenants/LINGYUN.Abp.MultiTenancy/LINGYUN/Abp/MultiTenancy/ConnectionStringChangedEventData.cs b/aspnet-core/modules/tenants/LINGYUN.Abp.MultiTenancy/LINGYUN/Abp/MultiTenancy/ConnectionStringChangedEventData.cs new file mode 100644 index 000000000..d12d41518 --- /dev/null +++ b/aspnet-core/modules/tenants/LINGYUN.Abp.MultiTenancy/LINGYUN/Abp/MultiTenancy/ConnectionStringChangedEventData.cs @@ -0,0 +1,13 @@ +using System; + +namespace LINGYUN.Abp.MultiTenancy +{ + public class ConnectionStringChangedEventData + { + public Guid Id { get; set; } + + public string OriginName { get; set; } + + public string Name { get; set; } + } +}