public static bool TryParse(byte[] raw, out RedisSessionStateStore.LockData data)
 {
     if (raw != null && raw.Length > 1)
     {
         byte[] array = ((IEnumerable <byte>)raw).Take <byte>(16).ToArray <byte>();
         long   int64 = BitConverter.ToInt64(raw, 17);
         data = new RedisSessionStateStore.LockData()
         {
             LockId      = array,
             LockUtcTime = new DateTime(int64)
         };
         return(true);
     }
     data = new RedisSessionStateStore.LockData();
     return(false);
 }
        public override SessionStateStoreData GetItemExclusive(HttpContext context, string id, out bool locked, out TimeSpan lockAge, out object lockId, out SessionStateActions actions)
        {
            RedisConnection redisConnection = this.GetRedisConnection();
            Task <byte[]>   task1           = redisConnection.Hashes.Get(0, this.lockHashKey, id, false);

            actions = SessionStateActions.None;
            locked  = false;
            lockId  = (object)null;
            lockAge = TimeSpan.MinValue;
            task1.Wait();
            byte[] result1 = task1.Result;
            if (result1 == null)
            {
                RedisSessionStateStore.LockData data = RedisSessionStateStore.LockData.New();
                using (RedisTransaction transaction = redisConnection.CreateTransaction())
                {
                    Task <bool> task2 = transaction.Hashes.SetIfNotExists(0, this.lockHashKey, id, data.ToByteArray(), false);
                    Task <Dictionary <string, byte[]> > all = transaction.Hashes.GetAll(0, this.GetKeyForSessionId(id), false);
                    transaction.Execute(false, (object)null);
                    task2.Wait();
                    if (task2.Result)
                    {
                        locked  = true;
                        lockAge = new TimeSpan(0L);
                        lockId  = (object)data.LockId;
                        SessionStateItemCollection  stateItemCollection = new SessionStateItemCollection();
                        Dictionary <string, byte[]> dictionary          = redisConnection.Wait <Dictionary <string, byte[]> >(all);
                        if (dictionary.Count == 3)
                        {
                            actions = (int)dictionary["initialize"][0] == 1 ? SessionStateActions.InitializeItem : SessionStateActions.None;
                            MemoryStream memoryStream = new MemoryStream(dictionary["data"]);
                            if (memoryStream.Length > 0L)
                            {
                                stateItemCollection = SessionStateItemCollection.Deserialize(new BinaryReader((Stream)memoryStream));
                            }
                            int int32 = BitConverter.ToInt32(dictionary["timeoutMinutes"], 0);
                            redisConnection.Keys.Expire(0, this.GetKeyForSessionId(id), int32 * 60, false);
                        }
                        return(new SessionStateStoreData((ISessionStateItemCollection)stateItemCollection, SessionStateUtility.GetSessionStaticObjects(context), this.redisConfig.SessionTimeout));
                    }
                    byte[] result2 = redisConnection.Hashes.Get(0, this.lockHashKey, id, false).Result;
                    if (result2 != null && RedisSessionStateStore.LockData.TryParse(result2, out data))
                    {
                        locked  = true;
                        lockId  = (object)data.LockId;
                        lockAge = DateTime.UtcNow - data.LockUtcTime;
                    }
                    return((SessionStateStoreData)null);
                }
            }
            else
            {
                RedisSessionStateStore.LockData data;
                if (RedisSessionStateStore.LockData.TryParse(result1, out data))
                {
                    locked  = true;
                    lockId  = (object)data.LockId;
                    lockAge = DateTime.UtcNow - data.LockUtcTime;
                }
                return((SessionStateStoreData)null);
            }
        }