本文整理汇总了C#中IJabbrRepository.GetOnlineUsers方法的典型用法代码示例。如果您正苦于以下问题:C# IJabbrRepository.GetOnlineUsers方法的具体用法?C# IJabbrRepository.GetOnlineUsers怎么用?C# IJabbrRepository.GetOnlineUsers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IJabbrRepository
的用法示例。
在下文中一共展示了IJabbrRepository.GetOnlineUsers方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckUserStatus
private static void CheckUserStatus(IJabbrRepository repo, IHubContext hubContext)
{
var inactiveUsers = new List<ChatUser>();
var offlineUsers = new List<ChatUser>();
IQueryable<ChatUser> users = repo.GetOnlineUsers();
foreach (var user in users)
{
var status = (UserStatus)user.Status;
var elapsed = DateTime.UtcNow - user.LastActivity;
if (user.ConnectedClients.Count == 0)
{
// Fix users that are marked as inactive but have no clients
user.Status = (int)UserStatus.Offline;
offlineUsers.Add(user);
}
else if (elapsed.TotalMinutes > 5)
{
user.Status = (int)UserStatus.Inactive;
inactiveUsers.Add(user);
}
}
if (inactiveUsers.Count > 0)
{
PerformRoomAction(inactiveUsers, roomGroup =>
{
hubContext.Clients.Group(roomGroup.Room.Name).markInactive(roomGroup.Users);
});
}
// TODO: Only remove users relevant to this server.
//if (offlineUsers.Count > 0)
//{
// PerformRoomAction(offlineUsers, roomGroup =>
// {
// foreach (var user in roomGroup.Users)
// {
// hubContext.Clients.Group(roomGroup.Room.Name).leave(user, roomGroup.Room.Name);
// }
// });
//}
}
示例2: MarkInactiveUsers
private static void MarkInactiveUsers(IJabbrRepository repo, IHubContext hubContext)
{
var inactiveUsers = new List<ChatUser>();
IQueryable<ChatUser> users = repo.GetOnlineUsers();
foreach (var user in users)
{
var status = (UserStatus)user.Status;
var elapsed = DateTime.UtcNow - user.LastActivity;
if (user.ConnectedClients.Count == 0)
{
// Fix users that are marked as inactive but have no clients
user.Status = (int)UserStatus.Offline;
}
else if (elapsed.TotalMinutes > 15)
{
user.Status = (int)UserStatus.Inactive;
inactiveUsers.Add(user);
}
}
if (inactiveUsers.Count > 0)
{
var roomGroups = from u in inactiveUsers
from r in u.Rooms
select new { User = u, Room = r } into tuple
group tuple by tuple.Room into g
select new
{
Room = g.Key,
Users = g.Select(t => new UserViewModel(t.User))
};
foreach (var roomGroup in roomGroups)
{
hubContext.Clients.Group(roomGroup.Room.Name).markInactive(roomGroup.Users).Wait();
}
}
}
示例3: CheckUserStatus
private void CheckUserStatus(ILogger logger, IJabbrRepository repo)
{
var inactiveUsers = new List<ChatUser>();
IQueryable<ChatUser> users = repo.GetOnlineUsers().Where(u =>
SqlFunctions.DateDiff("mi", u.LastActivity, DateTime.UtcNow) > 5);
foreach (var user in users.ToList())
{
user.Status = (int)UserStatus.Inactive;
inactiveUsers.Add(user);
}
if (inactiveUsers.Count > 0)
{
PerformRoomAction(inactiveUsers, async roomGroup =>
{
await _hubContext.Clients.Group(roomGroup.Room.Name).markInactive(roomGroup.Users);
});
repo.CommitChanges();
}
}
示例4: RemoveOfflineUsers
private void RemoveOfflineUsers(ILogger logger, IJabbrRepository repo)
{
var offlineUsers = new List<ChatUser>();
IQueryable<ChatUser> users = repo.GetOnlineUsers();
foreach (var user in users.ToList())
{
if (user.ConnectedClients.Count == 0)
{
logger.Log("{0} has no clients. Marking as offline", user.Name);
// Fix users that are marked as inactive but have no clients
user.Status = (int)UserStatus.Offline;
offlineUsers.Add(user);
}
}
if (offlineUsers.Count > 0)
{
PerformRoomAction(offlineUsers, async roomGroup =>
{
foreach (var user in roomGroup.Users)
{
await _hubContext.Clients.Group(roomGroup.Room.Name).leave(user, roomGroup.Room.Name);
}
});
repo.CommitChanges();
}
}