/// <inheritdoc/>
        public Task SendNotificationsAsync(UserNotification[] userNotifications)
        {
            foreach (var userNotification in userNotifications)
            {
                try
                {
                    var onlineClient = _onlineClientManager.GetByUserIdOrNull(userNotification.UserId);
                    if (onlineClient == null)
                    {
                        //User is not online. No problem, go to the next user.
                        continue;
                    }

                    var signalRClient = CommonHub.Clients.Client(onlineClient.ConnectionId);
                    if (signalRClient == null)
                    {
                        Logger.Debug("Can not get user " + userNotification.UserId + " from SignalR hub!");
                        continue;
                    }

                    //TODO: await call or not?
                    signalRClient.getNotification(userNotification);
                }
                catch (Exception ex)
                {
                    Logger.Warn("Could not send notification to userId: " + userNotification.UserId);
                    Logger.Warn(ex.ToString(), ex);
                }
            }

            return(Task.FromResult(0));
        }
 /// <summary>
 /// Determines whether the specified user is online or not.
 /// 确定指定的用户是否在线
 /// </summary>
 /// <param name="onlineClientManager">The online client manager. 在线客户端管理类</param>
 /// <param name="userId">User id. 用户Id</param>
 public static bool IsOnline(IOnlineClientManager onlineClientManager,long userId)
 {
     return onlineClientManager.GetByUserIdOrNull(userId) != null;
 }
 /// <summary>
 /// Determines whether the specified user is online or not.
 /// </summary>
 /// <param name="onlineClientManager">The online client manager.</param>
 /// <param name="user">User.</param>
 public static bool IsOnline(IOnlineClientManager onlineClientManager, UserIdentifier user)
 {
     return onlineClientManager.GetByUserIdOrNull(user) != null;
 }
Пример #4
0
 /// <summary>
 /// Determines whether the specified user is online or not.
 /// </summary>
 /// <param name="onlineClientManager">The online client manager.</param>
 /// <param name="userId">User id.</param>
 public static bool IsOnline(IOnlineClientManager onlineClientManager, long userId)
 {
     return(onlineClientManager.GetByUserIdOrNull(userId) != null);
 }
Пример #5
0
 /// <summary>
 /// Determines whether the specified user is online or not.
 /// </summary>
 /// <param name="onlineClientManager">The online client manager.</param>
 /// <param name="user">User.</param>
 public static bool IsOnline(IOnlineClientManager onlineClientManager, UserIdentifier user)
 {
     return(onlineClientManager.GetByUserIdOrNull(user) != null);
 }