Пример #1
0
        public override Task OnDisconnected(bool stopCalled)
        {
            CurrentlyUsedWebPage userTrace = _repo.GetAllWebPages().SingleOrDefault(x => x.ConnectionId == new Guid(Context.ConnectionId));
            // try to delete if user has not reconnected
            Task mytask = Task.Run(() =>
            {
                UserDisconnected(userTrace, _repo, Context.ConnectionId);
            });

            return(base.OnDisconnected(stopCalled));
        }
Пример #2
0
        private async void UserDisconnected(CurrentlyUsedWebPage userTrace, CurrentlyUsedWebPageRepository repo, string connectionId)
        {
            // copy userTrace to local var, this gets disposed by CLR after some time.
            var localUserTrace = userTrace;
            await Task.Delay(_userTimeToLive);

            // make sure localtrace isn't null
            if (localUserTrace == null)
            {
                return;
            }

            // check db if a connection still exist
            bool hasUserReconnected = repo.GetAllWebPages().Any(x => x.User == localUserTrace.User &&
                                                                x.Url == localUserTrace.Url && x.ConnectionId != new Guid(connectionId));


            // delete if disconnected
            if (!hasUserReconnected)
            {
                repo.DeletePage(connectionId);
                Update(userTrace, 4);
            }
        }