/// <summary> /// Gets an <see cref="ISession"/> associated with the specified session key. /// </summary> /// <param name="sessionKey">The session key</param> /// <returns>An <see cref="ISession"/> for quering the data store.</returns> public ISession GetSession(Guid sessionKey) { lock (syncRoot) { if (SessionStore.ContainsKey(sessionKey)) { // Re-initiate session if it is in an unusable state if (SessionStore[sessionKey] == null) { SessionStore[sessionKey] = SessionFactory.Instance.OpenSession(); } else if (SessionStore[sessionKey].IsOpen == false) { SessionStore[sessionKey].Dispose(); SessionStore[sessionKey] = SessionFactory.Instance.OpenSession(); } return(SessionStore[sessionKey]); } // Open new session, add it to SessionStore and return the session ISession session = SessionFactory.Instance.OpenSession(); SessionStore.Add(sessionKey, session); return(session); } }
private void TestBasicOptions() { const string fName = "test_fname"; const string lName = "test_lname"; var store = new SessionStore(); var key = Guid.NewGuid().ToString(); store.Add(Category, key, new TestData() { FirstName = fName, LastName = lName }); var storedVal = store.Get <TestData>(Category, key); Assert.IsNotNull(storedVal); Assert.IsTrue(fName.Equals(storedVal.FirstName), "First name did not match."); Assert.IsTrue(lName.Equals(storedVal.LastName), "Last name did not match."); store.Remove(Category, key); storedVal = store.Get <TestData>(Category, key); Assert.IsNull(storedVal); }
public Guid CreateNewSession(LaunchSession launchSession) { var session = new Session(launchSession); SessionStore.Add(session); session.StartApplication(); return(session.SessionId); }
private static string PutItemToExpire(int sizeInBytes) { var data = new byte[sizeInBytes]; for (var i = 0; i < sizeInBytes; i++) { data[i] = Convert.ToByte(i.ToString()[0]); } var store = new SessionStore(); var key = Guid.NewGuid().ToString(); store.Add(Category, key, new TestData() { FirstName = Encoding.UTF8.GetString(data) }, TimeSpan.FromMilliseconds(5)); return(key); }