Цитата:
Сообщение от
Dolores
А как лучше проводить мониторинг активности пользователей, чтобы определить делает ли пользователь что-то в программе или просто сеанс открыл ? По какой таблице? К журналу базы данных нельзя привязаться, т.к. не все действия пользователей журнализируются...
На случай если пользователь ничего не делает - есть timeout сессии, тут придумывать не нужно.
В AX 2012 следующие методы реализуют подсчет числа активных сессий:
Info::licensedUsers(),
Info::licensedComUsers(),
так же в
Info::licensedUsersTotal() идет подсчет.
Есть замечательный класс
SysUserOnline:
X++:
server static container getAllOnlineUserInfo()
{
int num;
int idleTicks;
container users;
xSession session;
UserInfo userInfo;
AOSClientMode clientMode;
SysClientSessions clientSessions;
;
num = 0;
// SessionId field is not recognized
// BP deviation documented
while select clientSessions where
//clientSessions.Status == SessionState::Running || clientSessions.Status == SessionState::Killed
clientSessions.Status == SessionStatus::Running
|| clientSessions.Status == SessionStatus::Killed
|| clientSessions.Status == SessionStatus::MarkedAsKill
{
session = new xSession(clientSessions.SessionId);
if(clientSessions.UserId)
{
select firstonly userInfo
where userInfo.Id == clientSessions.UserId;
if (userInfo) //If no SYS_OPEN_DOMAIN access they should not be shown
{
num++;
clientMode = AOSClientMode::Thin;
idleTicks = 0;
users += [[clientSessions.SessionId,
clientSessions.UserId,
clientSessions.ClientType,
DateTimeUtil::applyTimeZoneOffset(clientSessions.LoginDateTime, DateTimeUtil::getUserPreferredTimeZone()),
clientSessions.ClientComputer,
session.databaseSpid(),
userInfo.Name,
clientMode,
idleTicks
]];
}
}
}
users = [users,num];
return users;
}
Ограничить количество входов одного пользователя. В классе Info:
X++:
void startupPost()
{
int counter;
int num = 0;
int maxSessions = Info::licensedUsersTotal();
xSession session;
UserInfo userInfo;
UserId currentUserId;
;
currentUserId = curuserid();
for(counter = 1; counter < maxSessions;counter++ )
{
session = new xSession(counter, true);
if(session && session.userId())
{
select firstOnly userInfo
where userInfo.id == session.userId();
if (userInfo && (currentUserId == session.userId()))
{
num++ ;
}
}
}
if (num > 1)
{
if(ox::yesno("Вы пытаетесь посторно войти пот тем же именем пользователя, а это не разрешается. Все равно войти?",
DialogButton::Yes, "Войти", "Выйти") == DialogButton::No)
{
infolog.shutDown(true);
}
}
}