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


C# SessionState.SessionStateStoreData类代码示例

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


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

示例1: GetItemExclusive_RecordFound

        public void GetItemExclusive_RecordFound()
        {
            Utility.SetConfigUtilityToDefault();
            string id = "session-id";
            bool locked;
            TimeSpan lockAge;
            object lockId = null;
            SessionStateActions actions;

            ISessionStateItemCollection sessionStateItemCollection = new ChangeTrackingSessionStateItemCollection();
            sessionStateItemCollection["session-key"] = "session-value";
            SessionStateStoreData sssd = new SessionStateStoreData(sessionStateItemCollection, null, 15);

            ISessionStateItemCollection sessionData = new ChangeTrackingSessionStateItemCollection();
            sessionData["session-key"] = "session-value";

            ISessionStateItemCollection mockSessionData = null;
            object mockLockId = 0;
            int mockSessionTimeout;
            int sessionTimeout = (int)RedisSessionStateProvider.configuration.SessionTimeout.TotalMinutes;
            var mockCache = A.Fake<ICacheConnection>();
            A.CallTo(() => mockCache.TryTakeWriteLockAndGetData(A<DateTime>.Ignored, 90, out mockLockId, out mockSessionData, out mockSessionTimeout)).Returns(true).AssignsOutAndRefParameters(0, sessionData, (int)RedisSessionStateProvider.configuration.SessionTimeout.TotalMinutes);

            RedisSessionStateProvider sessionStateStore = new RedisSessionStateProvider();
            sessionStateStore.cache = mockCache;
            SessionStateStoreData sessionStateStoreData = sessionStateStore.GetItemExclusive(null, id, out locked, out lockAge, out lockId, out actions);
            A.CallTo(() => mockCache.TryTakeWriteLockAndGetData(A<DateTime>.Ignored, 90, out mockLockId, out sessionData, out sessionTimeout)).MustHaveHappened();

            Assert.Equal(true, Utility.CompareSessionStateStoreData(sessionStateStoreData, sssd));
            Assert.Equal(false, locked);
            Assert.Equal(TimeSpan.Zero, lockAge);
            Assert.Equal(actions, SessionStateActions.None);
        }
开发者ID:ynoami,项目名称:aspnet-redis-providers,代码行数:33,代码来源:RedisSessionStateProviderTests.cs

示例2: CreateNewStoreData_WithEmptyStore

 public void CreateNewStoreData_WithEmptyStore()
 {
     Utility.SetConfigUtilityToDefault();
     SessionStateStoreData sssd = new SessionStateStoreData(new ChangeTrackingSessionStateItemCollection(), null, 900);
     RedisSessionStateProvider sessionStateStore = new RedisSessionStateProvider();
     Assert.Equal(true, Utility.CompareSessionStateStoreData(sessionStateStore.CreateNewStoreData(null, 900),sssd));
 }
开发者ID:Remy-Burney-Powerfront,项目名称:aspnet-redis-providers,代码行数:7,代码来源:RedisSessionStateProviderTests.cs

示例3: Save

 public void Save(ISessionStateContext context, IDictionary<string, object> values)
 {
     EnsureInitialized(context);
     var sessionState = new SessionStateStoreData(new SessionStateItemCollection().AddItems(values), new HttpStaticObjectsCollection(), _timeout);
     var data = new SessionStateEncoding().Serialize(sessionState);
     _sessionStore.Save(SqlSessionId.Create(context.MetabasePath, context.SessionId), data);
 }
开发者ID:mikeobrien,项目名称:ClassicAspRemoteSession,代码行数:7,代码来源:SqlSessionStateProvider.cs

示例4: CompareSessionStateStoreData

        internal static bool CompareSessionStateStoreData(SessionStateStoreData obj1, SessionStateStoreData obj2)
        {
            if ((obj1 == null && obj2 != null) || (obj1 != null && obj2 == null))
            {
                return false;
            }
            else if (obj1 != null && obj2 != null)
            {
                if (obj1.Timeout != obj2.Timeout)
                {
                    return false;
                }

                System.Collections.Specialized.NameObjectCollectionBase.KeysCollection keys1 = obj1.Items.Keys;
                System.Collections.Specialized.NameObjectCollectionBase.KeysCollection keys2 = obj2.Items.Keys;

                if ((keys1 != null && keys2 == null) || (keys1 == null && keys2 != null))
                {
                    return false;
                }
                else if (keys1 != null && keys2 != null)
                {
                    foreach (string key in keys1)
                    {
                        if (obj2.Items[key] == null)
                        {
                            return false;
                        }
                    }
                }

            }
            return true;
        }
开发者ID:Remy-Burney-Powerfront,项目名称:aspnet-redis-providers,代码行数:34,代码来源:Utility.cs

示例5: 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

示例6: SetAndReleaseItemExclusive

        public override void SetAndReleaseItemExclusive(HttpContext context, string id, SessionStateStoreData item, object lockId, bool newItem)
        {
            var sessionStore = SessionStore.Instance;
            try
            {

                byte[] serializedItems = Serialize((SessionStateItemCollection)item.Items);
                Binary sessionItems = new Binary(serializedItems);

                if (newItem)
                {
                    // Delete an existing expired session if it exists.
                    sessionStore.EvictExpiredSession(id, _applicationName);

                    // insert new session item.
                    Session session = new Session(id, this._applicationName, item.Timeout, sessionItems, item.Items.Count, 0);
                    sessionStore.Insert(session);
                }
                else
                {
                    sessionStore.UpdateSession(id, item.Timeout, sessionItems, this._applicationName, item.Items.Count, lockId);
                }
            }
            catch (Exception e)
            {
                if (WriteExceptionsToEventLog)
                {
                    WriteToEventLog(e, "SetAndReleaseItemExclusive");
                    throw new ProviderException(e.Message, e.InnerException);
                }
                else
                    throw e;
            }
        }
开发者ID:jango2015,项目名称:MongoSessionStore,代码行数:34,代码来源:MongoSessionStoreProvider.cs

示例7: CreateNewStoreData

 public override SessionStateStoreData CreateNewStoreData(HttpContext context, int timeout)
 {
     var sessionItems = new SessionStateItemCollection();
     string sessionString = JsonConvert.SerializeObject(sessionItems);
     cache.PutAsync(context.Session.SessionID, sessionString, TimeSpan.FromMinutes(timeout));
     var data = new SessionStateStoreData(sessionItems, null, timeout);
     return data;
 }
开发者ID:jahmad-fareportal,项目名称:CacheSharp,代码行数:8,代码来源:CacheSharpSessionProvider.cs

示例8: SetUp

 public void SetUp()
 {
     var configure = new MongoConfigurationBuilder();
     configure.ConnectionStringAppSettingKey("mongoserver");
     config = configure.BuildConfiguration();
     SessionStateItemCollection sessionItemsCollection = new SessionStateItemCollection();
     HttpStaticObjectsCollection staticObjectsCollection = new HttpStaticObjectsCollection();
     item = new SessionStateStoreData(sessionItemsCollection, staticObjectsCollection, 1);
 }
开发者ID:jango2015,项目名称:MongoSessionStore,代码行数:9,代码来源:SessionStoreTest.cs

示例9: CreateNewStoreData

        /// <summary>
        /// Creates a new System.Web.SessionState.SessionStateStoreData object to be
        /// used for the current request.
        /// </summary>
        /// <param name="context">The current request context</param>
        /// <param name="timeout">The session-state System.Web.SessionState.HttpSessionState.Timeout value
        /// for the new System.Web.SessionState.SessionStateStoreData.</param>
        /// <returns>A new System.Web.SessionState.SessionStateStoreData for the current request.</returns>
        public override SessionStateStoreData CreateNewStoreData(HttpContext context, int timeout)
        {
            SessionStateStoreData data = new SessionStateStoreData(
                new SessionStateItemCollection(),
                SessionStateUtility.GetSessionStaticObjects(context),
                timeout);

            return data;
        }
开发者ID:rrdiaz,项目名称:MongoDBSharedSession,代码行数:17,代码来源:SharedSessionStoreProvider.cs

示例10: Should_Encode_Session_Data

 public void Should_Encode_Session_Data()
 {
     var encoding = new SessionStateEncoding();
     var sessionState = new SessionStateStoreData(new SessionStateItemCollection(), new HttpStaticObjectsCollection(), 20);
     sessionState.Items[Constants.SessionStateKey1] = Constants.SessionStateValue1;
     sessionState.Items[Constants.SessionStateKey2] = Constants.SessionStateValue2;
     sessionState.Items[Constants.SessionStateKey3] = Constants.SessionStateValue3;
     encoding.Serialize(sessionState).SequenceEqual(Constants.SessionStateSerializedBytes).ShouldBeTrue();
 }
开发者ID:mikeobrien,项目名称:ClassicAspRemoteSession,代码行数:9,代码来源:SessionStateEncodingTests.cs

示例11: Init

        public RedisASPSessionVariantDictionary Init(RedisASPSessionStateProvider sessionProvider, SessionStateStoreData storeData, string sessionId, int expiry)
        {
            //PFSession.Log.Debug($"PFRedisVariantDictionary:Init:{hashkey}");
            //System.IO.File.AppendAllText(@"C:\\log files\\pfsession.log", $"PFRedisVariantDictionary:Init:{hashkey}");
            this.sessionId = sessionId;
            this.sessionProvider = sessionProvider;
            this.storeData = storeData;

            return this;
        }
开发者ID:Remy-Burney-Powerfront,项目名称:aspnet-redis-providers,代码行数:10,代码来源:RedisASPSessionVariantDictionary.cs

示例12: SetAndReleaseItemExclusive

        public override void SetAndReleaseItemExclusive(HttpContext context, string id, SessionStateStoreData item, object lockId, bool newItem)
        {
            ISessionStateItemCollection sessionItems = null;
            HttpStaticObjectsCollection staticObjects = null;

            if (item.Items.Count > 0)
                sessionItems = item.Items;
            if (!item.StaticObjects.NeverAccessed)
                staticObjects = item.StaticObjects;

            RedisSessionState state2 = new RedisSessionState(sessionItems, staticObjects, item.Timeout);
            RedisHelper.Set<string>(id, state2.ToJson(), DateTime.Now.AddHours(1));
        }
开发者ID:JamesFoxChen,项目名称:AspNetSessionManage,代码行数:13,代码来源:RedisSessionStateStore.cs

示例13: RaiseSessionOnEnd

 internal void RaiseSessionOnEnd(string id, SessionStateStoreData item)
 {
     HttpSessionStateContainer container = new HttpSessionStateContainer(id, item.Items, item.StaticObjects, item.Timeout, false, SessionStateModule.s_configCookieless, SessionStateModule.s_configMode, true);
     HttpSessionState sessionState = new HttpSessionState(container);
     if (HttpRuntime.ShutdownInProgress)
     {
         this.RaiseOnEnd(sessionState);
     }
     else
     {
         SessionOnEndTargetWorkItem item2 = new SessionOnEndTargetWorkItem(this, sessionState);
         WorkItem.PostInternal(new WorkItemCallback(item2.RaiseOnEndCallback));
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:14,代码来源:SessionOnEndTarget.cs

示例14: Serialize

 public byte[] Serialize(SessionStateStoreData sessionState)
 {
     var hasItems = sessionState.Items != null && sessionState.Items.Count > 0;
     var hasStaticObjects = sessionState.StaticObjects != null && !sessionState.StaticObjects.NeverAccessed;
     var stream = new MemoryStream();
     var writer = new BinaryWriter(stream);
     writer.Write(sessionState.Timeout);
     writer.Write(hasItems);
     writer.Write(hasStaticObjects);
     if (hasItems) ((SessionStateItemCollection)sessionState.Items).Serialize(writer);
     if (hasStaticObjects) sessionState.StaticObjects.Serialize(writer);
     writer.Write(byte.MaxValue);
     return stream.ToArray();
 }
开发者ID:mikeobrien,项目名称:ClassicAspRemoteSession,代码行数:14,代码来源:SessionStateEncoding.cs

示例15: DeserializeToSessionStateStoreData

        /// <summary>
        /// Deserializes a base 64 string to a SessionStateStoreData object.
        /// </summary>
        /// <param name="base64String">The base64 string.</param>
        /// <param name="context">The context.</param>
        /// <param name="timeout">The timeout.</param>
        /// <returns></returns>
        public static SessionStateStoreData DeserializeToSessionStateStoreData(this string base64String, HttpContext context, int timeout)
        {
            using (var memoryStream = new MemoryStream(Convert.FromBase64String(base64String)))
            {
                var sessionItems = new SessionStateItemCollection();
                if (memoryStream.Length > 0)
                {
                    using (var reader = new BinaryReader(memoryStream))
                    {
                        sessionItems = SessionStateItemCollection.Deserialize(reader);
                    }
                }

                var sessionStateStoreData = new SessionStateStoreData(sessionItems, SessionStateUtility.GetSessionStaticObjects(context), timeout);
                return sessionStateStoreData;
            }
        }
开发者ID:QuintSys,项目名称:Web.Providers.MongoDBSessionStateStore,代码行数:24,代码来源:Base64StringExtensions.cs


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