Example #1
0
        public void Slide(bool async = false)
        {
            var prefix = GetSessionItemKey(string.Empty);
            var expire = UnlockedExtensions.GetNextTimeout(configuration.SessionTimeout);

            SlideInternal(prefix, expire, async);
        }
Example #2
0
        public void Abondon(bool async = false)
        {
            var key = GetSessionItemPrefix();

            DeleteStartsWith(key, async);
            UnlockedExtensions.EndSessionWithCustomCookie(configuration.CookieName);
        }
Example #3
0
        public bool Set(string key, object value, TimeSpan?expireTime = null, bool async = false)
        {
            var expire = expireTime.HasValue
                ? expireTime.Value
                : UnlockedExtensions.GetNextTimeout(configuration.SessionTimeout);
            var redisKey = GetSessionItemKey(key);
            var result   = SetInternal(redisKey, value, expire, async);

            return(result);
        }
Example #4
0
        public override void EndRequest(System.Web.HttpContext context)
        {
            if (UnlockedStateStoreConfiguration.Instance.Disabled)
            {
                return;
            }

            //var session = filterContext.HttpContext.GetContextItem(UNLOCKED_STATE_OBJECT_KEY);
            if (Store.Items.Count > 0)
            {
                //filterContext.StartSessionIfNew();
                //var store = (IUnlockedStateStore)filterContext.GetContextItem(UNLOCKED_STATE_STORE_KEY);
                // store.UpdateContext();
                var expire = UnlockedExtensions.GetNextTimeout(Store.Configuration.SessionTimeout);
                Store.Set(UnlockedExtensions.UNLOCKED_STATE_STORE_KEY, Store.Items, expire);
            }
            //base.EndRequest(context);
            //UnlockedStateStore.Dispose();
        }
Example #5
0
        protected object GetInternal(string key, bool slide = true, bool slideAsync = true, bool preferSlave = true)
        {
            var redisDatabase = GetRedisDatabase();
            var flag          = CommandFlags.None;

            if (preferSlave)
            {
                flag = CommandFlags.PreferSlave;
            }
            var data   = redisDatabase.StringGet(key, flag);
            var result = StateBinarySerializer.Deserialize(data);

            if (slide)
            {
                var expire = UnlockedExtensions.GetNextTimeout(configuration.SessionTimeout);
                var prefix = GetSessionItemPrefix();
                SlideInternal(prefix, expire, slideAsync);
            }
            return(result);
        }
        public void SaveTempData(ControllerContext controllerContext, IDictionary <string, object> values)
        {
            var cookieName = UnlockedStateStoreConfiguration.Instance.CookieName;

            if (values == null)
            {
                return;
            }
            if (values.Count == 0)
            {
                return;
            }
            var sessionId = controllerContext.GetSessionId(UnlockedStateStoreConfiguration.Instance.CookieName);

            if (!string.IsNullOrWhiteSpace(sessionId))
            {
                var key   = UnlockedExtensions.GetSessionItemKey(TEMP_DATA_PROVIDER_KEY, cookieName, sessionId);
                var store = new RedisUnlockedStateStore();
                store.Set(key, values);
            }
        }
        public IDictionary <string, object> LoadTempData(ControllerContext controllerContext)
        {
            var cookieName = UnlockedStateStoreConfiguration.Instance.CookieName;
            var result     = new Dictionary <string, object>(3);
            var sessionId  = controllerContext.GetSessionId(cookieName);

            if (!string.IsNullOrWhiteSpace(sessionId))
            {
                var key   = UnlockedExtensions.GetSessionItemKey(TEMP_DATA_PROVIDER_KEY, cookieName, sessionId);
                var store = new RedisUnlockedStateStore();
                var data  = (Dictionary <string, object>)store.Get(key);
                if (data != null && data.Count > 0)
                {
                    if (AutoRemove)
                    {
                        store.Delete(key);
                    }
                    result = data;
                }
            }
            return(result);
        }
Example #8
0
        protected string GetSessionItemPrefix()
        {
            var prefix = UnlockedExtensions.GetSessionItemKey(string.Empty, configuration.CookieName);

            return(prefix);
        }
Example #9
0
        protected string GetSessionItemKey(string keyName)
        {
            var redisKey = UnlockedExtensions.GetSessionItemKey(keyName, configuration.CookieName);

            return(redisKey);
        }