コード例 #1
0
        public void FixCorruptConnections(int moduleid)
        {
            try
            {
                if (moduleid == EntityId)
                {
                    List <ChatHubUser> onlineUsers = chatHubRepository.GetOnlineUsers().ToList();
                    foreach (var user in onlineUsers)
                    {
                        foreach (ChatHubConnection connection in user.Connections)
                        {
                            connection.Status = Enum.GetName(typeof(ChatHubConnectionStatus), ChatHubConnectionStatus.Inactive);
                            chatHubRepository.UpdateChatHubConnection(connection);

                            logger.Log(LogLevel.Information, this, LogFunction.Delete, "ChatHubConnection Deleted {ChatHubConnection}", connection);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Log(LogLevel.Error, this, LogFunction.Delete, ex, "Delete Error {Error}", ex.Message);
                throw;
            }
        }
コード例 #2
0
ファイル: ChatHub.cs プロジェクト: farvashani/oqtane.chathubs
        public override async Task OnDisconnectedAsync(Exception exception)
        {
            ChatHubUser user = await this.GetChatHubUserAsync();

            var rooms = chatHubRepository.GetChatHubRoomsByUser(user).Active();

            foreach (var room in await rooms.ToListAsync())
            {
                if (user.Connections.Active().Count() == 1)
                {
                    var chatHubUserClientModel = this.chatHubService.CreateChatHubUserClientModel(user);
                    await Clients.Group(room.Id.ToString()).SendAsync("RemoveUser", chatHubUserClientModel, room.Id.ToString());
                }

                await this.SendGroupNotification(string.Format("{0} disconnected from chat with client device {1}.", user.DisplayName, this.MakeStringAnonymous(Context.ConnectionId, 7, '*')), room.Id, Context.ConnectionId, user, ChatHubMessageType.Connect_Disconnect);

                await Groups.RemoveFromGroupAsync(Context.ConnectionId, room.Id.ToString());
            }

            var connection = await this.chatHubRepository.GetConnectionByConnectionId(Context.ConnectionId);

            connection.Status = Enum.GetName(typeof(ChatHubConnectionStatus), ChatHubConnectionStatus.Inactive);
            chatHubRepository.UpdateChatHubConnection(connection);

            await base.OnDisconnectedAsync(exception);
        }
コード例 #3
0
        public override async Task OnDisconnectedAsync(Exception exception)
        {
            ChatHubUser user = await this.GetChatHubUserAsync();

            var rooms = chatHubRepository.GetChatHubRoomsByUser(user).Enabled();

            foreach (var room in await rooms.ToListAsync())
            {
                if (user.Connections.Active().Count() == 1)
                {
                    var clientModel = this.chatHubService.CreateChatHubUserClientModel(user);
                    await Clients.Group(room.Id.ToString()).SendAsync("RemoveUser", clientModel, room.Id.ToString());
                }

                await this.SendGroupNotification(string.Format("{0} disconnected from chat with client device {1}.", user.DisplayName, this.chatHubService.MakeStringAnonymous(Context.ConnectionId, 7, '*')), room.Id, Context.ConnectionId, user, ChatHubMessageType.Connect_Disconnect);

                await Groups.RemoveFromGroupAsync(Context.ConnectionId, room.Id.ToString());
            }

            if (!Context.User.HasClaim(ClaimTypes.Role, RoleNames.Registered) && !Context.User.HasClaim(ClaimTypes.Role, RoleNames.Admin) && !Context.User.HasClaim(ClaimTypes.Role, RoleNames.Host))
            {
                var roomsByCreator = this.chatHubRepository.GetChatHubRoomsByCreator(user.UserId);
                foreach (var room in await roomsByCreator.ToListAsync())
                {
                    room.Status = ChatHubRoomStatus.Archived.ToString();
                    this.chatHubRepository.UpdateChatHubRoom(room);
                }
            }

            var connection = await this.chatHubRepository.GetConnectionByConnectionId(Context.ConnectionId);

            connection.Status = Enum.GetName(typeof(ChatHubConnectionStatus), ChatHubConnectionStatus.Inactive);
            chatHubRepository.UpdateChatHubConnection(connection);

            ChatHubUser chatHubUserClientModel = this.chatHubService.CreateChatHubUserClientModel(user);
            await Clients.Clients(user.Connections.Select(item => item.ConnectionId)).SendAsync("OnUpdateConnectedUser", chatHubUserClientModel);

            await base.OnDisconnectedAsync(exception);
        }