Example #1
0
        /// <summary>
        /// Gets an object from session.
        /// </summary>
        /// <param name="sessionId">User's SessionId indicating whose session to store in.</param>
        /// <param name="key">The key whose value to get.</param>
        /// <returns>The value for specified key. Returns <c>null</c> if the specified key doesn't exist.</returns>
        /// <exception cref="ClientException">Session expired.</exception>
        public object GetData(T sessionId, string key)
        {
            this.slimLock.EnterReadLock();

            try
            {
                if (this.activeEntries.ContainsKey(sessionId))
                {
                    MemorySessionEntry entry = this.activeEntries[sessionId];
                    entry.LastAccessTime = DateTime.Now;

                    if (entry.SessionObjects.ContainsKey(key))
                    {
                        return(entry.SessionObjects[key]);
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    throw new SessionExpiredException();
                }
            }
            finally
            {
                this.slimLock.ExitReadLock();
            }
        }
Example #2
0
        /// <summary>
        /// Stores an object in session.
        /// </summary>
        /// <param name="sessionId">User's SessionId indicating whose session to store in.</param>
        /// <param name="key">The key of the element to add or modify.</param>
        /// <param name="value">The value of the element to add or modify.</param>
        /// <exception cref="ClientException">Session expired.</exception>
        public void SetData(T sessionId, string key, object value)
        {
            this.slimLock.EnterReadLock();

            try
            {
                //MemorySessionEntry exists
                if (this.activeEntries.ContainsKey(sessionId))
                {
                    MemorySessionEntry entry = this.activeEntries[sessionId];
                    //Overwrite if object already exist
                    if (entry.SessionObjects.ContainsKey(key))
                    {
                        entry.SessionObjects[key] = value;
                    }
                    else //add new object to the SessionObjects collection
                    {
                        entry.SessionObjects.Add(key, value);
                    }
                }
                else
                {
                    throw new SessionExpiredException();
                }
            }
            finally
            {
                this.slimLock.ExitReadLock();
            }
        }