Browse Source

split the connection string change event data.

pull/354/head
cKey 4 years ago
parent
commit
d853b7fd64
  1. 31
      aspnet-core/modules/tenants/LINGYUN.Abp.MultiTenancy.DbFinder/LINGYUN/Abp/MultiTenancy/DbFinder/EventBus/Distributed/ConnectionStringChangedEventHandler.cs
  2. 16
      aspnet-core/modules/tenants/LINGYUN.Abp.MultiTenancy.RemoteService/LINGYUN/Abp/MultiTenancy/RemoteService/EventBus/Distributed/ConnectionStringChangedEventHandler.cs
  3. 4
      aspnet-core/modules/tenants/LINGYUN.Abp.MultiTenancy/LINGYUN/Abp/MultiTenancy/ConnectionStringCreatedEventData.cs
  4. 11
      aspnet-core/modules/tenants/LINGYUN.Abp.MultiTenancy/LINGYUN/Abp/MultiTenancy/ConnectionStringDeletedEventData.cs
  5. 16
      aspnet-core/modules/tenants/LINGYUN.Abp.TenantManagement.Application/LINGYUN/Abp/TenantManagement/TenantAppService.cs
  6. 2
      aspnet-core/services/account/AuthServer.Host/Localization/Resources/zh-Hans.json

31
aspnet-core/modules/tenants/LINGYUN.Abp.MultiTenancy.DbFinder/LINGYUN/Abp/MultiTenancy/DbFinder/EventBus/Distributed/ConnectionStringChangedEventHandler.cs

@ -1,5 +1,4 @@
using LINGYUN.Abp.MultiTenancy.DbFinder;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging;
using System;
using System.Threading.Tasks;
using Volo.Abp.Caching;
@ -10,9 +9,12 @@ using Volo.Abp.MultiTenancy;
using Volo.Abp.TenantManagement;
using Volo.Abp.Uow;
namespace LINGYUN.Abp.MultiTenancy.RemoteService.EventBus.Distributed
namespace LINGYUN.Abp.MultiTenancy.DbFinder.EventBus.Distributed
{
public class ConnectionStringChangedEventHandler : IDistributedEventHandler<ConnectionStringChangedEventData>, ITransientDependency
public class ConnectionStringChangedEventHandler :
IDistributedEventHandler<ConnectionStringCreatedEventData>,
IDistributedEventHandler<ConnectionStringDeletedEventData>,
ITransientDependency
{
private readonly ILogger<ConnectionStringChangedEventHandler> _logger;
private readonly ICurrentTenant _currentTenant;
@ -32,7 +34,7 @@ namespace LINGYUN.Abp.MultiTenancy.RemoteService.EventBus.Distributed
}
[UnitOfWork]
public virtual async Task HandleEventAsync(ConnectionStringChangedEventData eventData)
public virtual async Task HandleEventAsync(ConnectionStringCreatedEventData eventData)
{
try
{
@ -64,5 +66,24 @@ namespace LINGYUN.Abp.MultiTenancy.RemoteService.EventBus.Distributed
_logger.LogException(ex);
}
}
public virtual async Task HandleEventAsync(ConnectionStringDeletedEventData eventData)
{
try
{
using (_currentTenant.Change(null))
{
await _cache.RemoveManyAsync(
new string[] {
TenantConfigurationCacheItem.CalculateCacheKey(eventData.Id.ToString()),
TenantConfigurationCacheItem.CalculateCacheKey(eventData.Name)
});
}
}
catch (Exception ex)
{
_logger.LogException(ex);
}
}
}
}

16
aspnet-core/modules/tenants/LINGYUN.Abp.MultiTenancy.RemoteService/LINGYUN/Abp/MultiTenancy/RemoteService/EventBus/Distributed/ConnectionStringChangedEventHandler.cs

@ -7,7 +7,10 @@ using Volo.Abp.EventBus.Distributed;
namespace LINGYUN.Abp.MultiTenancy.RemoteService.EventBus.Distributed
{
public class ConnectionStringChangedEventHandler : IDistributedEventHandler<ConnectionStringChangedEventData>, ITransientDependency
public class ConnectionStringChangedEventHandler :
IDistributedEventHandler<ConnectionStringCreatedEventData>,
IDistributedEventHandler<ConnectionStringDeletedEventData>,
ITransientDependency
{
private readonly ITenantAppService _tenantAppService;
private readonly IDistributedCache<TenantConfigurationCacheItem> _cache;
@ -21,7 +24,7 @@ namespace LINGYUN.Abp.MultiTenancy.RemoteService.EventBus.Distributed
}
public virtual async Task HandleEventAsync(ConnectionStringChangedEventData eventData)
public virtual async Task HandleEventAsync(ConnectionStringCreatedEventData eventData)
{
var tenantDto = await _tenantAppService.GetAsync(eventData.Id);
var tenantConnectionStringsDto = await _tenantAppService.GetConnectionStringAsync(eventData.Id);
@ -40,5 +43,14 @@ namespace LINGYUN.Abp.MultiTenancy.RemoteService.EventBus.Distributed
TenantConfigurationCacheItem.CalculateCacheKey(tenantDto.Name),
cacheItem);
}
public virtual async Task HandleEventAsync(ConnectionStringDeletedEventData eventData)
{
await _cache.RemoveManyAsync(
new string[] {
TenantConfigurationCacheItem.CalculateCacheKey(eventData.Id.ToString()),
TenantConfigurationCacheItem.CalculateCacheKey(eventData.Name)
});
}
}
}

4
aspnet-core/modules/tenants/LINGYUN.Abp.MultiTenancy/LINGYUN/Abp/MultiTenancy/ConnectionStringChangedEventData.cs → aspnet-core/modules/tenants/LINGYUN.Abp.MultiTenancy/LINGYUN/Abp/MultiTenancy/ConnectionStringCreatedEventData.cs

@ -2,12 +2,10 @@
namespace LINGYUN.Abp.MultiTenancy
{
public class ConnectionStringChangedEventData
public class ConnectionStringCreatedEventData
{
public Guid Id { get; set; }
public string OriginName { get; set; }
public string Name { get; set; }
}
}

11
aspnet-core/modules/tenants/LINGYUN.Abp.MultiTenancy/LINGYUN/Abp/MultiTenancy/ConnectionStringDeletedEventData.cs

@ -0,0 +1,11 @@
using System;
namespace LINGYUN.Abp.MultiTenancy
{
public class ConnectionStringDeletedEventData
{
public Guid Id { get; set; }
public string Name { get; set; }
}
}

16
aspnet-core/modules/tenants/LINGYUN.Abp.TenantManagement.Application/LINGYUN/Abp/TenantManagement/TenantAppService.cs

@ -145,15 +145,20 @@ namespace LINGYUN.Abp.TenantManagement
public virtual async Task<TenantConnectionStringDto> SetConnectionStringAsync(Guid id, TenantConnectionStringCreateOrUpdateDto tenantConnectionStringCreateOrUpdate)
{
var tenant = await TenantRepository.GetAsync(id);
tenant.SetConnectionString(tenantConnectionStringCreateOrUpdate.Name, tenantConnectionStringCreateOrUpdate.Value);
var eventData = new ConnectionStringChangedEventData
if (tenant.FindConnectionString(tenantConnectionStringCreateOrUpdate.Name) == null)
{
CurrentUnitOfWork.OnCompleted(async () =>
{
var eventData = new ConnectionStringCreatedEventData
{
Id = tenant.Id,
OriginName = tenantConnectionStringCreateOrUpdate.Name,
Name = tenantConnectionStringCreateOrUpdate.Name
};
await EventBus.PublishAsync(eventData);
});
}
tenant.SetConnectionString(tenantConnectionStringCreateOrUpdate.Name, tenantConnectionStringCreateOrUpdate.Value);
return new TenantConnectionStringDto
{
@ -169,10 +174,9 @@ namespace LINGYUN.Abp.TenantManagement
tenant.RemoveConnectionString(name);
var eventData = new ConnectionStringChangedEventData
var eventData = new ConnectionStringDeletedEventData
{
Id = tenant.Id,
OriginName = name,
Name = name
};
await EventBus.PublishAsync(eventData);

2
aspnet-core/services/account/AuthServer.Host/Localization/Resources/zh-Hans.json

@ -11,7 +11,7 @@
"InvaidGenerateTwoFactorToken": "验证码生成失败,请联系管理员!",
"TextTemplate:Abp.Account.MailSecurityVerifyLink": "邮件安全验证模板",
"MailSecurityVerify": "邮件安全验证",
"VerifyMyEmailAddress": "亲爱的 {0},您好<br/><p>您此次邮件安全验证码如下,请输入验证码进行下一步操作。</p><p>如非你本人操作,请忽略此邮件。</p>",
"VerifyMyEmailAddress": "您好<br/><p>您此次邮件安全验证码如下,请输入验证码进行下一步操作。</p><p>如非你本人操作,请忽略此邮件。</p>",
"MailSecurityVerifyRemarks": "此邮件为系统所发,请勿直接回复。",
"ClickToValidation": "点击进行验证"
}

Loading…
Cancel
Save