public RedisASPSessionVariantDictionary Init(RedisASPSessionStateProvider sessionProvider, SessionStateStoreData storeData, string sessionId, int expiry) { //PFSession.Log.Debug($"PFRedisVariantDictionary:Init:{hashkey}"); //System.IO.File.AppendAllText(@"C:\\log files\\pfsession.log", $"PFRedisVariantDictionary:Init:{hashkey}"); this.sessionId = sessionId; this.sessionProvider = sessionProvider; this.storeData = storeData; return this; }
/// <summary> /// Try to retrive the existing session data from Redis /// If the data is not found, it will create a new session with a new sessionId /// </summary> private void InitSession() { // If sessionProvider is not null that means we already initialized the session and got the dataStore if (_sessionProvider == null) { _sessionProvider = new RedisASPSessionStateProvider(); } _storeData = null; // Get write lock and session from cache bool locked; TimeSpan lockAge; object lockId; SessionStateActions actions; if (!string.IsNullOrWhiteSpace(_sessionId)) { // Try Retrieve the existing session _storeData = _sessionProvider.GetItem(null, _sessionId, out locked, out lockAge, out lockId, out actions); } // If we cannot find an existing session we will create a new one if (_storeData == null) { // Generate a new session id SessionIDManager Manager = new SessionIDManager(); _sessionId = Manager.CreateSessionID(_context); // Create a new Session in Redis _sessionTimeout = (int)RedisSessionStateProvider.configuration.SessionTimeout.TotalMinutes; _sessionProvider.CreateUninitializedItem(null, _sessionId, _sessionTimeout); // Get the store Data from the new session created _storeData = _sessionProvider.GetItem(null, _sessionId, out locked, out lockAge, out lockId, out actions); // If for some reason it failed to get the store data we raise an exception if (_storeData == null) { throw new InvalidOperationException("Store Data cannot be created"); } } }