コード例 #1
0
        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);
            }
        }
コード例 #2
0
        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);
        }
コード例 #3
0
 public override void ResetItemTimeout(HttpContext context, string id)
 {
     using (SqlStore store = GetStore())
     {
         store.ExecuteResetItemTimeout(id);
     }
 }
コード例 #4
0
        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);
        }
コード例 #5
0
        private static SqlStore TryGetFromPool()
        {
            SqlStore store = null;

            s_pool.TryPop(out store);

            return(store);
        }
コード例 #6
0
        public override void RemoveItem(HttpContext context, string id, object lockId, SessionStateStoreData item)
        {
            int lockCookie = (int)lockId;

            using (SqlStore store = GetStore())
            {
                store.ExecuteRemoveItem(id, lockCookie);
            }
        }
コード例 #7
0
        public override void ReleaseItemExclusive(HttpContext context, string id, object lockId)
        {
            int lockCookie = (int)lockId;

            using (SqlStore store = GetStore())
            {
                store.ExecuteReleaseItemExclusive(id, lockCookie);
            }
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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);
            }
        }
コード例 #10
0
 private SqlStore GetStore()
 {
     return(SqlStore.GetOrCreate(s_connectionString, CanUsePooling()));
 }