mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-01-19 05:33:31 +01:00
Generalizing saving to database and registration of NotificationEventBase classes
This commit is contained in:
parent
b6e3ad9325
commit
73588ea22b
@ -7,7 +7,7 @@ using BTCPayServer.Data;
|
|||||||
using ExchangeSharp;
|
using ExchangeSharp;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace BTCPayServer.Events
|
namespace BTCPayServer.Events.Notifications
|
||||||
{
|
{
|
||||||
public abstract class NotificationEventBase
|
public abstract class NotificationEventBase
|
||||||
{
|
{
|
@ -28,15 +28,30 @@ namespace BTCPayServer.HostedServices
|
|||||||
|
|
||||||
protected override void SubscribeToEvents()
|
protected override void SubscribeToEvents()
|
||||||
{
|
{
|
||||||
Subscribe<NewVersionNotification>();
|
SubscribeAllChildrenOfNotificationEventBase();
|
||||||
base.SubscribeToEvents();
|
base.SubscribeToEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// subscribe all children of NotificationEventBase
|
||||||
|
public void SubscribeAllChildrenOfNotificationEventBase()
|
||||||
|
{
|
||||||
|
var method = this.GetType().GetMethod(nameof(SubscribeHelper));
|
||||||
|
var notificationTypes = this.GetType().Assembly.GetTypes().Where(a => typeof(NotificationEventBase).IsAssignableFrom(a));
|
||||||
|
foreach (var notif in notificationTypes)
|
||||||
|
{
|
||||||
|
var generic = method.MakeGenericMethod(notif);
|
||||||
|
generic.Invoke(this, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// we need publicly accessible method for reflection invoke
|
||||||
|
public void SubscribeHelper<T>() => base.Subscribe<T>();
|
||||||
|
|
||||||
protected override async Task ProcessEvent(object evt, CancellationToken cancellationToken)
|
protected override async Task ProcessEvent(object evt, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
if (evt is NewVersionNotification)
|
if (evt is NotificationEventBase)
|
||||||
{
|
{
|
||||||
var data = (evt as NewVersionNotification).ToData();
|
var data = (evt as NotificationEventBase).ToData();
|
||||||
|
|
||||||
var admins = await _UserManager.GetUsersInRoleAsync(Roles.ServerAdmin);
|
var admins = await _UserManager.GetUsersInRoleAsync(Roles.ServerAdmin);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user