Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public async Task InitUser(long userId)
        {
            var oneClient = _onlineClientManager.GetByConnectionIdOrNull(Context.ConnectionId);

            if (oneClient != null)
            {
                _onlineClientManager.Remove(Context.ConnectionId);
                var newclient = CreateClientForCurrentConnection(userId);
                _onlineClientManager.Add(newclient);
            }
            else
            {
            }
            //await Clients.All.InvokeAsync("NoticeOnline", $"用户组数据更新完成,新增id为:{Context.ConnectionId}userId:{userId}");
        }
Esempio n. 2
0
        public void Test_All()
        {
            int tenantId = 1;

            Dictionary <string, int> connections = new Dictionary <string, int>();

            for (int i = 0; i < 100; i++)
            {
                connections.Add(MakeNewConnectionId(), i + 1);
            }

            foreach (var pair in connections)
            {
                _clientManager.Add(new OnlineClient(pair.Key, "127.0.0.1", tenantId, pair.Value));
            }

            var testId = connections.Keys.ToList()[5];

            _clientManager.GetAllClients().Count.ShouldBe(connections.Count);
            _clientManager.GetAllByUserId(new UserIdentifier(tenantId, connections[testId])).Count.ShouldBe(1);
            _clientManager.GetByConnectionIdOrNull(testId).ShouldNotBeNull();
            _clientManager.Remove(testId).ShouldBeTrue();
            _clientManager.GetAllClients().Count.ShouldBe(connections.Count - 1);
            _clientManager.GetByConnectionIdOrNull(testId).ShouldBeNull();
            _clientManager.GetAllByUserId(new UserIdentifier(tenantId, connections[testId])).Count.ShouldBe(0);
        }
        public static bool Remove(
            [NotNull] this IOnlineClientManager onlineClientManager,
            [NotNull] IOnlineClient client)
        {
            Check.NotNull(onlineClientManager, nameof(onlineClientManager));
            Check.NotNull(client, nameof(client));

            return(onlineClientManager.Remove(client.ConnectionId));
        }
Esempio n. 4
0
        public override async Task OnDisconnectedAsync(Exception exception)
        {
            await base.OnDisconnectedAsync(exception);

            try
            {
                mOnlineClientManager.Remove(Context.ConnectionId);
            }
            catch
            {
            }
        }
Esempio n. 5
0
        public async override Task OnDisconnected(bool stopCalled)
        {
            await base.OnDisconnected(stopCalled);

            try
            {
                _onlineClientManager.Remove(Context.ConnectionId);
            }
            catch (Exception ex)
            {
                Logger.Warn(ex.ToString(), ex);
            }
        }
Esempio n. 6
0
        public override async Task OnDisconnectedAsync(Exception exception)
        {
            await base.OnDisconnectedAsync(exception);

            Logger.Debug("A client is disconnected: " + Context.ConnectionId);

            try
            {
                _onlineClientManager.Remove(Context.ConnectionId);
            }
            catch (Exception ex)
            {
                Logger.Warn(ex.ToString(), ex);
            }
        }
Esempio n. 7
0
 public static bool Remove(this IOnlineClientManager onlineClientManager, IOnlineClient client)
 {
     return(onlineClientManager.Remove(client.ConnectionId));
 }