当前位置: 首页>>代码示例>>C#>>正文


C# IJabbrRepository.GetOnlineUsers方法代码示例

本文整理汇总了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);
            //        }
            //    });
            //}
        }
开发者ID:csainty,项目名称:JabbR,代码行数:45,代码来源:Startup.BackgroundWork.cs

示例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();
                }
            }
        }
开发者ID:arri-cc,项目名称:JabbR,代码行数:41,代码来源:Startup.BackgroundWork.cs

示例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();
            }
        }
开发者ID:BrianRosamilia,项目名称:JabbR,代码行数:23,代码来源:PresenceMonitor.cs

示例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();
            }
        }
开发者ID:BrianRosamilia,项目名称:JabbR,代码行数:30,代码来源:PresenceMonitor.cs


注:本文中的IJabbrRepository.GetOnlineUsers方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。