Beispiel #1
0
        public async Task <bool> RemoveUserMappingByConnectionId(string connectionId)
        {
            var result = false;

            try
            {
                var guidUserId = new Guid(connLookup.GetUserFromConnection(connectionId));
                if (proxyLookup.ContainsKey(guidUserId))
                {
                    var proxy = proxyLookup[guidUserId];
                    ActorEventHandler evenHandler = eventHandlerLookup[guidUserId];
                    await proxy.UnsubscribeAsync <IUserEvent>(evenHandler);

                    IUser             removedActor;
                    ActorEventHandler removedEventHandler;
                    proxyLookup.TryRemove(guidUserId, out removedActor);
                    eventHandlerLookup.TryRemove(guidUserId, out removedEventHandler);
                }
                result = connLookup.RemoveConnection(connectionId);
            }
            catch (Exception e)
            {
                e.Log();
            }
            return(result);
        }
Beispiel #2
0
        public async Task <bool> AddUserMapping(string userId, string connectionId)
        {
            var result = false;

            try
            {
                Guid guidUserId = new Guid(userId);
                if (!proxyLookup.ContainsKey(guidUserId))
                {
                    var eventHandler = new ActorEventHandler(userId);
                    proxyLookup.TryAdd(guidUserId, guidUserId.ToActorId().Proxy <IUser>());
                    eventHandlerLookup.TryAdd(guidUserId, eventHandler);
                    await proxyLookup[guidUserId].SubscribeAsync(eventHandler, TimeSpan.FromSeconds(30));
                }
                result = connLookup.AddConnection(userId, connectionId);
            }
            catch (Exception e)
            {
                e.Log();
            }
            return(result);
        }