public async void SendNewSessionNoticeAsync(ClientConnection clientConnection)
        {
            try
            {
                if (clientConnection.CurrentToken == null)
                {
                    throw new ArgumentNullException(nameof(clientConnection));
                }

                List <TokenVm> tokens = await tokensService.GetAllUsersTokensAsync(new List <long> {
                    clientConnection.UserId.GetValueOrDefault()
                }).ConfigureAwait(false);

                var token      = clientConnection.CurrentToken;
                var userTokens = GetOfflineUserTokens(tokens, clientConnection.UserId.GetValueOrDefault());
                userTokens = userTokens.Where(opt => opt.AccessToken != token.AccessToken)?.ToList();
                if (userTokens != null && userTokens.Any())
                {
                    NewSessionNotice notice = new NewSessionNotice(new SessionVm
                    {
                        AppName    = token.AppName,
                        DeviceName = token.DeviceName,
                        OSName     = token.OSName,
                        IP         = clientConnection.ClientIP.ToString(),
                        TokenId    = token.Id.GetValueOrDefault()
                    });
                    await SendNotificationRequestAsync(userTokens.Select(opt => opt.DeviceTokenId), notice).ConfigureAwait(false);
                }
            }
            catch (Exception ex)
            {
                Logger.WriteLog(ex);
            }
        }
Beispiel #2
0
 public async void SendNewSessionNoticeAsync(ClientConnection connection)
 {
     try
     {
         pushNotificationsService.SendNewSessionNoticeAsync(connection);
         var clientConnections = connectionsService
                                 .GetUserClientConnections(connection.UserId.GetValueOrDefault())?
                                 .Where(opt => opt != connection)?.ToList();
         if (!clientConnections.IsNullOrEmpty())
         {
             NewSessionNotice notice = new NewSessionNotice(new SessionVm
             {
                 AppName    = connection.CurrentToken.AppName,
                 DeviceName = connection.CurrentToken.DeviceName,
                 IP         = connection.ClientIP.ToString(),
                 OSName     = connection.CurrentToken.OSName,
                 TokenId    = connection.CurrentToken.Id.GetValueOrDefault()
             });
             await SendNoticeToClientsAsync(clientConnections, notice).ConfigureAwait(false);
         }
     }
     catch (Exception ex)
     {
         Logger.WriteLog(ex);
     }
 }