コード例 #1
0
        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);
            }
        }
コード例 #2
0
        public async Task GetAllUserTokens()
        {
            var user   = fillTestDbHelper.Users.FirstOrDefault();
            var tokens = new List <TokenVm>
            {
                await tokensService.CreateTokenPairByUserIdAsync(user.Id),
                await tokensService.CreateTokenPairByUserIdAsync(user.Id)
            };
            var expectedTokens = fillTestDbHelper.Users
                                 .FirstOrDefault(opt => opt.Id == user.Id)
                                 .Tokens;
            var actualTokens = await tokensService.GetAllUsersTokensAsync(new List <long> {
                user.Id
            }, false);

            Assert.Contains(actualTokens, opt => expectedTokens.Any(p => p.Id == opt.Id));
        }