public virtual async Task UnsubscribeAllAsync( Guid?tenantId, string notificationName, CancellationToken cancellationToken = default) { await _store.DeleteAllUserSubscriptionAsync(tenantId, notificationName, cancellationToken); }
/// <summary> /// 发送通知 /// </summary> /// <param name="notificationName">通知名称</param> /// <param name="data">通知数据</param> /// <param name="tenantId">租户</param> /// <param name="notificationSeverity">级别</param> /// <returns></returns> public virtual async Task DispatchAsync(NotificationName notificationName, NotificationData data, Guid?tenantId = null, NotificationSeverity notificationSeverity = NotificationSeverity.Info) { // 获取自定义的通知 var defineNotification = _notificationDefinitionManager.Get(notificationName.CateGory); //// 没有定义的通知,应该也要能发布、订阅, //// 比如订单之类的,是以订单编号为通知名称,这是动态的,没法自定义 //if(defineNotification == null) //{ // defineNotification = new NotificationDefinition(notificationName.CateGory); //} var notificationInfo = new NotificationInfo { CateGory = notificationName.CateGory, Name = notificationName.Name, CreationTime = DateTime.Now, NotificationSeverity = notificationSeverity, Lifetime = defineNotification.NotificationLifetime, NotificationType = defineNotification.NotificationType, TenantId = tenantId, Data = data }; var providers = Enumerable .Reverse(_notificationPublishProviderManager.Providers); if (defineNotification.Providers.Any()) { providers = providers.Where(p => defineNotification.Providers.Contains(p.Name)); } await PublishFromProvidersAsync(providers, notificationInfo); if (notificationInfo.Lifetime == NotificationLifetime.OnlyOne) { // 一次性通知在发送完成后就取消用户订阅 await _notificationStore.DeleteAllUserSubscriptionAsync(notificationInfo.TenantId, notificationInfo.Name); } }
public virtual async Task UnsubscribeAllAsync(Guid?tenantId, string notificationName) { await _store.DeleteAllUserSubscriptionAsync(tenantId, notificationName); }