• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# SessionStateActions类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: GetItemReturnsExpectedSessionStateStoreDataWhenItemHasNotExpired

        public void GetItemReturnsExpectedSessionStateStoreDataWhenItemHasNotExpired()
        {
            // Arrange
            string expectedAppName = "You are everything ... to me";
            string appPath = "Application path";
            var subject = TestStoreProviderFactory.SetupStoreProvider(appPath, MockHostingProvider);
            NameValueCollection keyPairs = new NameValueCollection();
            keyPairs.Set("applicationName", expectedAppName);

            bool locked = false;
            TimeSpan lockAge = new TimeSpan();
            SessionStateActions actions = new SessionStateActions();
            object lockId = null;

            string providedSessionId = "A sessionId";

            SessionStateDocument sessionObject = TestSessionDocumentFactory.CreateSessionStateDocument(providedSessionId, expectedAppName);
            sessionObject.Expiry = DateTime.UtcNow.AddDays(1);

            var sessionItems = new SessionStateItemCollection();

            sessionItems["ACar"] = new Car("A6", "Audi");

            sessionObject.SessionItems  = subject.Serialize(sessionItems);

            MockDocumentSession.Setup(cmd => cmd.Load<SessionStateDocument>(SessionStateDocument.GenerateDocumentId(providedSessionId, expectedAppName))).Returns(sessionObject);

            subject.Initialize("A name", keyPairs, MockDocumentStore.Object);

            // Act
            var result =
                    subject.GetItem(new HttpContext(new SimpleWorkerRequest("", "", "", "", new StringWriter())), "A sessionId", out locked, out lockAge, out lockId , out actions );

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Items.Count);
            Assert.IsInstanceOf<Car>(result.Items[0]);
            Assert.AreEqual("A6", ((Car)result.Items[0]).Name);
            Assert.AreEqual("Audi", ((Car)result.Items[0]).Manufacturer);
        }
开发者ID:CorporateActionMan,项目名称:RavenDbSessionStateStoreProvider,代码行数:40,代码来源:GetItemTests.cs


示例17: GetItemInternal

		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);
		}
开发者ID:kumpera,项目名称:mono,代码行数:79,代码来源:SessionStateServerHandler.cs


示例18: GetItemExclusive

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


示例19: GetSessionStoreItem

        /// <summary>
        /// Get the session for DynamoDB and optionally lock the record.
        /// </summary>
        /// <param name="lockRecord"></param>
        /// <param name="context"></param>
        /// <param name="sessionId"></param>
        /// <param name="locked"></param>
        /// <param name="lockAge"></param>
        /// <param name="lockId"></param>
        /// <param name="actionFlags"></param>
        /// <returns></returns>
        private SessionStateStoreData GetSessionStoreItem(bool lockRecord,
                                                          HttpContext context,
                                                          string sessionId,
                                                          out bool locked,
                                                          out TimeSpan lockAge,
                                                          out object lockId,
                                                          out SessionStateActions actionFlags)
        {
            LogInfo("GetSessionStoreItem", sessionId, lockRecord, context);

            // Initial values for return value and out parameters.
            SessionStateStoreData item = null;
            lockAge = TimeSpan.Zero;
            lockId = Guid.NewGuid().ToString();
            locked = false;
            actionFlags = SessionStateActions.None;

            bool foundRecord = false;
            bool deleteData = false;

            DateTime newLockedDate = DateTime.Now;

            Document session = null;
            if (lockRecord)
            {
                Document lockDoc = new Document();
                lockDoc[ATTRIBUTE_SESSION_ID] = GetHashKey(sessionId);
                lockDoc[ATTRIBUTE_LOCK_ID] = lockId.ToString();
                lockDoc[ATTRIBUTE_LOCKED] = true;
                lockDoc[ATTRIBUTE_LOCK_DATE] = DateTime.Now;

                try
                {
                    session = this._table.UpdateItem(lockDoc, LOCK_UPDATE_CONFIG);
                    locked = false;
                }
                catch (ConditionalCheckFailedException)
                {
                    // This means the record is already locked by another request.
                    locked = true;
                }
            }

            if (session == null)
            {
                session = this._table.GetItem(GetHashKey(sessionId), CONSISTENT_READ_GET);
                if (session == null && lockRecord)
                {
                    locked = true;
                }
            }

            string serializedItems = null;
            if (session != null)
            {
                DateTime expire = (DateTime)session[ATTRIBUTE_EXPIRES];

                if (expire < DateTime.Now)
                {
                    deleteData = true;
                    locked = false;
                }
                else
                {
                    foundRecord = true;

                    DynamoDBEntry entry;
                    if (session.TryGetValue(ATTRIBUTE_SESSION_ITEMS, out entry))
                    {
                        serializedItems = (string)entry;
                    }

                    if (session.Contains(ATTRIBUTE_LOCK_ID))
                        lockId = (string)session[ATTRIBUTE_LOCK_ID];

                    if (session.Contains(ATTRIBUTE_FLAGS))
                        actionFlags = (SessionStateActions)((int)session[ATTRIBUTE_FLAGS]);

                    if (session[ATTRIBUTE_LOCK_DATE] != null)
                    {
                        DateTime lockDate = (DateTime)session[ATTRIBUTE_LOCK_DATE];
                        lockAge = DateTime.Now.Subtract(lockDate);
                    }
                }
            }

            if (deleteData)
            {
                this.deleteItem(sessionId);
//.........这里部分代码省略.........
开发者ID:JaredHatfield,项目名称:aws-dotnet-session-provider,代码行数:101,代码来源:DynamoDBSessionStateStore.cs


示例20: GetItemExclusive

 /// <summary>
 /// Returns session-state data from the DynamoDB table.
 /// </summary>
 /// <param name="context"></param>
 /// <param name="sessionId"></param>
 /// <param name="locked"></param>
 /// <param name="lockAge"></param>
 /// <param name="lockId"></param>
 /// <param name="actionFlags"></param>
 /// <returns></returns>
 public override SessionStateStoreData GetItemExclusive(HttpContext context,
                                                       string sessionId,
                                                       out bool locked,
                                                       out TimeSpan lockAge,
                                                       out object lockId,
                                                       out SessionStateActions actionFlags)
 {
     LogInfo("GetItemExclusive", sessionId, context);
     return GetSessionStoreItem(true, context, sessionId, out locked,
       out lockAge, out lockId, out actionFlags);
 }
开发者ID:JaredHatfield,项目名称:aws-dotnet-session-provider,代码行数:21,代码来源:DynamoDBSessionStateStore.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# SessionStateItemExpireCallback类代码示例发布时间:2022-05-24
下一篇:
C# SessionState类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap