Beispiel #1
0
        public void Connect(string userId)
        {
            var curConnectionId = Context.ConnectionId;

            //this.Init();

            // case: user not connected yet
            if(ConnectedUsers.Count(u => u.ConnectionId == curConnectionId) == 0)
            //if (!this._chatRepository.IsConnected(ConnectedUsers, curConnectionId))
            {
                // add new user connected
                var newUserConnected = new UserChatViewModel { ConnectionId = curConnectionId, UserId = userId };
                ConnectedUsers.Add(newUserConnected);

                // init fields
                this.Init();

                // send to all except caller client
                Clients.AllExcept(this._curConnectionId).onNewUserConnected(userId);

                // send to friend list online
                var friendListId_OnLine = this._chatRepository.GetFriendListId_Online(this._friendListOnline);
                Clients.Caller.onConnected(friendListId_OnLine);
            }
        }
Beispiel #2
0
        public void Init()
        {
            // init repository
            this._dbContext = new ApplicationDbContext();
            this._chatRepository = new ChatRepository(this._dbContext);
            this._friendRepository = new FriendRepository(this._dbContext);
            this._privateMessageRepository = new PrivateMessageRepository(this._dbContext);

            this._statusRepository = new StatusRepository(this._dbContext);
            this._statusMessageRepository = new StatusMessageRepository(this._dbContext);
            this._statusLocationRepository = new StatusLocationRepository(this._dbContext);
            this._statusImageRepository = new StatusImageRepository(this._dbContext);

            this._likeRepository = new LikeRepository(this._dbContext);
            this._shareRepository = new ShareRepository(this._dbContext);
            this._commentRepository = new CommentRepository(this._dbContext);

            this._newFeedRepository = new NewFeedsRepository(this._dbContext);

            // get current connectionId
            this._curConnectionId = this.Context.ConnectionId;

            // get chatViewModel of User via connectionId
            this._curUserChat = this._chatRepository.GetUserByConnectionId(ConnectedUsers, this.Context.ConnectionId);

            // get friendListId
            this._friendListId = this._friendRepository.GetFriendListId(this._curUserChat.UserId).ToList();

            // get friendListOnline
            this._friendListOnline = this._chatRepository.GetFriendListOnline(ConnectedUsers, this._friendListId, this._curUserChat.UserId);

            // get friendListConnectionId
            this._friendListConnectionId_Online = this._chatRepository.GetFriendList_ConnectionId(this._friendListOnline);

            this._allUserRelate_ConnectionId = this._chatRepository.GetAllUserRelate_ConnectionId(this._friendListConnectionId_Online, this._curUserChat.ConnectionId);
        }
 public void RemoveUserConnected(List<UserChatViewModel> connectedUsers, UserChatViewModel user)
 {
     connectedUsers.Remove(user);
 }