Introduce INotificationHandler

This commit is contained in:
nicolas.dorier
2020-06-16 23:29:25 +09:00
parent 677cc3bee9
commit cff5b82b06
9 changed files with 85 additions and 83 deletions

View File

@@ -27,31 +27,4 @@ namespace BTCPayServer.Models.NotificationViewModels
public string ActionLink { get; set; }
public bool Seen { get; set; }
}
public static class NotificationViewModelExt
{
static Dictionary<string, Type> _NotificationTypes;
static NotificationViewModelExt()
{
_NotificationTypes = Assembly.GetExecutingAssembly()
.GetTypes()
.Select(t => (t, NotificationType: t.GetCustomAttribute<NotificationAttribute>()?.NotificationType))
.Where(t => t.NotificationType is string)
.ToDictionary(o => o.NotificationType, o => o.t);
}
public static NotificationViewModel ToViewModel(this NotificationData data)
{
var casted = (BaseNotification)JsonConvert.DeserializeObject(ZipUtils.Unzip(data.Blob), _NotificationTypes[data.NotificationType]);
var obj = new NotificationViewModel
{
Id = data.Id,
Created = data.Created,
Seen = data.Seen
};
casted.FillViewModel(obj);
return obj;
}
}
}