当前位置: 首页>>代码示例>>C#>>正文


C# SessionStateActions类代码示例

本文整理汇总了C#中SessionStateActions的典型用法代码示例。如果您正苦于以下问题:C# SessionStateActions类的具体用法?C# SessionStateActions怎么用?C# SessionStateActions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SessionStateActions类属于命名空间,在下文中一共展示了SessionStateActions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetItemInternal

		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);
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:60,代码来源:SessionStateServerHandler.cs

示例2: GetItem

        public override SessionStateStoreData GetItem(HttpContext context,
				string id,
				out bool locked,
				out TimeSpan lockAge,
				out object lockId,
				out SessionStateActions actions)
        {
            var redis = GetRedisConnection();
            var getSessionData = redis.Hashes.GetAll(0, GetKeyForSessionId(id));
            locked = false;
            lockAge = new TimeSpan(0);
            lockId = null;
            actions = SessionStateActions.None;

            if (getSessionData.Result == null) {
                return null;
            }
            else {
                var sessionItems = new SessionStateItemCollection();
                var sessionDataHash = getSessionData.Result;
                if (sessionDataHash.Count == 3) {
                    sessionItems = Deserialize(sessionDataHash["data"]);

                    var timeoutMinutes = BitConverter.ToInt32(sessionDataHash["timeoutMinutes"], 0);
                    redis.Keys.Expire(0, GetKeyForSessionId(id), timeoutMinutes * 60);
                }

                return new SessionStateStoreData(sessionItems,
                     SessionStateUtility.GetSessionStaticObjects(context),
                     redisConfig.SessionTimeout);
            }
        }
开发者ID:rbwestmoreland,项目名称:AL-Redis,代码行数:32,代码来源:RedisSessionStateStore.cs

示例3: GetItem

        /// <summary>
        /// Called when SessionState = ReadOnly
        /// </summary>
        public override SessionStateStoreData GetItem(HttpContext context, string id, out bool locked, out TimeSpan lockAge, out object lockId, out SessionStateActions actions)
        {
            RedisConnection redisConnection = ConnectionUtils.Connect("10.0.0.3:6379");
            {
                redisConnection.Open();

                var result = redisConnection.Strings.Get(0, id);
                byte[] raw = redisConnection.Wait(result);

                actions = SessionStateActions.None;

                SessionEntity sessionEntity = GetFromBytes(raw);
                if (sessionEntity == null || sessionEntity.SessionItems == null )
                {
                    locked = false;
                    lockId = _lock;
                    lockAge = TimeSpan.MinValue;
                    return null;
                }

                ISessionStateItemCollection sessionItems = new SessionStateItemCollection();
                foreach (string key in sessionEntity.SessionItems.Keys)
                {
                    sessionItems[key] = sessionEntity.SessionItems[key];
                }

                SessionStateStoreData data = new SessionStateStoreData(sessionItems, _staticObjects, context.Session.Timeout);

                locked = false;
                lockId = _lock;
                lockAge = TimeSpan.MinValue;
                return data;
            }
        }
开发者ID:ThomasSchmidt,项目名称:MixedStuff,代码行数:37,代码来源:RedisSessionStateStoreProvider.cs

示例4: GetItem

		internal StateServerItem GetItem (string id,
						  out bool locked,
						  out TimeSpan lockAge,
						  out object lockId,
						  out SessionStateActions actions,
						  bool exclusive)
		{
			Console.WriteLine ("RemoteStateServer.GetItem");
			Console.WriteLine ("\tid == {0}", id);
			locked = false;
			lockAge = TimeSpan.MinValue;
			lockId = Int32.MinValue;
			actions = SessionStateActions.None;
			
			LockableStateServerItem item = Retrieve (id);
			if (item == null || item.item.IsAbandoned ()) {
				Console.WriteLine ("\tNo item for that id (abandoned == {0})", item != null ? item.item.IsAbandoned() : false);
				return null;
			}
			
			try {
				Console.WriteLine ("\tacquiring reader lock");
				item.rwlock.AcquireReaderLock (lockAcquireTimeout);
				if (item.item.Locked) {
					Console.WriteLine ("\titem is locked");
					locked = true;
					lockAge = DateTime.UtcNow.Subtract (item.item.LockedTime);
					lockId = item.item.LockId;
					return null;
				}
				Console.WriteLine ("\teleasing reader lock");
				item.rwlock.ReleaseReaderLock ();
				if (exclusive) {
					Console.WriteLine ("\tacquiring writer lock");
					item.rwlock.AcquireWriterLock (lockAcquireTimeout);
					Console.WriteLine ("\tlocking the item");
					item.item.Locked = true;
					item.item.LockedTime = DateTime.UtcNow;
					item.item.LockId++;
					Console.WriteLine ("\tnew lock id == {0}", item.item.LockId);
					lockId = item.item.LockId;
				}
			} catch {
				throw;
			} finally {
				if (item.rwlock.IsReaderLockHeld) {
					Console.WriteLine ("\treleasing reader lock [finally]");
					item.rwlock.ReleaseReaderLock ();
				}
				if (item.rwlock.IsWriterLockHeld) {
					Console.WriteLine ("\treleasing writer lock [finally]");
					item.rwlock.ReleaseWriterLock ();
				}
			}
			
			Console.WriteLine ("\treturning an item");
			actions = item.item.Action;
			return item.item;
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:59,代码来源:RemoteStateServer.cs

示例5: GetItemExclusive

        public override SessionStateStoreData GetItemExclusive(HttpContext context, string id, out bool locked, out TimeSpan lockAge, out object lockId, out SessionStateActions actions)
        {
            var e = Get(context, true, id, out locked, out lockAge, out lockId, out actions);

            return (e == null)
                    ? null
                    : e.ToStoreData(context);
        }
开发者ID:colinbate,项目名称:memcached-providers,代码行数:8,代码来源:MembaseSessionStateProvider.cs

示例6: GetSessionStoreItem

        /// <summary>
        /// Retrieves the session data from the data source. If the lockRecord parameter is true 
        /// (in the case of GetItemExclusive), then the record is locked and we return a new lockId 
        /// and lockAge.
        /// </summary>
        /// <param name="bucket">Reference to the couchbase bucket we are using</param>
        /// <param name="context">HttpContext for the current request</param>
        /// <param name="acquireLock">True to aquire the lock, false to not aquire it</param>
        /// <param name="id">Session ID for the session</param>
        /// <param name="locked">Returns true if the session item is locked, otherwise false</param>
        /// <param name="lockAge">Returns the amount of time that the item has been locked</param>
        /// <param name="lockId">Returns lock identifier for the current request</param>
        /// <param name="actions">Indicates whether the current sessions is an uninitialized, cookieless session</param>
        /// <returns>SessionStateItem object containing the session state data</returns>
        public static SessionStateItem GetSessionStoreItem(
            IBucket bucket,
            HttpContext context,
            bool acquireLock,
            string id,
            out bool locked,
            out TimeSpan lockAge,
            out object lockId,
            out SessionStateActions actions)
        {
            locked = false;
            lockId = null;
            lockAge = TimeSpan.Zero;
            actions = SessionStateActions.None;

            var e = SessionStateItem.Load(bucket, id, false);
            if (e == null)
                return null;

            if (acquireLock) {
                // repeat until we can update the retrieved
                // item (i.e. nobody changes it between the
                // time we get it from the store and updates it s attributes)
                // Save() will return false if Cas() fails
                while (true) {
                    if (e.LockId > 0)
                        break;

                    actions = e.Flag;

                    e.LockId = _exclusiveAccess ? e.HeadCas : 0;
                    e.LockTime = DateTime.UtcNow;
                    e.Flag = SessionStateActions.None;

                    // try to update the item in the store
                    if (e.SaveHeader(bucket, id, _exclusiveAccess))
                    {
                        locked = true;
                        lockId = e.LockId;

                        return e;
                    }

                    // it has been modified between we loaded and tried to save it
                    e = SessionStateItem.Load(bucket, id, false);
                    if (e == null)
                        return null;
                }
            }

            locked = true;
            lockAge = DateTime.UtcNow - e.LockTime;
            lockId = e.LockId;
            actions = SessionStateActions.None;

            return acquireLock ? null : e;
        }
开发者ID:andynewm,项目名称:couchbase-aspnet,代码行数:71,代码来源:CouchbaseSessionStateProvider.cs

示例7: GetItem

 public override SessionStateStoreData GetItem(HttpContext context,
     string id,
     out bool locked,
     out TimeSpan lockAge,
     out object lockId,
     out SessionStateActions actionFlags)
 {
     return GetSessionStoreItem(false, context, id, out locked, out lockAge, out lockId, out actionFlags);
 }
开发者ID:GunioRobot,项目名称:MongoSessionStore,代码行数:9,代码来源:MongoSessionStoreProvider.cs

示例8: GetItem

        private SessionStateStoreData GetItem(bool exclusive, System.Web.HttpContext context, string id, out bool locked, out TimeSpan lockAge, out object lockId, out SessionStateActions actions) {
            actions = 0;
            locked = false;
            lockId = 0;
            lockAge = TimeSpan.Zero;

            var collection = this._mongo.GetCollection();

            if (exclusive && !this._mongo.LockSession(collection, id)) {
                var previouslyLockedSession = this._mongo.GetMongoSessionObject(collection, id);

                if (previouslyLockedSession == null) {
                    lockId = previouslyLockedSession.LockID;
                    lockAge = DateTime.UtcNow - previouslyLockedSession.LockedDate;
                }

                this.LogEvent(id, context.Request.RawUrl, GetUsername(context.User), "Unable to obtain lock - " + lockAge);

                return null;
            }

            var sessionObject = this._mongo.GetMongoSessionObject(collection, id);

            if (sessionObject == null) {
                this.LogEvent(id, context.Request.RawUrl, GetUsername(context.User), "No session");

                return null;
            }

            if (sessionObject.ExpiresDate < DateTime.UtcNow) {
                this._mongo.ClearMongoSessionObject(collection, id);

                this.LogEvent(id, context.Request.RawUrl, GetUsername(context.User), "Session has expired");

                return null;
            }

            locked = sessionObject.IsLocked;
            if (locked) {
                lockAge = DateTime.UtcNow - sessionObject.LockedDate;
                lockId = sessionObject.LockID;

                this.LogEvent(id, context.Request.RawUrl, GetUsername(context.User), "Obtained lock on session - " + lockId);
            }

            actions = (SessionStateActions)sessionObject.Flags;
            sessionObject.Flags = 0;

            collection.Save(sessionObject);

            if (actions == SessionStateActions.InitializeItem) {
                return CreateNewStoreData(context, (int)this._timeoutInMinutes);
            }

            return Deserialize(context, sessionObject.SessionData, sessionObject.Timeout);
        }
开发者ID:bkrauska,项目名称:MongoDB.Session,代码行数:56,代码来源:SessionStateProvider.cs

示例9: GetItemExclusive

 public override SessionStateStoreData GetItemExclusive(
     HttpContext context,
     string id,
     out bool locked,
     out TimeSpan lockAge,
     out object lockId,
     out SessionStateActions actions)
 {
     return this.GetSessionItem(true, context, id, out locked, out lockAge, out lockId, out actions);
 }
开发者ID:kendi,项目名称:MemcachedSessionStateStoreProvider,代码行数:10,代码来源:MemcachedSessionStateStoreProvider.cs

示例10: StateServerItem

		public StateServerItem (byte [] collection_data, byte [] sobjs_data, int timeout)
		{
			this.CollectionData = collection_data;
			this.StaticObjectsData = sobjs_data;
			this.Timeout = timeout;
			this.last_access = DateTime.UtcNow;
			this.Locked = false;
			this.LockId = Int32.MinValue;
			this.LockedTime = DateTime.MinValue;
			this.Action = SessionStateActions.None;
		}
开发者ID:Profit0004,项目名称:mono,代码行数:11,代码来源:StateServerItem.cs

示例11: Session

 public Session(string id, string applicationName, int timeout, Binary sessionItems, int sessionItemsCount,SessionStateActions actionFlags )
 {
     this._sessionID = id;
     this._applicationName = applicationName;
     this._lockDate = DateTime.Now;
     this._lockID = 0;
     this._timeout = timeout;
     this._locked = false;
     this._sessionItems = sessionItems;
     this._sessionItemsCount = sessionItemsCount;
     this._flags = (int)actionFlags;
     this._created = DateTime.Now;
     this._expires = DateTime.Now.AddMinutes((Double)this._timeout);         
 }
开发者ID:jango2015,项目名称:MongoSessionStore,代码行数:14,代码来源:Session.cs

示例12: Session

        public Session(string id, string applicationName, int timeout, BsonBinaryData sessionItems, int sessionItemsCount, SessionStateActions actionFlags)
        {
            DateTime now = DateTime.Now;

            SessionID = id;
            ApplicationName = applicationName;
            LockDate = now;
            LockID = 0;
            Timeout = timeout;
            Locked = false;
            SessionItems = sessionItems;
            SessionItemsCount = sessionItemsCount;
            Flags = (int)actionFlags;
            Created = now;
            Expires = now.AddMinutes((Double)this.Timeout);
        }
开发者ID:paralect,项目名称:MongoSessionStore,代码行数:16,代码来源:Session.cs

示例13: GetItem

		internal StateServerItem GetItem (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;
			
			LockableStateServerItem item = Retrieve (id);
			if (item == null || item.item.IsAbandoned ())
				return null;
			
			try {
				item.rwlock.AcquireReaderLock (lockAcquireTimeout);
				if (item.item.Locked) {
					locked = true;
					lockAge = DateTime.UtcNow.Subtract (item.item.LockedTime);
					lockId = item.item.LockId;
					return null;
				}

				item.rwlock.ReleaseReaderLock ();
				if (exclusive) {
					item.rwlock.AcquireWriterLock (lockAcquireTimeout);
					item.item.Locked = true;
					item.item.LockedTime = DateTime.UtcNow;
					item.item.LockId++;
					lockId = item.item.LockId;
				}
			} catch {
				throw;
			} finally {
				if (item.rwlock.IsReaderLockHeld)
					item.rwlock.ReleaseReaderLock ();
				
				if (item.rwlock.IsWriterLockHeld)
					item.rwlock.ReleaseWriterLock ();
			}
			
			actions = item.item.Action;
			return item.item;
		}
开发者ID:Profit0004,项目名称:mono,代码行数:46,代码来源:RemoteStateServer.cs

示例14: GetItem

 public override SessionStateStoreData GetItem(HttpContext context, string id, out bool locked,
     out TimeSpan lockAge, out object lockId,
     out SessionStateActions actions)
 {
     // set default out parameters
     locked = false;
     lockAge = new TimeSpan();
     lockId = null;
     actions = SessionStateActions.None;
     // try to get the session from cache.
     string sessionString = cache.GetAsync<string>(id).Result;
     if (string.IsNullOrEmpty(sessionString))
         return null;
     var sessionItems = JsonConvert.DeserializeObject<SessionStateItemCollection>(sessionString);
     var data = new SessionStateStoreData(sessionItems, null, 60); // todo: set timeout.
     return data;
 }
开发者ID:jahmad-fareportal,项目名称:CacheSharp,代码行数:17,代码来源:CacheSharpSessionProvider.cs

示例15: GetItem

		public override SessionStateStoreData GetItem (HttpContext context, string id, out bool locked, out TimeSpan lockAge, out object lockId, out SessionStateActions actions) {
			locked = false;
			lockAge = TimeSpan.Zero;
			lockId = null;
			actions = SessionStateActions.None;
			if (id == null)
				return null;
			HttpSession session = GetSession (context, false, false);
			if (session == null)
				return null;
			ServletSessionStateItemCollection sessionState = session.getAttribute (J2EEConsts.SESSION_STATE) as ServletSessionStateItemCollection;
			if (sessionState == null) //was not set
				sessionState = new ServletSessionStateItemCollection (context);
			return new SessionStateStoreData (
				sessionState,
				sessionState.StaticObjects,
				GetIntervalInMinutes(session.getMaxInactiveInterval ()));
		}
开发者ID:KonajuGames,项目名称:SharpLang,代码行数:18,代码来源:ServletSessionStateStoreProvider.cs


注:本文中的SessionStateActions类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。