Exemplo n.º 1
0
 /// <summary>
 /// 发送通知
 /// </summary>
 /// <param name="notificationName">订阅名称</param>
 /// <param name="data">推送的数据对象(自定义对象需要继承 NotificationData)</param>
 /// <param name="entityIdentifier">实体通知对象(new EntityIdentifier(typeof(对象类型), 对象id))</param>
 /// <param name="severity">通知类型枚举</param>
 /// <param name="userIds">接收通知的用户id集合 (如果未null将发送到所有人)</param>
 /// <param name="excludedUserIds">不接收通知的用户id集合</param>
 /// <returns></returns>
 public virtual async Task PublishAsync(string notificationName, NotificationData data = null, EntityIdentifier entityIdentifier = null, NotificationSeverity severity = NotificationSeverity.Info, UserIdentifier[] userIds = null, UserIdentifier[] excludedUserIds = null)
 {
     if (userIds != null)
     {
         //获取订阅了该通知的用户
         userIds = userIds.Where(w => _notificationSubscriptionManager.IsSubscribed(w, notificationName)).ToArray();
     }
     await _notificationPublisher.PublishAsync(notificationName, data, entityIdentifier, severity, userIds, excludedUserIds);
 }
Exemplo n.º 2
0
        //Just for test, could be implemented better
        private async Task ManageSubscription(string notificationName)
        {
            var userIdentifier = new UserIdentifier(AbpSession.TenantId, AbpSession.UserId ?? -1);

            if (AbpSession.UserId.HasValue &&
                !_notificationSubscriptionManager.IsSubscribed(
                    userIdentifier, notificationName))
            {
                await _notificationSubscriptionManager.SubscribeAsync(userIdentifier, notificationName);
            }
        }