本文整理汇总了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);
}
示例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);
}
示例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;
}
示例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;
}
}
示例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;
}
}
示例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;
}
示例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);
}
示例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;
}
示例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();
}
示例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));
}
示例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));
}
}
示例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();
}
示例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;
}
}