Exemple #1
0
        public async Task <MemoryStream> Export()
        {
            //FileStream fs = new FileStream("C:\\Users\\jm\\Desktop\\委托和事件\\1.txt", FileMode.OpenOrCreate, FileAccess.Read);

            UserNotification not = new UserNotification();

            not.Id       = Guid.NewGuid();
            not.TenantId = 1;
            not.State    = UserNotificationState.Unread;
            //not.Notification
            TenantNotification tenNot = new TenantNotification();

            tenNot.TenantId         = 1;
            tenNot.Id               = Guid.NewGuid();
            tenNot.NotificationName = "export";
            Dictionary <string, object> s = new Dictionary <string, object>();

            s.Add("message", "我的通知");
            tenNot.Data = new NotificationData()
            {
                Properties = s
            };
            UserNotification[] notArray = { not };
            _not.SendNotificationsAsync(notArray);

            byte[]       buff = File.ReadAllBytes("C:\\Users\\jm\\Desktop\\委托和事件\\1.txt");
            MemoryStream ms   = new MemoryStream(buff);

            return(ms);
        }
 /// <summary>
 /// Converts <see cref="UserNotificationInfo"/> to <see cref="UserNotification"/>.
 /// </summary>
 public static UserNotification ToUserNotification(this UserNotificationInfo userNotificationInfo, TenantNotification tenantNotification)
 {
     return new UserNotification
     {
         Id = userNotificationInfo.Id,
         Notification = tenantNotification,
         UserId = userNotificationInfo.UserId,
         State = userNotificationInfo.State,
         TenantId = userNotificationInfo.TenantId
     };
 }
 /// <summary>
 ///     Converts <see cref="UserNotificationInfo" /> to <see cref="UserNotification" />.
 /// </summary>
 public static UserNotification ToUserNotification(this UserNotificationInfo userNotificationInfo,
                                                   TenantNotification tenantNotification)
 {
     return(new UserNotification
     {
         Id = userNotificationInfo.Id,
         Notification = tenantNotification,
         UserId = userNotificationInfo.UserId,
         State = userNotificationInfo.State,
         TenantId = userNotificationInfo.TenantId
     });
 }
        /// <summary>
        /// 发送点对点消息
        /// </summary>
        /// <param name="recipientId"></param>
        /// <param name="chatDetailed"></param>
        /// <param name="severity"></param>
        /// <returns></returns>
        public virtual async Task SendChatAsync(long recipientId, string chatDetailed, NotificationSeverity severity = NotificationSeverity.Info)
        {
            UserIdentifier userIdentifier = new UserIdentifier(AbpSessionExtens.TenantId, recipientId);
            //用户不在线直接返回
            var onlineClients = _onlineClientManager.GetAllByUserId(userIdentifier);

            if (onlineClients == null || onlineClients.Count == 0)
            {
                return;
            }

            UserInfo userModel     = _cacheManagerExtens.GetUserInfoCache(recipientId);
            string   promptContent = "您有一条来自[" + userModel.UserNameCn + "]的消息";
            string   promptTitle   = "您有一条新消息";

            FrameNotificationData frameNotificationData = new FrameNotificationData(promptContent);

            frameNotificationData.NotificationType     = "chat"; //推送的类型用于前端JS判断
            frameNotificationData.Title                = promptTitle;
            frameNotificationData.NotificationDetailed = chatDetailed;
            frameNotificationData.SendId               = AbpSessionExtens.UserId.Value;

            TenantNotification tenantNotification = new TenantNotification()
            {
                Id               = Guid.NewGuid(),
                Data             = frameNotificationData,
                Severity         = severity,
                NotificationName = "站内短信",
                TenantId         = userIdentifier.TenantId,
                CreationTime     = DateTime.Now
            };

            List <UserNotification> userNotification = new List <UserNotification>();

            userNotification.Add(
                new UserNotification
            {
                Id           = Guid.NewGuid(),
                Notification = tenantNotification,
                UserId       = userIdentifier.UserId,
                State        = UserNotificationState.Unread,
                TenantId     = userIdentifier.TenantId
            });

            await _realTimeNotifier.SendNotificationsAsync(userNotification.ToArray());
        }