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)); }
private async void IsUserIdle(CurrentlyUsedWebPageRepository repo, string connectionId) { await Task.Delay(_userIdleTime); CurrentlyUsedWebPage userTrace = _repo.GetAllWebPages().SingleOrDefault(x => x.ConnectionId == new Guid(connectionId)); if (userTrace != null) { _repo.DeletePage(connectionId); // blast the inactivity notif Update(userTrace, 3); } }
public IHttpActionResult StoreNewPages(CurrentlyUsedWebPage data) { try { _repoWebPage.InsertPage(data); SalesHub hub = new SalesHub(); hub.Update(data, 1); return(Ok()); } catch (Exception ex) { return(InternalServerError(ex)); } }
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); } }
public void Update(CurrentlyUsedWebPage data, int type) { IHubContext context = GlobalHost.ConnectionManager.GetHubContext <SalesHub>(); context.Clients.All.updatePages(data, type); }