| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- using System;
- using System.Threading.Tasks;
- using Abp;
- using Abp.Dependency;
- using Abp.Notifications;
- using Abp.Runtime.Session;
- using WeOnlineApp.Configuration;
- using IwbZero.Runtime.Session;
- namespace WeOnlineApp.CommonManager.Notifications
- {
- public class NotificationManager : INotificationManager, ISingletonDependency
- {
- private readonly INotificationPublisher _notificationPublisher;
- private readonly IwbSession _abpSession;
- public NotificationManager(INotificationPublisher notificationPublisher, IwbSession abpSession)
- {
- _notificationPublisher = notificationPublisher;
- _abpSession = abpSession;
- }
- public async Task WelcomeToSystemAsync()
- {
- await _notificationPublisher.PublishAsync(
- IwbNotificationName.WelcomeMsg, new MessageNotificationData("欢迎登陆"), severity: NotificationSeverity.Success,
- userIds: new[] { _abpSession.ToUserIdentifier() });
- }
- /// <summary>
- /// 发送给指定用户消息(info)
- /// </summary>
- /// <param name="user"></param>
- /// <param name="message"></param>
- /// <returns></returns>
- public async Task SendMsgAsync(UserIdentifier user, string message)
- {
- await SendMsgAsync(user, message, NotificationSeverity.Info);
- }
- /// <summary>
- /// 发送给指定用户消息
- /// </summary>
- /// <param name="user"></param>
- /// <param name="message"></param>
- /// <param name="severity"></param>
- /// <returns></returns>
- public async Task SendMsgAsync(UserIdentifier user, string message, NotificationSeverity severity)
- {
- await _notificationPublisher.PublishAsync(
- IwbNotificationName.SendMsg,
- new MessageNotificationData(message), severity: severity, userIds: new[] { user });
- }
- /// <summary>
- /// 发送某种消息给订阅用户(Info)
- /// </summary>
- /// <param name="msgName">消息唯一名称</param>
- /// <param name="message"></param>
- /// <returns></returns>
- public async Task SendMsgAsync(string msgName, string message)
- {
- await SendMsgAsync(msgName, message, NotificationSeverity.Info);
- }
- /// <summary>
- /// 发送某种消息给订阅用户
- /// </summary>
- /// <param name="msgName">消息唯一名称</param>
- /// <param name="message"></param>
- /// <param name="severity"></param>
- /// <returns></returns>
- public async Task SendMsgAsync(string msgName, string message, NotificationSeverity severity)
- {
- await _notificationPublisher.PublishAsync(msgName, new MessageNotificationData(message), severity: severity);
- }
- /// <summary>
- /// 发送某种消息给指定用户(带发送人)
- /// </summary>
- /// <param name="user"></param>
- /// <param name="msgName"></param>
- /// <param name="data"></param>
- /// <param name="severity"></param>
- /// <returns></returns>
- public async Task SendMessageAsync(UserIdentifier user, string msgName, SendMsgNotificationData data, NotificationSeverity severity)
- {
- await _notificationPublisher.PublishAsync(msgName, data, severity: severity, userIds: new[] { user });
- }
- /// <summary>
- /// 发送某种消息给订阅用户(带发送人)
- /// </summary>
- /// <param name="msgName"></param>
- /// <param name="data"></param>
- /// <param name="severity"></param>
- /// <returns></returns>
- public async Task SendMessageAsync(string msgName, SendMsgNotificationData data, NotificationSeverity severity)
- {
- await _notificationPublisher.PublishAsync(msgName, data, severity: severity);
- }
- }
- [Serializable]
- public class SendMsgNotificationData : NotificationData
- {
- public string SenderUserName { get; set; }
- public string Message { get; set; }
- public SendMsgNotificationData(string senderUserName, string message)
- {
- SenderUserName = senderUserName;
- Message = message;
- }
- }
- }
|