Exemplo n.º 1
0
        public HubCallerContext TryGetHubCallerContext(ScopedClientKey scopedClientKey)
        {
            var oneKey = scopedClientKey.ToOneKey();

            ScopedContexts.TryGetValue(oneKey, out var theOne);
            return(theOne);
        }
Exemplo n.º 2
0
        private async Task KickSameScopedClient(Hub hub, HubCallerContext oldClientHub, ScopedClientKey scopedClientKey)
        {
            if (oldClientHub == null)
            {
                return;
            }

            //already exist, should kick!
            var oldConnectionId = oldClientHub.ConnectionId;
            var theConn         = _repository.GetScopedConnection(oldConnectionId);

            if (theConn != null)
            {
                var clientProxy = hub.Clients.Client(oldConnectionId);
                if (clientProxy != null)
                {
                    var scopedConnections = _repository.GetScopedConnections(scopedClientKey.ScopeGroupId);
                    var connections       = scopedConnections.OrderBy(x => x.CreateAt).ToList();
                    var theOne            = connections.SingleOrDefault(x => x.ConnectionId.Equals(oldConnectionId));
                    if (theOne != null)
                    {
                        var oneKey  = scopedClientKey.ToOneKey();
                        var message = string.Format("{0} is kicked by another same scoped client!", oneKey);
                        theOne.Desc = message;
                    }
                    await clientProxy.SendAsync(ScopedConst.ForClient.ScopedConnectionsUpdated(), connections).ConfigureAwait(false);
                }
            }
            _repository.RemoveScopedConnection(oldConnectionId);
            oldClientHub.Abort();
        }