public virtual async Task PublishAsync(string notificationName, NotificationData data = null, EntityIdentifier entityIdentifier = null, NotificationSeverity severity = NotificationSeverity.Info, long[] userIds = null) { if (notificationName.IsNullOrEmpty()) { throw new ArgumentException("NotificationName can not be null or whitespace!", "notificationName"); } var notificationInfo = new NotificationInfo { NotificationName = notificationName, EntityTypeName = entityIdentifier == null ? null : entityIdentifier.Type.FullName, EntityTypeAssemblyQualifiedName = entityIdentifier == null ? null : entityIdentifier.Type.AssemblyQualifiedName, EntityId = entityIdentifier == null ? null : entityIdentifier.Id.ToJsonString(), Severity = severity, UserIds = userIds.IsNullOrEmpty() ? null : userIds.JoinAsString(","), Data = data == null ? null : data.ToJsonString(), DataTypeName = data == null ? null : data.GetType().AssemblyQualifiedName }; await _store.InsertNotificationAsync(notificationInfo); await _backgroundJobManager.EnqueueAsync<NotificationDistributionJob, NotificationDistributionJobArgs>( new NotificationDistributionJobArgs( notificationInfo.Id ) ); }
public virtual async Task PublishAsync( string notificationName, NotificationData data = null, EntityIdentifier entityIdentifier = null, NotificationSeverity severity = NotificationSeverity.Info, long[] userIds = null, long[] excludedUserIds = null, int?[] tenantIds = null) { if (notificationName.IsNullOrEmpty()) { throw new ArgumentException("NotificationName can not be null or whitespace!", "notificationName"); } if (!tenantIds.IsNullOrEmpty() && !userIds.IsNullOrEmpty()) { throw new ArgumentException("tenantIds can be set only userIds is not set!", "tenantIds"); } if (tenantIds.IsNullOrEmpty() && userIds.IsNullOrEmpty()) { tenantIds = new[] {AbpSession.TenantId}; } var notificationInfo = new NotificationInfo { NotificationName = notificationName, EntityTypeName = entityIdentifier == null ? null : entityIdentifier.Type.FullName, EntityTypeAssemblyQualifiedName = entityIdentifier == null ? null : entityIdentifier.Type.AssemblyQualifiedName, EntityId = entityIdentifier == null ? null : entityIdentifier.Id.ToJsonString(), Severity = severity, UserIds = userIds.IsNullOrEmpty() ? null : userIds.JoinAsString(","), ExcludedUserIds = excludedUserIds.IsNullOrEmpty() ? null : excludedUserIds.JoinAsString(","), TenantIds = tenantIds.IsNullOrEmpty() ? null : tenantIds.JoinAsString(","), Data = data == null ? null : data.ToJsonString(), DataTypeName = data == null ? null : data.GetType().AssemblyQualifiedName }; await _store.InsertNotificationAsync(notificationInfo); await CurrentUnitOfWork.SaveChangesAsync(); //To get Id of the notification 获得通知的身份证 if (userIds != null && userIds.Length <= 5) { //We can directly distribute the notification since there are not much receivers //我们可以直接分发通知,因为没有太多的接收器 await _notificationDistributer.DistributeAsync(notificationInfo.Id); } else { //We enqueue a background job since distributing may get a long time //我们将后台工作分配可能会很长一段时间以来 await _backgroundJobManager.EnqueueAsync<NotificationDistributionJob, NotificationDistributionJobArgs>( new NotificationDistributionJobArgs( notificationInfo.Id ) ); } }
/// <summary> /// 取消通知-异步 /// </summary> /// <param name="userId">用户Id</param> /// <param name="notificationName">通知名称</param> /// <param name="entityIdentifier">实体标识</param> /// <returns></returns> public async Task UnsubscribeAsync(long userId, string notificationName, EntityIdentifier entityIdentifier = null) { await _store.DeleteSubscriptionAsync( userId, notificationName, entityIdentifier == null ? null : entityIdentifier.Type.FullName, entityIdentifier == null ? null : entityIdentifier.Id.ToJsonString() ); }
public Task<bool> IsSubscribedAsync(long userId, string notificationName, EntityIdentifier entityIdentifier = null) { return _store.IsSubscribedAsync( userId, notificationName, entityIdentifier == null ? null : entityIdentifier.Type.FullName, entityIdentifier == null ? null : entityIdentifier.Id.ToJsonString() ); }
public async Task SubscribeAsync(long userId, string notificationName, EntityIdentifier entityIdentifier = null) { await _store.InsertSubscriptionAsync( new NotificationSubscriptionInfo( userId, notificationName, entityIdentifier ) ); }
public async Task<List<NotificationSubscription>> GetSubscriptionsAsync(string notificationName, EntityIdentifier entityIdentifier = null) { var notificationSubscriptionInfos = await _store.GetSubscriptionsAsync( notificationName, entityIdentifier == null ? null : entityIdentifier.Type.FullName, entityIdentifier == null ? null : entityIdentifier.Id.ToJsonString() ); return notificationSubscriptionInfos .Select(nsi => nsi.ToNotificationSubscription()) .ToList(); }
public virtual async Task PublishAsync( string notificationName, NotificationData data = null, EntityIdentifier entityIdentifier = null, NotificationSeverity severity = NotificationSeverity.Info, long[] userIds = null, long[] excludedUserIds = null, int?[] tenantIds = null) { if (notificationName.IsNullOrEmpty()) { throw new ArgumentException("NotificationName can not be null or whitespace!", "notificationName"); } if (!tenantIds.IsNullOrEmpty() && !userIds.IsNullOrEmpty()) { throw new ArgumentException("tenantIds can be set only userIds is not set!", "tenantIds"); } if (tenantIds.IsNullOrEmpty() && userIds.IsNullOrEmpty()) { tenantIds = new[] {AbpSession.TenantId}; } var notificationInfo = new NotificationInfo { NotificationName = notificationName, EntityTypeName = entityIdentifier == null ? null : entityIdentifier.Type.FullName, EntityTypeAssemblyQualifiedName = entityIdentifier == null ? null : entityIdentifier.Type.AssemblyQualifiedName, EntityId = entityIdentifier == null ? null : entityIdentifier.Id.ToJsonString(), Severity = severity, UserIds = userIds.IsNullOrEmpty() ? null : userIds.JoinAsString(","), ExcludedUserIds = excludedUserIds.IsNullOrEmpty() ? null : excludedUserIds.JoinAsString(","), TenantIds = tenantIds.IsNullOrEmpty() ? null : tenantIds.JoinAsString(","), Data = data == null ? null : data.ToJsonString(), DataTypeName = data == null ? null : data.GetType().AssemblyQualifiedName }; await _store.InsertNotificationAsync(notificationInfo); await CurrentUnitOfWork.SaveChangesAsync(); //To get Id of the notification await _backgroundJobManager.EnqueueAsync<NotificationDistributionJob, NotificationDistributionJobArgs>( new NotificationDistributionJobArgs( notificationInfo.Id ) ); }
/// <summary> /// 订阅-异步 /// </summary> /// <param name="tenantId">租户Id</param> /// <param name="userId">用户Id</param> /// <param name="notificationName">通知名称</param> /// <param name="entityIdentifier">实体标识</param> /// <returns></returns> public async Task SubscribeAsync(int? tenantId, long userId, string notificationName, EntityIdentifier entityIdentifier = null) { if (await IsSubscribedAsync(userId, notificationName, entityIdentifier)) { return; } await _store.InsertSubscriptionAsync( new NotificationSubscriptionInfo( tenantId, userId, notificationName, entityIdentifier ) ); }
/// <summary> /// Checks if a user subscribed for a notification. /// </summary> /// <param name="notificationSubscriptionManager">Notification subscription manager</param> /// <param name="user">User.</param> /// <param name="notificationName">Name of the notification.</param> /// <param name="entityIdentifier">entity identifier</param> public static bool IsSubscribed(this INotificationSubscriptionManager notificationSubscriptionManager, UserIdentifier user, string notificationName, EntityIdentifier entityIdentifier = null) { return AsyncHelper.RunSync(() => notificationSubscriptionManager.IsSubscribedAsync(user, notificationName, entityIdentifier)); }
/// <summary> /// Gets all subscribtions for given notification. /// </summary> /// <param name="notificationSubscriptionManager">Notification subscription manager</param> /// <param name="tenantId">Tenant id. Null for the host.</param> /// <param name="notificationName">Name of the notification.</param> /// <param name="entityIdentifier">entity identifier</param> public static List<NotificationSubscription> GetSubscriptions(this INotificationSubscriptionManager notificationSubscriptionManager, int? tenantId, string notificationName, EntityIdentifier entityIdentifier = null) { return AsyncHelper.RunSync(() => notificationSubscriptionManager.GetSubscriptionsAsync(tenantId, notificationName, entityIdentifier)); }
/// <summary> /// Unsubscribes from a notification. /// </summary> /// <param name="notificationSubscriptionManager">Notification subscription manager</param> /// <param name="user">User.</param> /// <param name="notificationName">Name of the notification.</param> /// <param name="entityIdentifier">entity identifier</param> public static void Unsubscribe(this INotificationSubscriptionManager notificationSubscriptionManager, UserIdentifier user, string notificationName, EntityIdentifier entityIdentifier = null) { AsyncHelper.RunSync(() => notificationSubscriptionManager.UnsubscribeAsync(user, notificationName, entityIdentifier)); }
/// <summary> /// Publishes a new notification. /// </summary> /// <param name="notificationPublisher">Notification publisher</param> /// <param name="notificationName">Unique notification name</param> /// <param name="data">Notification data (optional)</param> /// <param name="entityIdentifier">The entity identifier if this notification is related to an entity</param> /// <param name="severity">Notification severity</param> /// <param name="userIds">Target user id(s). Used to send notification to specific user(s). If this is null/empty, the notification is sent to all subscribed users</param> public static void Publish(this INotificationPublisher notificationPublisher, string notificationName, NotificationData data = null, EntityIdentifier entityIdentifier = null, NotificationSeverity severity = NotificationSeverity.Info, UserIdentifier[] userIds = null) { AsyncHelper.RunSync(() => notificationPublisher.PublishAsync(notificationName, data, entityIdentifier, severity, userIds)); }
/// <summary> /// Subscribes to a notification. /// </summary> /// <param name="notificationSubscriptionManager">Notification subscription manager</param> /// <param name="userId">The user id.</param> /// <param name="notificationName">Name of the notification.</param> /// <param name="tenantId"></param> /// <param name="entityIdentifier">entity identifier</param> public static void Subscribe(this INotificationSubscriptionManager notificationSubscriptionManager, int? tenantId, long userId, string notificationName, EntityIdentifier entityIdentifier = null) { AsyncHelper.RunSync(() => notificationSubscriptionManager.SubscribeAsync(tenantId, userId, notificationName, entityIdentifier)); }