public async Task RegisterNewSessionAsync(AuthorizationToken token, RefreshToken refreshToken, string userAgent, string ip, string description, PlatformTypes platformType, LoginApplication application)
        {
            if (!token.RootSessionId.HasValue)
            {
                throw new Exception("Cannot RegisterNewSession without RootSessionId");
            }

            var pkBase64 = token.PublicKey != null?Convert.ToBase64String(token.PublicKey) : "";

            var session = RootSessionNoSqlEntity.Generate(token.RootSessionId.Value, token.TraderId(), token.BrandId, userAgent, ip, pkBase64,
                                                          token.Passed2FA, token.EmailVerified, description, platformType, application);

            session.Expires = refreshToken.Expires;

            var task1 = _sessionWriter.InsertOrReplaceAsync(session).AsTask();

            var shortSession = ShortRootSessionNoSqlEntity.Create(session);

            shortSession.Expires = refreshToken.Expires;
            var task2 = _rootSessionWriter.InsertOrReplaceAsync(shortSession).AsTask();

            var task3 = _rootSessionWriter.GetCountAsync(
                ShortRootSessionNoSqlEntity.GeneratePartitionKey(token.TraderId())).AsTask();
            await Task.WhenAll(task1, task2, task3);

            if (task3.Result > _maxSessionsCount)
            {
                var sessions = await _sessionWriter.GetAsync(
                    ShortRootSessionNoSqlEntity.GeneratePartitionKey(token.TraderId()));

                var oldestSession = sessions.OrderBy(s => s.CreateTime).First();
                await Logout(token.TraderId(), oldestSession.RootSessionId);
            }
        }