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>, ILocalEventHandler>, ILocalEventHandler>, ITransientDependency { private readonly IDistributedEventBus _eventBus; public LocalizationSynchronizer( IDistributedEventBus eventBus) { _eventBus = eventBus; } public async virtual Task HandleEventAsync(EntityCreatedEventData eventData) { await HandleEventAsync(BuildResetEventData(eventData.Entity)); } public async virtual Task HandleEventAsync(EntityUpdatedEventData eventData) { await HandleEventAsync(BuildResetEventData(eventData.Entity)); } public async virtual Task HandleEventAsync(EntityDeletedEventData 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); } }