Exemplo n.º 1
0
 public NotificationInfo(Guid id, string notificationName, NotificationData data, string entityTypeName, string entityId, NotificationSeverity severity, DateTime creationTime, Guid?tenantId)
 {
     Id = id;
     NotificationName = notificationName;
     Data             = data;
     EntityTypeName   = entityTypeName;
     EntityId         = entityId;
     Severity         = severity;
     CreationTime     = creationTime;
     TenantId         = tenantId;
 }
Exemplo n.º 2
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
                        )
                    );
            }
        }