示例#1
0
        /**<summary>
         * Inserts item in store.
         * When an items expires, its automatically been removed from cache, so we do not have
         * to check the expiration time, and simply an Insert call to cache will add the items if
         * its new or updates the item if it already exists, so newItem parameter is also useless
         * </summary>**/
        public override void SetAndReleaseItemExclusive(HttpContext context, string id, SessionStateStoreData items, object lockID, bool newItem)
        {
            try
            {
                PutInNCache(id, InsertContents(context, items, SessionStateActions.None, items.Timeout), lockID, true);
            }
            catch (Exception)
            {
                try
                {
                    if (_cache != null)
                    {
                        _cache.Remove(GetUniqueSessionId(id), true);
                    }
                }
                catch (Exception ex)
                {
                    if (_detailedLogs)
                    {
                        NCacheLog.Debug("SetAndReleaseItemExclusive failed ( " + id + "). Exception = " + ex.ToString());
                    }
                }

                try
                {
                    PutInNCache(id, InsertContents(context, items, SessionStateActions.None, items.Timeout), lockID, false);
                }
                catch (Exception exc)
                {
                    RaiseException(exc, id);
                }
            }
        }
示例#2
0
 private bool ReleaseSessionItemLock(string sessionid, object lockID)
 {
     try
     {
         _cache.Unlock(GetUniqueSessionId(sessionid));//, lockID);
         return(true);
     }
     catch (Exception)
     {
         try
         {
             _cache.Unlock(GetUniqueSessionId(sessionid));
             return(true);
         }
         catch (Exception e)
         {
             if (_detailedLogs)
             {
                 NCacheLog.Debug("ReleaseSessionItemLock failed ( " + sessionid + "). Exception = " + e.ToString());
             }
             RaiseException(e, sessionid);
         }
     }
     return(false);
 }
示例#3
0
        public override SessionStateStoreData CreateNewStoreData(HttpContext context, int timeOut)
        {
            SessionStateStoreData data = new SessionStateStoreData(new SessionStateItemCollection(),
                                                                   SessionStateUtility.GetSessionStaticObjects(context),
                                                                   timeOut);

            if (_detailedLogs)
            {
                NCacheLog.Debug("New data object created to be used for current request");
            }

            return(data);
        }
示例#4
0
 public void LogDebug(string message, string sessionID)
 {
     try
     {
         if (sessionID == null)
         {
             sessionID = "";
         }
         if (NCacheLog != null)
         {
             NCacheLog.Debug("[Debug]", sessionID + " :" + message);
         }
     }
     catch (Exception ex)
     {
         LogError(ex, sessionID);
     }
 }
示例#5
0
        public override void CreateUninitializedItem(HttpContext context, string id, int timeOut)
        {
            try
            {
                _cache.IsSessionCookieless = IsSessionCookieless(HttpContext.Current);
                PutInNCache(id, InsertContents(context, null, SessionInitializationActions.InitializeItem, timeOut), null, true);
                if (_detailedLogs)
                {
                    NCacheLog.Debug(id + " :new session added to cache.");
                }
            }
            catch (Exception)
            {
                try
                {
                    if (_cache != null)
                    {
                        string locationID = GetLocationID(context, id);
                        _cache.Remove(locationID, GetUniqueSessionId(id), false);
                    }
                }
                catch (Exception)
                {
                }

                try
                {
                    if (_isLocationAffinityEnabled)
                    {
                        UpdateCookies(context);
                    }

                    PutInNCache(id, InsertContents(context, null, SessionInitializationActions.InitializeItem, timeOut), null, false);
                    if (_detailedLogs)
                    {
                        NCacheLog.Debug(id + " :new session added to cache.");
                    }
                }
                catch (Exception exc)
                {
                    RaiseException(exc, id);
                }
            }
        }
示例#6
0
        /**<summary>
         * Inserts item in store.
         * When an items expires, its automatically been removed from cache, so we do not have
         * to check the expiration time, and simply an Insert call to cache will add the items if
         * its new or updates the item if it already exists, so newItem parameter is also useless
         * </summary>**/
        public override void SetAndReleaseItemExclusive(HttpContext context, string id, SessionStateStoreData items, object lockID, bool newItem)
        {
            try
            {
                _cache.IsSessionCookieless = IsSessionCookieless(HttpContext.Current);
                PutInNCache(id, InsertContents(context, items, SessionInitializationActions.None, items.Timeout), lockID, true);
            }
            catch (Exception)
            {
                try
                {
                    if (_cache != null)
                    {
                        string locationID = GetLocationID(context, id);
                        _cache.Remove(locationID, GetUniqueSessionId(id), true);
                    }
                }
                catch (Exception ex)
                {
                    if (_detailedLogs)
                    {
                        NCacheLog.Debug("SetAndReleaseItemExclusive failed ( " + id + "). Exception = " + ex.ToString());
                    }
                }

                try
                {
                    if (_isLocationAffinityEnabled)
                    {
                        UpdateCookies(context);
                    }

                    PutInNCache(id, InsertContents(context, items, SessionInitializationActions.None, items.Timeout), lockID, false);
                }
                catch (Exception exc)
                {
                    RaiseException(exc, id);
                }
            }
        }
示例#7
0
        private bool ReleaseSessionItemLock(string sessionid, object lockID)
        {
            string locationID = sessionid;

            try
            {
                if (_isLocationAffinityEnabled)
                {
                    locationID = GetLocationID(HttpContext.Current, locationID);
                }
                _cache.Unlock(locationID, GetUniqueSessionId(sessionid));//, lockID);
                return(true);
            }
            catch (Exception)
            {
                try
                {
                    _cache.Unlock(locationID, GetUniqueSessionId(sessionid));
                    return(true);
                }
                catch (Exception e)
                {
                    if (_detailedLogs)
                    {
                        NCacheLog.Debug("ReleaseSessionItemLock failed ( " + sessionid + "). Exception = " + e.ToString());
                    }
                    if (_isLocationAffinityEnabled)
                    {
                        UpdateCookies(HttpContext.Current);
                        return(true);
                    }
                    else
                    {
                        RaiseException(e, sessionid);
                    }
                }
            }
            return(false);
        }
示例#8
0
        public override void CreateUninitializedItem(HttpContext context, string id, int timeOut)
        {
            try
            {
                PutInNCache(id, InsertContents(context, null, SessionStateActions.InitializeItem, timeOut), null, true);
                if (_detailedLogs)
                {
                    NCacheLog.Debug(id + " :new session added to cache.");
                }
            }
            catch (Exception)
            {
                try
                {
                    if (_cache != null)
                    {
                        _cache.Remove(GetUniqueSessionId(id), false);
                    }
                }
                catch (Exception)
                {
                }

                try
                {
                    PutInNCache(id, InsertContents(context, null, SessionStateActions.InitializeItem, timeOut), null, false);
                    if (_detailedLogs)
                    {
                        NCacheLog.Debug(id + " :new session added to cache.");
                    }
                }
                catch (Exception exc)
                {
                    RaiseException(exc, id);
                }
            }
        }
示例#9
0
        public override void RemoveItem(HttpContext context, string id, object lockID, SessionStateStoreData item)
        {
            try
            {
                if (_cache != null)
                {
                    lock (_cache)
                    {
                        bool removeFromCache = true;
                        if (lockID is LockHandle)
                        {
                            removeFromCache = (((LockHandle)lockID).LockId != null);
                        }

                        if (removeFromCache)
                        {
                            if (_lockSessions)
                            {
                                _cache.Remove(GetUniqueSessionId(id), lockID as LockHandle, true);
                            }
                            else
                            {
                                _cache.Remove(GetUniqueSessionId(id), true);
                            }
                        }
                    }
                }
                if (_detailedLogs)
                {
                    NCacheLog.Debug(id + " :session removed from cache");
                }
            }
            catch (Exception)
            {
                try
                {
                    if (_cache != null)
                    {
                        lock (_cache)
                        {
                            if (_lockSessions)
                            {
                                _cache.Remove(GetUniqueSessionId(id), lockID as LockHandle, false);
                            }
                            else
                            {
                                _cache.Remove(GetUniqueSessionId(id), false);
                            }
                        }
                    }

                    if (_detailedLogs)
                    {
                        NCacheLog.Debug(id + " :session removed from cache");
                    }
                }
                catch (Exception exc)
                {
                    if (_detailedLogs)
                    {
                        NCacheLog.Debug("RemoveItem failed( " + id + "). Exception = " + exc.ToString());
                    }
                    RaiseException(exc, id);
                }
            }
        }
示例#10
0
        public override void RemoveItem(HttpContext context, string id, object lockID, SessionStateStoreData item)
        {
            try
            {
                _cache.IsSessionCookieless = IsSessionCookieless(HttpContext.Current);
                if (_cache != null)
                {
                    string locationID = GetLocationID(context, id);

                    lock (_cache)
                    {
                        bool removeFromCache = true;
                        if (lockID is LockHandle)
                        {
                            removeFromCache = (((LockHandle)lockID).LockId != null);
                        }

                        if (removeFromCache)
                        {
                            if (_lockSessions)
                            {
                                _cache.Remove(locationID, GetUniqueSessionId(id), lockID as LockHandle, true);
                            }
                            else
                            {
                                _cache.Remove(locationID, GetUniqueSessionId(id), true);
                            }
                        }
                    }
                }
                if (_detailedLogs)
                {
                    NCacheLog.Debug(id + " :session removed from cache");
                }
            }
            catch (Exception)
            {
                try
                {
                    if (_cache != null)
                    {
                        string locationID = GetLocationID(context, id);

                        lock (_cache)
                        {
                            if (_lockSessions)
                            {
                                _cache.Remove(locationID, GetUniqueSessionId(id), lockID as LockHandle, false);
                            }
                            else
                            {
                                _cache.Remove(locationID, GetUniqueSessionId(id), false);
                            }
                        }
                    }

                    if (_detailedLogs)
                    {
                        NCacheLog.Debug(id + " :session removed from cache");
                    }
                }
                catch (Exception exc)
                {
                    if (_detailedLogs)
                    {
                        NCacheLog.Debug("RemoveItem failed( " + id + "). Exception = " + exc.ToString());
                    }
                    if (_isLocationAffinityEnabled)
                    {
                        UpdateCookies(context);
                    }
                    else
                    {
                        RaiseException(exc, id);
                    }
                }
            }
        }