Exemple #1
0
 public Task <bool> IsSubscribedAsync(Guid userId, string notificationName, NotificationEntityIdentifier entityIdentifier = null)
 {
     return(_store.IsSubscribedAsync(
                userId,
                notificationName,
                entityIdentifier == null ? null : entityIdentifier.Type.FullName,
                entityIdentifier == null ? null : entityIdentifier.Id
                ));
 }
Exemple #2
0
 public async Task UnsubscribeAsync(Guid userId, string notificationName, NotificationEntityIdentifier entityIdentifier = null)
 {
     await _store.DeleteSubscriptionAsync(
         userId,
         notificationName,
         entityIdentifier == null?null : entityIdentifier.Type.FullName,
         entityIdentifier == null?null : entityIdentifier.Id
         );
 }
Exemple #3
0
        public async Task SubscribeAsync(Guid userId, string notificationName, NotificationEntityIdentifier entityIdentifier = null)
        {
            if (await IsSubscribedAsync(userId, notificationName, entityIdentifier))
            {
                return;
            }

            await _store.InsertSubscriptionAsync(
                new NotificationSubscriptionInfo(
                    userId,
                    notificationName,
                    entityIdentifier == null ? null : entityIdentifier.Type.FullName,
                    entityIdentifier == null ? null : entityIdentifier.Id,
                    _clock.Now,
                    _currentTenant.Id
                    )
                );
        }
Exemple #4
0
        public virtual async Task PublishAsync(
            [NotNull] string notificationName,
            NotificationData data = null,
            NotificationEntityIdentifier entityIdentifier = null,
            NotificationSeverity severity = NotificationSeverity.Info,
            Guid[] userIds         = null,
            Guid[] excludedUserIds = null)
        {
            var notificationInfo = new NotificationInfo(
                _guidGenerator.Create(),
                notificationName,
                data,
                entityIdentifier?.Type.FullName,
                entityIdentifier?.Id,
                severity,
                _clock.Now,
                _currentTenant.Id
                );


            if (userIds != null && userIds.Length <= MaxUserCountToDirectlyDistributeANotification)
            {
                //We can directly distribute the notification since there are not much receivers
                await _notificationDistributer.DistributeAsync(notificationInfo, userIds, excludedUserIds);
            }
            else
            {
                //We enqueue a background job since distributing may get a long time
                await _backgroundJobManager.EnqueueAsync(
                    new NotificationDistributionJobArgs(
                        notificationInfo,
                        userIds,
                        excludedUserIds
                        )
                    );
            }
        }
Exemple #5
0
        public async Task <List <NotificationSubscriptionInfo> > GetSubscriptionsAsync(string notificationName, NotificationEntityIdentifier entityIdentifier = null)
        {
            var notificationSubscriptionInfos = await _store.GetSubscriptionsAsync(
                notificationName,
                entityIdentifier == null?null : entityIdentifier.Type.FullName,
                entityIdentifier == null?null : entityIdentifier.Id
                );

            return(notificationSubscriptionInfos);
        }