Abp模块
abp
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

52 lines
1.6 KiB

using Sanhe.Abp.Localization.Dynamic;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Entities.Events;
using Volo.Abp.EventBus;
using Volo.Abp.EventBus.Distributed;
namespace Sanhe.Abp.LocalizationManagement;
public class LocalizationSynchronizer :
ILocalEventHandler<EntityCreatedEventData<Text>>,
ILocalEventHandler<EntityUpdatedEventData<Text>>,
ILocalEventHandler<EntityDeletedEventData<Text>>,
ITransientDependency
{
private readonly IDistributedEventBus _eventBus;
public LocalizationSynchronizer(
IDistributedEventBus eventBus)
{
_eventBus = eventBus;
}
public async virtual Task HandleEventAsync(EntityCreatedEventData<Text> eventData)
{
await HandleEventAsync(BuildResetEventData(eventData.Entity));
}
public async virtual Task HandleEventAsync(EntityUpdatedEventData<Text> eventData)
{
await HandleEventAsync(BuildResetEventData(eventData.Entity));
}
public async virtual Task HandleEventAsync(EntityDeletedEventData<Text> eventData)
{
var data = BuildResetEventData(eventData.Entity);
data.IsDeleted = true;
await HandleEventAsync(data);
}
private LocalizedStringCacheResetEventData BuildResetEventData(Text text)
{
return new LocalizedStringCacheResetEventData(
text.ResourceName, text.CultureName, text.Key, text.Value);
}
private async Task HandleEventAsync(LocalizedStringCacheResetEventData eventData)
{
await _eventBus.PublishAsync(eventData);
}
}