MongoDB.Web.Providers.MongoDBSessionStateProvider.ReleaseItemExclusive C# (CSharp) Method

ReleaseItemExclusive() public method

public ReleaseItemExclusive ( HttpContext context, string id, object lockId ) : void
context System.Web.HttpContext
id string
lockId object
return void
        public override void ReleaseItemExclusive(HttpContext context, string id, object lockId)
        {
            var query = Query.And(Query.EQ("applicationVirtualPath", HostingEnvironment.ApplicationVirtualPath), Query.EQ("id", id), Query.EQ("lockId", lockId.ToString()));
            var update = Update.Set("expires", DateTime.Now.Add(sessionStateSection.Timeout)).Set("locked", false);
            this.mongoCollection.Update(query, update);
        }

Usage Example

Ejemplo n.º 1
0
		/// <summary>
		/// Method that creates a new session using the provider supplied.  This method
		/// also verifies that the session was created, then modifies the session, then
		/// deletes the session and verifies deletion from the store and the memory cache
		/// in the provider.
		/// </summary>
		/// <param name="provider">The MongoDB provider to use for the test.</param>
		private void VerifySessionPersistence(MongoDBSessionStateProvider provider)
		{
			string itemName = "DummyItem";
			string itemValue = "Value";

			HttpRequest request = null;
			HttpResponse response = null;
			HttpContext context = GetContext(out request, out response);

			TestContext.WriteLine("Creating Store Data");
			var dataStore = provider.CreateNewStoreData(context, (_TimeoutInSeconds / 60));
			dataStore.Items[itemName] = itemValue;

			var sessionId = _SessionIdManager.CreateSessionID(context);

			TestContext.WriteLine("Writing Store Data");
			provider.SetAndReleaseItemExclusive(context, sessionId, dataStore, null, true);

			System.Threading.Thread.Sleep(2000);

			bool locked;
			TimeSpan lockAge;
			object lockId;
			System.Web.SessionState.SessionStateActions actions;

			TestContext.WriteLine("Retrieving new Store Data");
			var retrievedDataStore = provider.GetItemExclusive(context, sessionId, out locked, out lockAge, out lockId, out actions);

			if (retrievedDataStore == null || retrievedDataStore.Items.Count == 0)
			{
				Assert.Fail("Retrieved data store does not contain session data");
			}

			TestContext.WriteLine("Testing Store Data");
			var dummyValue = retrievedDataStore.Items[itemName];
			Assert.AreEqual(itemValue, dummyValue);

			itemValue = "NewValue";
			retrievedDataStore.Items[itemName] = itemValue;

			TestContext.WriteLine("Updating Store Data");
			provider.SetAndReleaseItemExclusive(context, sessionId, retrievedDataStore, lockId, false);

			System.Threading.Thread.Sleep(2000);

			var retrievedDataStore2 = provider.GetItemExclusive(context, sessionId, out locked, out lockAge, out lockId, out actions);
			if (retrievedDataStore2 == null || retrievedDataStore2.Items.Count == 0)
			{
				Assert.Fail("Retrieved data store does not contain session data");
			}

			TestContext.WriteLine("Testing Store Data");
			Assert.AreEqual(itemValue, retrievedDataStore2.Items[itemName]);

			TestContext.WriteLine("Releasing Store Data");
			provider.ReleaseItemExclusive(context, sessionId, lockId);

			System.Threading.Thread.Sleep(2000);

			retrievedDataStore2 = provider.GetItemExclusive(context, sessionId, out locked, out lockAge, out lockId, out actions);
			TestContext.WriteLine("Deleting Store Data");
			provider.RemoveItem(context, sessionId, lockId, retrievedDataStore2);

			System.Threading.Thread.Sleep(2000);

			TestContext.WriteLine("Ensuring store was deleted");
			var retrievedDataStore3 = provider.GetItem(context, sessionId, out locked, out lockAge, out lockId, out actions);
			Assert.IsNull(retrievedDataStore3);

			System.Threading.Thread.Sleep(2000);

			TestContext.WriteLine("Ensuring cache is empty");
			ISessionStateData sessionStateDataFromCache = null;
			bool sessionExistsInCache = CheckSessionExistsInCache(provider, sessionId, out sessionStateDataFromCache);
			if (sessionExistsInCache)
			{
				Assert.Fail("Session should have been removed but still exists in cache");
			}

			TestContext.WriteLine("Success");
		}
All Usage Examples Of MongoDB.Web.Providers.MongoDBSessionStateProvider::ReleaseItemExclusive