public override void CreateUninitializedItem(HttpContext context, string id, int timeout) { var riakSessionItem = new RiakSessionItem { SessionContainer = ApplicationName, SessionId = id, Created = DateTime.Now, Timeout = timeout }; _client.Async.Put(riakSessionItem.ToRiakObject(), result => { return; }); return; }
private SessionStateStoreData GetSessionStoreItem(bool lockRecord, HttpContext context, string id, out bool locked, out TimeSpan lockAge, out object lockId, out SessionStateActions actions) { SessionStateStoreData result = null; locked = default(bool); lockAge = default(TimeSpan); lockId = null; actions = default(SessionStateActions); var riakResult = _client.Get(ApplicationName, id); if (riakResult.IsSuccess) { var riakObject = riakResult.Value; var riakSessionItem = new RiakSessionItem(riakObject); locked = riakSessionItem.Locked; lockAge = DateTime.Now.Subtract(riakSessionItem.LockDate); lockId = riakSessionItem.LockId; actions = (SessionStateActions) riakSessionItem.Flags; if (riakSessionItem.Expires < DateTime.Now || riakSessionItem.Locked) return null; if (actions == SessionStateActions.InitializeItem) { result = CreateNewStoreData(context, riakSessionItem.Timeout); } else { result = Deserialize(riakSessionItem.SessionStoreItems); } if (lockRecord) { riakSessionItem.Locked = true; _client.Async.Put(riakSessionItem.ToRiakObject(), results => { return; }); } } return result; }
public override void ResetItemTimeout(HttpContext context, string id) { var result = _client.Get(ApplicationName, id); var riakSessionItem = new RiakSessionItem(result.Value) {Timeout = _config.Timeout.Minutes}; riakSessionItem.ResetTimeout(); _client.Async.Put(riakSessionItem.ToRiakObject(), results => { return; }); }
public override void SetAndReleaseItemExclusive(HttpContext context, string id, SessionStateStoreData item, object lockId, bool newItem) { if (newItem) { var riakSessionItem = new RiakSessionItem { SessionStoreItems = Serialize(item) }; _client.Put(riakSessionItem.ToRiakObject()); } else { var result = _client.Get(ApplicationName, id); var riakSessionItem = new RiakSessionItem(); if (result.ResultCode != ResultCode.NotFound) { riakSessionItem = new RiakSessionItem(result.Value) {Flags = 0}; riakSessionItem.Unlock(); } else { riakSessionItem.SessionId = id; riakSessionItem.SessionContainer = ApplicationName; } riakSessionItem.Created = DateTime.Now; riakSessionItem.Timeout = item.Timeout; riakSessionItem.SessionStoreItems = Serialize(item); _client.Async.Put(riakSessionItem.ToRiakObject(), results => { return; }); } }
public override void ReleaseItemExclusive(HttpContext context, string id, object lockId) { var riakObject = _client.Get(ApplicationName, id).Value; var riakSessionItem = new RiakSessionItem(riakObject) {Timeout = _config.Timeout.Minutes}; if (riakSessionItem.LockId == (int)lockId) { riakSessionItem.ResetTimeout(); _client.Async.Put(riakSessionItem.ToRiakObject(), result => { return; }); } }