public IBookshelfSession GetSession(HttpResponse response,string userName, string clientId,string userEmail) { var hashCode = GetSessionHashCode(userName, clientId); IBookshelfSession session; var sessionFound = _sessions.TryGetValue(hashCode, out session); if (sessionFound && session.IsExpired()) { //remove expired session - IsExpired removes expired session by it's call //esnure session not found workflow is going to be applied sessionFound = false; } //if there is no such session in storage, or there is but it's expired - create new one if (!sessionFound) { var userInfo = new InSessionUserInfo { UserEmail = userEmail, UserClientId = clientId, UserName = userName }; session = CreateServerSession(hashCode, userInfo,response); //check if there is proper active device alreadybeen created if (_cache.Get(userName) != null) { Dictionary<string, IBookshelfSession> deviceSessions = (Dictionary<string, IBookshelfSession>) _cache.Get(userName); if (!deviceSessions.ContainsKey(clientId)) { deviceSessions.Add(clientId, session); } } else { _cache.Set(userName, new Dictionary<string, IBookshelfSession> { { clientId, session } }); } } return session; }
private CustomServerSession CreateServerSession(int hashCode, InSessionUserInfo userInfo,HttpResponse response) { var newSession=new CustomServerSession(response, userInfo, hashCode, _sessionCookieName, _timeout, this); _sessions.Add(hashCode, newSession); return newSession; }