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.
94 lines
2.5 KiB
94 lines
2.5 KiB
using JetBrains.Annotations; |
|
using System; |
|
using System.Collections.Generic; |
|
using Volo.Abp; |
|
using Volo.Abp.Localization; |
|
|
|
namespace Sanhe.Abp.Notifications; |
|
|
|
/// <summary> |
|
/// 通知定义 |
|
/// </summary> |
|
public class NotificationDefinition |
|
{ |
|
/// <summary> |
|
/// 通知名称 |
|
/// </summary> |
|
[NotNull] |
|
public string Name { get; set; } |
|
/// <summary> |
|
/// 通知显示名称 |
|
/// </summary> |
|
[NotNull] |
|
public ILocalizableString DisplayName { |
|
get => _displayName; |
|
set => _displayName = Check.NotNull(value, nameof(value)); |
|
} |
|
private ILocalizableString _displayName; |
|
/// <summary> |
|
/// 通知说明 |
|
/// </summary> |
|
[CanBeNull] |
|
public ILocalizableString Description { get; set; } |
|
/// <summary> |
|
/// 允许客户端显示订阅 |
|
/// </summary> |
|
public bool AllowSubscriptionToClients { get; set; } |
|
/// <summary> |
|
/// 存活类型 |
|
/// </summary> |
|
public NotificationLifetime NotificationLifetime { get; set; } |
|
/// <summary> |
|
/// 通知类型 |
|
/// </summary> |
|
public NotificationType NotificationType { get; set; } |
|
/// <summary> |
|
/// 通知提供者 |
|
/// </summary> |
|
public List<string> Providers { get; } |
|
/// <summary> |
|
/// 额外属性 |
|
/// </summary> |
|
[NotNull] |
|
public Dictionary<string, object> Properties { get; } |
|
|
|
public NotificationDefinition( |
|
string name, |
|
ILocalizableString displayName = null, |
|
ILocalizableString description = null, |
|
NotificationType notificationType = NotificationType.Application, |
|
NotificationLifetime lifetime = NotificationLifetime.Persistent, |
|
bool allowSubscriptionToClients = false) |
|
{ |
|
Name = name; |
|
DisplayName = displayName ?? new FixedLocalizableString(name); |
|
Description = description; |
|
NotificationLifetime = lifetime; |
|
NotificationType = notificationType; |
|
AllowSubscriptionToClients = allowSubscriptionToClients; |
|
|
|
Providers = new List<string>(); |
|
Properties = new Dictionary<string, object>(); |
|
} |
|
|
|
public virtual NotificationDefinition WithProviders(params string[] providers) |
|
{ |
|
if (!providers.IsNullOrEmpty()) |
|
{ |
|
Providers.AddRange(providers); |
|
} |
|
|
|
return this; |
|
} |
|
|
|
public virtual NotificationDefinition WithProperty(string key, object value) |
|
{ |
|
Properties[key] = value; |
|
return this; |
|
} |
|
|
|
public override string ToString() |
|
{ |
|
return $"[{nameof(NotificationDefinition)} {Name}]"; |
|
} |
|
}
|
|
|