public override void SetAndReleaseItemExclusive(HttpContext context, string id, SessionStateStoreData item, object lockId, bool newItem) { byte[] buffer; long itemLength; int lockCookie = (lockId == null) ? 0 : (int)lockId; try { Serialization.Serialize(item, s_compressionEnabled, out buffer, out itemLength); } catch { if (!newItem) { // Release the exclusiveness of the existing item. ((SessionStateStoreProviderBase)this).ReleaseItemExclusive(context, id, lockId); } throw; } using (SqlStore store = GetStore()) { const bool initialized = true; store.ExecuteInsertOrUpdateItem(id, TimeSpan.FromMinutes(item.Timeout), lockCookie, newItem, initialized, buffer, itemLength); } }
private SessionStateStoreData GetItem(HttpContext context, string id, bool exclusive, out bool locked, out TimeSpan lockAge, out object lockId, out SessionStateActions actions) { byte[] buffer; long itemLength; bool requiresInitialization; SessionStateStoreData item = null; using (SqlStore store = GetStore()) { int lockCookie; store.ExecuteGetItem(id, exclusive, out buffer, out itemLength, out locked, out lockAge, out lockCookie, out requiresInitialization); lockId = lockCookie; } if (requiresInitialization) { actions = SessionStateActions.InitializeItem; } else { actions = SessionStateActions.None; } if (buffer != null) { using (MemoryStream stream = new MemoryStream(buffer, 0, checked ((int)itemLength), false)) { item = Serialization.Deserialize(context, stream, s_compressionEnabled); } } return(item); }
public override void ResetItemTimeout(HttpContext context, string id) { using (SqlStore store = GetStore()) { store.ExecuteResetItemTimeout(id); } }
public static SqlStore GetOrCreate(string connectionString, bool usePooling) { SqlStore store = null; if (usePooling) { store = TryGetFromPool(); if (store != null && (store.sqlConnection.State & ConnectionState.Open) == 0) { store.usePooling = false; store.Dispose(); store = null; } } if (store == null) { store = new SqlStore(connectionString); } store.usePooling = usePooling; return(store); }
private static SqlStore TryGetFromPool() { SqlStore store = null; s_pool.TryPop(out store); return(store); }
public override void RemoveItem(HttpContext context, string id, object lockId, SessionStateStoreData item) { int lockCookie = (int)lockId; using (SqlStore store = GetStore()) { store.ExecuteRemoveItem(id, lockCookie); } }
public override void ReleaseItemExclusive(HttpContext context, string id, object lockId) { int lockCookie = (int)lockId; using (SqlStore store = GetStore()) { store.ExecuteReleaseItemExclusive(id, lockCookie); } }
private static bool TryReturnToPool(SqlStore store) { int extimatedCount = s_pool.Count; if (extimatedCount < s_poolMax) { store.poolTickCount = Environment.TickCount; s_pool.Push(store); return(true); } return(false); }
public override void CreateUninitializedItem(HttpContext context, string id, int timeout) { byte[] buffer; long itemLength; SessionStateStoreData item = CreateNewStoreData(context, timeout); Serialization.Serialize(item, s_compressionEnabled, out buffer, out itemLength); using (SqlStore store = GetStore()) { const bool newItem = true; const bool initialized = false; store.ExecuteInsertOrUpdateItem(id, TimeSpan.FromMinutes(item.Timeout), 0, newItem, initialized, buffer, itemLength); } }
private SqlStore GetStore() { return(SqlStore.GetOrCreate(s_connectionString, CanUsePooling())); }