public List<object> GetNewItemsAsList(ChangeTrackingSessionStateItemCollection sessionItems)
 {
     List<object> list = new List<object>(sessionItems.Keys.Count * 2);
     foreach (string key in sessionItems.Keys)
     {
         list.Add(key);
         list.Add(GetBytesFromObject(sessionItems[key]));
     }
     return list;
 }
 public int AppendRemoveItemsInList(ChangeTrackingSessionStateItemCollection sessionItems, List<object> list)
 {
     int noOfItemsRemoved = 0;
     if (sessionItems.GetDeletedKeys() != null && sessionItems.GetDeletedKeys().Count != 0)
     {
         foreach (string delKey in sessionItems.GetDeletedKeys())
         {
             list.Add(delKey);
             noOfItemsRemoved++;
         }
     }
     return noOfItemsRemoved;
 }
 public int AppendUpdatedOrNewItemsInList(ChangeTrackingSessionStateItemCollection sessionItems, List<object> list)
 {
     int noOfItemsUpdated = 0;
     if (sessionItems.GetModifiedKeys() != null && sessionItems.GetModifiedKeys().Count != 0)
     {
         foreach (string key in sessionItems.GetModifiedKeys())
         {
             list.Add(key);
             list.Add(GetBytesFromObject(sessionItems[key]));
             noOfItemsUpdated++;
         }
     }
     return noOfItemsUpdated;
 }
Exemple #4
0
 private bool SetPrepare(ISessionStateItemCollection data, int sessionTimeout, out string[] keyArgs, out object[] valueArgs)
 {
     keyArgs   = null;
     valueArgs = null;
     if (data != null && data.Count > 0)
     {
         ChangeTrackingSessionStateItemCollection sessionItems = (ChangeTrackingSessionStateItemCollection)data;
         List <object> list = RedisUtility.GetNewItemsAsList(sessionItems);
         if (list.Count > 0)
         {
             keyArgs      = new string[] { Keys.DataKey, Keys.InternalKey };
             valueArgs    = new object[list.Count + 2]; // this +2 is for first 2 values in ARGV that we will add now
             valueArgs[0] = list.Count + 2;
             valueArgs[1] = sessionTimeout;
             list.CopyTo(valueArgs, 2);
             return(true);
         }
     }
     return(false);
 }
Exemple #5
0
 public override void CreateUninitializedItem(HttpContext context, string id, int timeout)
 {
     try
     {
         if (LastException == null)
         {
             LogUtility.LogInfo("CreateUninitializedItem => Session Id: {0}, Session provider object: {1}.", id, this.GetHashCode());
             ISessionStateItemCollection sessionData = new ChangeTrackingSessionStateItemCollection();
             sessionData["SessionStateActions"] = SessionStateActions.InitializeItem;
             GetAccessToStore(id);
             // Converting timout from min to sec
             cache.Set(sessionData, (timeout * FROM_MIN_TO_SEC));
         }
     }
     catch (Exception e)
     {
         LogUtility.LogError("CreateUninitializedItem => {0}", e.ToString());
         LastException = e;
         if (configuration.ThrowOnError)
         {
             throw;
         }
     }
 }
 public override void CreateUninitializedItem(HttpContext context, string id, int timeout)
 {
     try
     {
         if (LastException == null)
         {
             LogUtility.LogInfo("CreateUninitializedItem => Session Id: {0}, Session provider object: {1}.", id, this.GetHashCode());
             ISessionStateItemCollection sessionData = new ChangeTrackingSessionStateItemCollection();
             sessionData["SessionStateActions"] = SessionStateActions.InitializeItem;
             GetAccessToStore(id);
             // Converting timout from min to sec
             cache.Set(sessionData, (timeout * FROM_MIN_TO_SEC));
         }
     }
     catch (Exception e)
     {
         LogUtility.LogError("CreateUninitializedItem => {0}", e.ToString());
         LastException = e;
         if (configuration.ThrowOnError)
         {
             throw;
         }
     }
 }
        public ISessionStateItemCollection GetSessionData(object rowDataFromRedis)
        {
            RedisResult rowDataAsRedisResult = (RedisResult)rowDataFromRedis;
            RedisResult[] lockScriptReturnValueArray = (RedisResult[])rowDataAsRedisResult;
            Debug.Assert(lockScriptReturnValueArray != null);

            ISessionStateItemCollection sessionData = null;
            if (lockScriptReturnValueArray.Length > 1 && lockScriptReturnValueArray[1] != null)
            {
                RedisResult[] data = (RedisResult[])lockScriptReturnValueArray[1];

                // LUA script returns data as object array so keys and values are store one after another
                // This list has to be even because it contains pair of <key, value> as {key, value, key, value}
                if (data != null && data.Length != 0 && data.Length % 2 == 0)
                {
                    sessionData = new ChangeTrackingSessionStateItemCollection();
                    // In every cycle of loop we are getting one pair of key value and putting it into session items
                    // thats why increment is by 2 because we want to move to next pair
                    for (int i = 0; (i + 1) < data.Length; i += 2)
                    {
                        string key = (string) data[i];
                        object val = redisUtility.GetObjectFromBytes((byte[]) data[i + 1]);
                        if (key != null)
                        {
                            sessionData[key] = val;
                        }
                    }
                }
            }
            return sessionData;
        }
        public override void SetAndReleaseItemExclusive(HttpContext context, string id, SessionStateStoreData item, object lockId, bool newItem)
        {
            try
            {
                if (LastException == null)
                {
                    GetAccessToStore(id);
                    // If it is new record
                    if (newItem)
                    {
                        ISessionStateItemCollection sessionItems = null;
                        if (item != null && item.Items != null)
                        {
                            sessionItems = item.Items;
                        }
                        else
                        {
                            sessionItems = new ChangeTrackingSessionStateItemCollection();
                        }

                        if (sessionItems["SessionStateActions"] != null)
                        {
                            sessionItems.Remove("SessionStateActions");
                        }

                        // Converting timout from min to sec
                        cache.Set(sessionItems, (item.Timeout * FROM_MIN_TO_SEC));
                        LogUtility.LogInfo("SetAndReleaseItemExclusive => Session Id: {0}, Session provider object: {1} => created new item in session.", id, this.GetHashCode());
                    } // If update if lock matches
                    else
                    {
                        if (item != null && item.Items != null)
                        {
                            if (item.Items["SessionStateActions"] != null)
                            {
                                item.Items.Remove("SessionStateActions");
                            }
                            // Converting timout from min to sec
                            cache.TryUpdateAndReleaseLockIfLockIdMatch(lockId, item.Items, (item.Timeout * FROM_MIN_TO_SEC));
                            LogUtility.LogInfo("SetAndReleaseItemExclusive => Session Id: {0}, Session provider object: {1} => updated item in session.", id, this.GetHashCode());
                        }
                    }
                }
            }
            catch (Exception e)
            {
                LogUtility.LogError("SetAndReleaseItemExclusive => {0}", e.ToString());
                LastException = e;
                if (configuration.ThrowOnError)
                {
                    throw;
                }
            }
        }