/// <summary>
        /// Instantiates a new instance of the RedisSessionStateItemCollection class with data from
        ///     Redis
        /// </summary>
        /// <param name="redisHashData">An array of keys to values from the redis hash</param>
        /// <param name="redisConnName">The name of the connection from the redis connection wrapper</param>
        public RedisSessionStateItemCollection(
            HashEntry[] redisHashData,
            string redisConnName,
            byte constructorSignatureDifferentiator)
        {
            int byteDataTotal = 0;
            int concLevel     = RedisSessionConfig.SessionAccessConcurrencyLevel;

            if (concLevel < 1)
            {
                concLevel = 1;
            }

            int numItems = 0;

            if (redisHashData != null)
            {
                numItems = redisHashData.Length;
            }

            // To match ASP.NET behavior, dictionaries should match keys case insensitively
            this.Items             = new ConcurrentDictionary <string, object>(concLevel, numItems, StringComparer.InvariantCultureIgnoreCase);
            this.SerializedRawData = new ConcurrentDictionary <string, string>(concLevel, numItems, StringComparer.InvariantCultureIgnoreCase);
            if (redisHashData != null)
            {
                foreach (var sessDataEntry in redisHashData)
                {
                    string hashItemKey   = sessDataEntry.Name.ToString();
                    string hashItemValue = sessDataEntry.Value.ToString();

                    if (this.SerializedRawData.TryAdd(
                            hashItemKey,
                            hashItemValue))
                    {
                        this.Items.TryAdd(
                            hashItemKey,
                            new NotYetDeserializedPlaceholderValue());
                    }

                    byteDataTotal += hashItemValue.Length;
                }
            }

            // To match ASP.NET behavior, dictionaries should match keys case insensitively
            this.ChangedKeysDict = new ConcurrentDictionary <string, ActionAndValue>(StringComparer.InvariantCultureIgnoreCase);

            if (byteDataTotal != 0 && !string.IsNullOrEmpty(redisConnName) &&
                RedisConnectionConfig.LogRedisSessionSize != null)
            {
                RedisConnectionConfig.LogRedisSessionSize(redisConnName, byteDataTotal);
            }

            this.cereal = RedisSerializationConfig.SessionDataSerializer;

            if (byteDataTotal > RedisConnectionConfig.MaxSessionByteSize)
            {
                RedisConnectionConfig.RedisSessionSizeExceededHandler(this, byteDataTotal);
            }
        }
Ejemplo n.º 2
0
        public RedisSessionStateItemCollection(Dictionary <string, byte[]> redisHashData, string redisConnName)
        {
            int byteDataTotal = 0;
            int concLevel     = RedisSessionConfig.SessionAccessConcurrencyLevel;

            if (concLevel < 1)
            {
                concLevel = 1;
            }

            int numItems = 0;

            if (redisHashData != null)
            {
                numItems = redisHashData.Count;
            }

            this.Items             = new ConcurrentDictionary <string, object>(concLevel, numItems);
            this.SerializedRawData = new ConcurrentDictionary <string, string>();
            if (redisHashData != null)
            {
                foreach (var sessDataEntry in redisHashData)
                {
                    if (this.SerializedRawData.TryAdd(
                            sessDataEntry.Key,
                            Encoding.UTF8.GetString(sessDataEntry.Value)))
                    {
                        this.Items.TryAdd(
                            sessDataEntry.Key,
                            new NotYetDeserializedPlaceholderValue());
                    }

                    byteDataTotal += sessDataEntry.Value.Length;
                }
            }

            this.ChangedKeysDict = new ConcurrentDictionary <string, ActionAndValue>();

            if (byteDataTotal != 0 && !string.IsNullOrEmpty(redisConnName) &&
                RedisConnectionConfig.LogRedisSessionSize != null)
            {
                RedisConnectionConfig.LogRedisSessionSize(redisConnName, byteDataTotal);
            }

            this.cereal = RedisSerializationConfig.SessionDataSerializer;

            if (byteDataTotal > RedisConnectionConfig.MaxSessionByteSize)
            {
                RedisConnectionConfig.RedisSessionSizeExceededHandler(this, byteDataTotal);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Instantiates a new instance of the RedisSessionStateItemCollection class with data from
        ///     Redis
        /// </summary>
        /// <param name="redisHashData">An array of keys to values from the redis hash</param>
        /// <param name="redisConnName">The name of the connection from the redis connection wrapper</param>
        public RedisSessionStateItemCollection(HashEntry[] redisHashData, string redisKey)
        {
            int concLevel = Math.Max(RedisSessionConfig.SessionAccessConcurrencyLevel, 1);
            int numItems  = redisHashData != null ? redisHashData.Length : 0;

            Items             = new ConcurrentDictionary <string, object>(concLevel, numItems);
            SerializedRawData = new ConcurrentDictionary <string, string>(concLevel, numItems);
            ChangedKeysDict   = new ConcurrentDictionary <string, ActionAndValue>();
            Serializer        = RedisSerializationConfig.SessionDataSerializer;

            if (numItems > 0)
            {
                int byteDataTotal = 0;
                foreach (var sessDataEntry in redisHashData)
                {
                    string hashItemKey   = sessDataEntry.Name.ToString();
                    string hashItemValue = sessDataEntry.Value.ToString();

                    if (this.SerializedRawData.TryAdd(hashItemKey, hashItemValue))
                    {
                        this.Items.TryAdd(hashItemKey, new NotYetDeserializedPlaceholderValue());
                    }

                    byteDataTotal += hashItemValue.Length;
                }

                if (byteDataTotal > 0 && !string.IsNullOrEmpty(redisKey) && RedisConnectionConfig.LogRedisSessionSize != null)
                {
                    RedisConnectionConfig.LogRedisSessionSize(RedisSessionProvider.Redis.RedisConnectionWrapper.GetConnectionId(redisKey), byteDataTotal);
                }

                if (byteDataTotal > RedisConnectionConfig.MaxSessionByteSize)
                {
                    RedisConnectionConfig.RedisSessionSizeExceededHandler(this, byteDataTotal);
                }
            }
        }