Example #1
0
        public NotificationInfo Convert(Notification source, NotificationInfo destination, ResolutionContext context)
        {
            destination = new NotificationInfo
            {
                Name         = source.NotificationName,
                Type         = source.Type,
                Severity     = source.Severity,
                CreationTime = source.CreationTime,
                TenantId     = source.TenantId
            };
            destination.SetId(source.NotificationId);

            var dataType = Type.GetType(source.NotificationTypeName);

            Check.NotNull(dataType, source.NotificationTypeName);

            var data = JsonConvert.DeserializeObject(source.NotificationData, dataType);

            if (data != null && data is NotificationData notificationData)
            {
                destination.Data = NotificationDataConverter.Convert(notificationData);
            }
            else
            {
                destination.Data = new NotificationData();
                destination.Data.TrySetData("data", source.NotificationData);
            }
            return(destination);
        }
Example #2
0
        public virtual async Task HandleEventAsync(NotificationEventData eventData)
        {
            var notification = NotificationDefinitionManager.Get(eventData.Name);

            var notificationInfo = new NotificationInfo
            {
                Name         = notification.Name,
                CreationTime = eventData.CreationTime,
                Data         = eventData.Data,
                Severity     = eventData.Severity,
                Lifetime     = notification.NotificationLifetime,
                TenantId     = eventData.TenantId,
                Type         = notification.NotificationType
            };

            notificationInfo.SetId(SnowflakeIdGenerator.Create());

            notificationInfo.Data = NotificationDataConverter.Convert(notificationInfo.Data);

            Logger.LogDebug($"Persistent notification {notificationInfo.Name}");

            // 持久化通知
            await NotificationStore.InsertNotificationAsync(notificationInfo);

            var providers = Enumerable
                            .Reverse(NotificationPublishProviderManager.Providers);

            await PublishFromProvidersAsync(providers, eventData.Users, notificationInfo);
        }
Example #3
0
        public virtual async Task HandleEventAsync(NotificationEventData eventData)
        {
            // 这样做的话就要注意了
            // 当只有一个消费者订阅时,事件总线会认为消息已经处理,从而发布Ack指令,从消息队列中移除此消息
            // 可能造成通知数据丢失
            var application = Options.Application ?? "Abp";

            if (!string.Equals(application, eventData.Application, StringComparison.InvariantCultureIgnoreCase))
            {
                // 不是当前监听应用的消息不做处理
                return;
            }
            // 如果上面过滤了应用程序,这里可以使用Get方法,否则,最好使用GetOrNull加以判断
            var notification = NotificationDefinitionManager.Get(eventData.Name);

            var notificationInfo = new NotificationInfo
            {
                Name         = notification.Name,
                CreationTime = eventData.CreationTime,
                Data         = eventData.Data,
                Severity     = eventData.Severity,
                Lifetime     = notification.NotificationLifetime,
                TenantId     = eventData.TenantId,
                Type         = notification.NotificationType
            };

            notificationInfo.SetId(SnowflakeIdGenerator.Create());

            // TODO: 可以做成一个接口来序列化消息
            notificationInfo.Data = NotificationDataConverter.Convert(notificationInfo.Data);

            Logger.LogDebug($"Persistent notification {notificationInfo.Name}");

            // 持久化通知
            await NotificationStore.InsertNotificationAsync(notificationInfo);

            var providers = Enumerable
                            .Reverse(NotificationPublishProviderManager.Providers);

            await PublishFromProvidersAsync(providers, eventData.Users, notificationInfo);
        }
Example #4
0
        public virtual async Task HandleEventAsync(NotificationEto <NotificationData> eventData)
        {
            // 如果上面过滤了应用程序,这里可以使用Get方法,否则,最好使用GetOrNull加以判断
            var notification = NotificationDefinitionManager.GetOrNull(eventData.Name);

            if (notification == null)
            {
                return;
            }

            var notificationInfo = new NotificationInfo
            {
                Name         = notification.Name,
                CreationTime = eventData.CreationTime,
                Data         = eventData.Data,
                Severity     = eventData.Severity,
                Lifetime     = notification.NotificationLifetime,
                TenantId     = eventData.TenantId,
                Type         = notification.NotificationType
            };

            notificationInfo.SetId(eventData.Id);

            // TODO: 可以做成一个接口来序列化消息
            notificationInfo.Data = NotificationDataConverter.Convert(notificationInfo.Data);

            Logger.LogDebug($"Persistent notification {notificationInfo.Name}");

            // 持久化通知
            await NotificationStore.InsertNotificationAsync(notificationInfo);

            var providers = Enumerable
                            .Reverse(NotificationPublishProviderManager.Providers);

            await PublishFromProvidersAsync(providers, eventData.Users, notificationInfo);
        }