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