Exemplo n.º 1
0
        /// <summary>
        /// 发布通知
        /// </summary>
        /// <param name="provider">通知发布者</param>
        /// <param name="notificationInfo">通知信息</param>
        /// <param name="subscriptionUserIdentifiers">订阅用户列表</param>
        /// <returns></returns>
        protected async Task PublishAsync(INotificationPublishProvider provider, NotificationInfo notificationInfo,
                                          IEnumerable <UserIdentifier> subscriptionUserIdentifiers)
        {
            try
            {
                Logger.LogDebug($"Sending notification with provider {provider.Name}");
                var notifacationDataMapping = Options.NotificationDataMappings
                                              .GetMapItemOrNull(provider.Name, notificationInfo.CateGory);
                if (notifacationDataMapping != null)
                {
                    notificationInfo.Data = notifacationDataMapping.MappingFunc(notificationInfo.Data);
                }
                // 发布
                await provider.PublishAsync(notificationInfo, subscriptionUserIdentifiers);

                Logger.LogDebug($"Send notification {notificationInfo.Name} with provider {provider.Name} was successful");
            }
            catch (Exception ex)
            {
                Logger.LogWarning($"Send notification error with provider {provider.Name}");
                Logger.LogWarning($"Error message:{ex.Message}");

                Logger.LogTrace(ex, $"Send notification error with provider { provider.Name}");

                Logger.LogDebug($"Send notification error, notification {notificationInfo.Name} entry queue");
                // 发送失败的消息进入后台队列
                await BackgroundJobManager.EnqueueAsync(
                    new NotificationPublishJobArgs(notificationInfo.GetId(),
                                                   provider.GetType().AssemblyQualifiedName,
                                                   subscriptionUserIdentifiers.ToList(),
                                                   notificationInfo.TenantId));
            }
        }
Exemplo n.º 2
0
        protected override async Task SendEmailAsync()
        {
            var publicationState = EventData.Entity.IsPublished ? "Published" : "Unpublished";
            var time             = EventData.Entity.LastModificationTime.Humanize();
            var message          = $"your product named {EventData.Entity.Title} was {publicationState} {time}";

            if (ToUser != null)
            {
                await BackgroundJobManager.EnqueueAsync(new EmailSendingArgs()
                {
                    EmailAddress = ToUser.Email,
                    Subject      = $"Product {publicationState}",
                    Body         = message
                });
            }
        }