Пример #1
0
        public override async Task OnConnectedAsync()
        {
            _currentAccount = getAccount(Context);
            SignalRAccount exists = _ConnectingAccounts.Where(p => p.PersonId == _currentAccount.PersonId).FirstOrDefault();

            if (exists == null)
            {
                _ConnectingAccounts.Add(_currentAccount);
            }
            await base.OnConnectedAsync();
        }
Пример #2
0
        public override async Task OnDisconnectedAsync(Exception exception)
        {
            _currentAccount = getAccount(Context);
            SignalRAccount exists = _ConnectingAccounts.Where(p => p.PersonId == _currentAccount.PersonId).FirstOrDefault();

            if (exists != null)
            {
                _ConnectingAccounts.Remove(exists);
            }
            await base.OnDisconnectedAsync(exception);
        }
Пример #3
0
        private SignalRAccount getAccount(HubCallerContext context)
        {
            string personId = string.Empty;

            personId = context.GetHttpContext().Request.Query["personId"].ToString();
            SignalRAccount account = new SignalRAccount()
            {
                PersonId     = personId,
                ConnectionId = context.ConnectionId
            };

            return(account);
        }
Пример #4
0
        private IReadOnlyList <string> GetConnectionIdsFromPersonIds(string[] personIds)
        {
            List <string> Ids = new List <string>();

            for (int i = 0; i < personIds.Length; i++)
            {
                SignalRAccount signalRAccount = _ConnectingAccounts.Where(p => p.PersonId == personIds[i]).FirstOrDefault();
                if (signalRAccount != null)
                {
                    Ids.Add(signalRAccount.ConnectionId);
                }
            }
            return(Ids);
        }
Пример #5
0
        public override async Task OnDisconnectedAsync(Exception exception)
        {
            AccountModel accountModel = new AccountModel(Context.GetHttpContext().GetUserInfo());

            if (accountModel != null)
            {
                _currentAccount = AutoMapper.Mapper.Map <SignalRAccount>(accountModel.Account);
                _currentAccount.ConnectionId = Context.ConnectionId;
                SignalRAccount exists = _ConnectingAccounts.Where(p => p.PersonId == _currentAccount.PersonId).FirstOrDefault();
                if (exists != null)
                {
                    _ConnectingAccounts.Remove(exists);
                }
            }
            await base.OnDisconnectedAsync(exception);
        }