10 changed files with 171 additions and 18 deletions
@ -0,0 +1,34 @@ |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.BackgroundJobs; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace LINGYUN.Abp.Notifications |
|||
{ |
|||
public class NotificationPublishJob : AsyncBackgroundJob<NotificationPublishJobArgs>, ITransientDependency |
|||
{ |
|||
protected INotificationStore Store { get; } |
|||
protected IServiceProvider ServiceProvider { get; } |
|||
|
|||
public NotificationPublishJob( |
|||
INotificationStore store, |
|||
IServiceProvider serviceProvider) |
|||
{ |
|||
Store = store; |
|||
ServiceProvider = serviceProvider; |
|||
} |
|||
|
|||
public override async Task ExecuteAsync(NotificationPublishJobArgs args) |
|||
{ |
|||
var providerType = Type.GetType(args.ProviderType); |
|||
|
|||
if (ServiceProvider.GetRequiredService(providerType) is INotificationPublishProvider publishProvider) |
|||
{ |
|||
var notification = await Store.GetNotificationOrNullAsync(args.TenantId, args.NotificationId); |
|||
|
|||
await publishProvider.PublishAsync(notification, args.UserIdentifiers); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
|
|||
namespace LINGYUN.Abp.Notifications |
|||
{ |
|||
public class NotificationPublishJobArgs |
|||
{ |
|||
public Guid? TenantId { get; set; } |
|||
public long NotificationId { get; set; } |
|||
public string ProviderType { get; set; } |
|||
public List<UserIdentifier> UserIdentifiers { get; set; } |
|||
public NotificationPublishJobArgs(long id, string providerType, List<UserIdentifier> userIdentifiers, Guid? tenantId = null ) |
|||
{ |
|||
NotificationId = id; |
|||
ProviderType = providerType; |
|||
UserIdentifiers = userIdentifiers; |
|||
TenantId = tenantId; |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue