示例#1
0
		internal void CreateUninitializedItem (string id, int timeout)
		{
			StateServerItem item = new StateServerItem (timeout);
			item.Action = SessionStateActions.InitializeItem;
			LockableStateServerItem cacheItem = new LockableStateServerItem (item);
			Insert (id, cacheItem);
		}
示例#2
0
        internal void CreateUninitializedItem(string id, int timeout)
        {
            StateServerItem item = new StateServerItem(timeout);

            item.Action = SessionStateActions.InitializeItem;
            LockableStateServerItem cacheItem = new LockableStateServerItem(item);

            Insert(id, cacheItem);
        }
示例#3
0
        internal StateServerItem Get(string id)
        {
            StateServerItem item = cache [id] as StateServerItem;

            if (item == null || item.IsAbandoned())
            {
                return(null);
            }

            return(item);
        }
示例#4
0
        internal void Touch(string id, int timeout)
        {
            StateServerItem item = Get(id);

            if (item == null)
            {
                return;
            }
            item.Timeout = timeout;
            cache.SetItemTimeout(id, Cache.NoAbsoluteExpiration, new TimeSpan(0, item.Timeout, 0), false);
        }
示例#5
0
        internal void Update(string id, byte [] dict_data, byte [] sobjs_data)
        {
            StateServerItem item = cache [id] as StateServerItem;

            if (item == null)
            {
                return;
            }

            item.DictionaryData    = dict_data;
            item.StaticObjectsData = sobjs_data;
        }
示例#6
0
		public LockableStateServerItem (StateServerItem item)
		{
			this.item = item;
			this.rwlock = new ReaderWriterLock ();
		}
		internal void Insert (string id, StateServerItem item)
		{
			table.Add (id, item);
		}
示例#8
0
 public LockableStateServerItem(StateServerItem item)
 {
     this.item   = item;
     this.rwlock = new ReaderWriterLock();
 }
		public HttpSessionState UpdateContext (HttpContext context, SessionStateModule module,
							bool required, bool read_only, ref bool isNew)
		{
			if (!required)
				return null;

			StateServerItem item = null;
			HttpSessionState session = null;
			SessionDictionary dict = null;
			HttpStaticObjectsCollection sobjs = null;
			string id = GetId (context);

			if (id != null) {
				item = state_server.Get (id);
				if (item != null) {
					dict = SessionDictionary.FromByteArray (item.DictionaryData);
					sobjs = HttpStaticObjectsCollection.FromByteArray (item.StaticObjectsData);
					session = new HttpSessionState (id, dict,
							HttpApplicationFactory.ApplicationState.SessionObjects,
							config.Timeout, false, config.CookieLess,
							SessionStateMode.StateServer, read_only);

					return session;
				}
			}
			
			id = SessionId.Create (module.Rng);
			dict = new SessionDictionary ();
			sobjs = HttpApplicationFactory.ApplicationState.SessionObjects;
			item = new StateServerItem (dict.ToByteArray (), sobjs.ToByteArray (), config.Timeout);
			
			state_server.Insert (id, item);

			session = new HttpSessionState (id, dict, sobjs, config.Timeout, true,
							config.CookieLess, SessionStateMode.StateServer,
							read_only);
			
			isNew = true;
			return session;
		}
示例#10
0
        SessionStateStoreData GetItemInternal(HttpContext context,
                                              string id,
                                              out bool locked,
                                              out TimeSpan lockAge,
                                              out object lockId,
                                              out SessionStateActions actions,
                                              bool exclusive)
        {
            Trace.WriteLine("SessionStateServerHandler.GetItemInternal");
            Trace.WriteLine("\tid == " + id);
            Trace.WriteLine("\tpath == " + context.Request.FilePath);
            locked  = false;
            lockAge = TimeSpan.MinValue;
            lockId  = Int32.MinValue;
            actions = SessionStateActions.None;

            if (id == null)
            {
                return(null);
            }

            StateServerItem item = stateServer.GetItem(id,
                                                       out locked,
                                                       out lockAge,
                                                       out lockId,
                                                       out actions,
                                                       exclusive);

            if (item == null)
            {
                Trace.WriteLine("\titem is null (locked == " + locked + ", actions == " + actions + ")");
                return(null);
            }
            if (actions == SessionStateActions.InitializeItem)
            {
                Trace.WriteLine("\titem needs initialization");
                return(CreateNewStoreData(context, item.Timeout));
            }
            SessionStateItemCollection  items = null;
            HttpStaticObjectsCollection sobjs = null;
            MemoryStream stream = null;
            BinaryReader reader = null;

            try {
                if (item.CollectionData != null && item.CollectionData.Length > 0)
                {
                    stream = new MemoryStream(item.CollectionData);
                    reader = new BinaryReader(stream);
                    items  = SessionStateItemCollection.Deserialize(reader);
                }
                else
                {
                    items = new SessionStateItemCollection();
                }
                if (item.StaticObjectsData != null && item.StaticObjectsData.Length > 0)
                {
                    sobjs = HttpStaticObjectsCollection.FromByteArray(item.StaticObjectsData);
                }
                else
                {
                    sobjs = new HttpStaticObjectsCollection();
                }
            } catch (Exception ex) {
                throw new HttpException("Failed to retrieve session state.", ex);
            } finally {
                if (reader != null)
                {
                    reader.Close();
                }
            }

            return(new SessionStateStoreData(items,
                                             sobjs,
                                             item.Timeout));
        }
		SessionStateStoreData GetItemInternal (HttpContext context,
						       string id,
						       out bool locked,
						       out TimeSpan lockAge,
						       out object lockId,
						       out SessionStateActions actions,
						       bool exclusive)
		{
			locked = false;
			lockAge = TimeSpan.MinValue;
			lockId = Int32.MinValue;
			actions = SessionStateActions.None;

			if (id == null)
				return null;
			
			StateServerItem item = stateServer.GetItem (id,
								    out locked,
								    out lockAge,
								    out lockId,
								    out actions,
								    exclusive);
			
			if (item == null)
				return null;
			
			if (actions == SessionStateActions.InitializeItem)
				return CreateNewStoreData (context, item.Timeout);
			
			SessionStateItemCollection items = null;
			HttpStaticObjectsCollection sobjs = null;
			MemoryStream stream = null;
			BinaryReader reader = null;
			Stream input = null;
#if NET_4_0
			GZipStream gzip = null;
#endif
			try {
				if (item.CollectionData != null && item.CollectionData.Length > 0) {
					stream = new MemoryStream (item.CollectionData);
#if NET_4_0					
					if (config.CompressionEnabled)
						input = gzip = new GZipStream (stream, CompressionMode.Decompress, true);
					else
#endif
						input = stream;
					reader = new BinaryReader (input);
					items = SessionStateItemCollection.Deserialize (reader);
#if NET_4_0
					if (gzip != null)
						gzip.Close ();
#endif
					reader.Close ();
				} else
					items = new SessionStateItemCollection ();
				if (item.StaticObjectsData != null && item.StaticObjectsData.Length > 0)
					sobjs = HttpStaticObjectsCollection.FromByteArray (item.StaticObjectsData);
				else
					sobjs = new HttpStaticObjectsCollection ();
			} catch (Exception ex) {
				throw new HttpException ("Failed to retrieve session state.", ex);
			} finally {
				if (stream != null)
					stream.Dispose ();
#if NET_4_0
				if (reader != null)
					reader.Dispose ();
				if (gzip != null)
					gzip.Dispose ();
#else
				if (reader != null)
					((IDisposable)reader).Dispose ();
#endif
			}
				
			return new SessionStateStoreData (items,
							  sobjs,
							  item.Timeout);
		}
		/*
		void OnItemRemoved (string key, object value, CacheItemRemovedReason reason)
		{
			Console.WriteLine ("{2} {0} removed. Reason: {1}", key, reason, Datetime.Now);
		}
		*/

		internal void Insert (string id, StateServerItem item)
		{
			//cache.Insert (id, item, null, Cache.NoAbsoluteExpiration, new TimeSpan (0, item.Timeout, 0), CacheItemPriority.Normal, removedCB);
			cache.Insert (id, item, null, Cache.NoAbsoluteExpiration, new TimeSpan (0, item.Timeout, 0));
		}
示例#13
0
        /*
         * void OnItemRemoved (string key, object value, CacheItemRemovedReason reason)
         * {
         *      Console.WriteLine ("{2} {0} removed. Reason: {1}", key, reason, Datetime.Now);
         * }
         */

        internal void Insert(string id, StateServerItem item)
        {
            //cache.Insert (id, item, null, Cache.NoAbsoluteExpiration, new TimeSpan (0, item.Timeout, 0), CacheItemPriority.Normal, removedCB);
            cache.Insert(id, item, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, item.Timeout, 0));
        }