public async Task <SessionItem> GetSessionStateItemAsync(string id, bool exclusive) { TimeSpan lockAge = TimeSpan.Zero; DateTime utcNow = DateTime.UtcNow; byte[] buf = (byte[])null; SessionStateActions actions = SessionStateActions.None; NpgsqlCommand cmd = (NpgsqlCommand)null; cmd = !exclusive?this._commandHelper.CreateGetStateItemCmd(PostgresSessionStateRepository.GetStateItemSql, id) : this._commandHelper.CreateGetStateItemExclusiveCmd(PostgresSessionStateRepository.GetStateItemExclusiveSql, id); using (NpgsqlConnection connection = new NpgsqlConnection(this._connectString)) { NpgsqlDataReader reader = (NpgsqlDataReader)await SqlSessionStateRepositoryUtil.SqlExecuteReaderWithRetryAsync(connection, cmd, new Func <RetryCheckParameter, bool>(this.CanRetry), CommandBehavior.Default); int lockId = 0; try { if (reader.ReadAsync().Result) { buf = (byte[])reader["sessionitemlong"]; actions = (SessionStateActions)reader["flags"]; lockId = (int)reader["lockcookie"]; //lockAge = 0; } } finally { if (reader != null) { reader.Dispose(); } } reader = (NpgsqlDataReader)null; // NpgsqlParameter putParameterValue = cmd.GetOutPutParameterValue(SqlParameterName.Locked); // if (putParameterValue == null || Convert.IsDBNull(putParameterValue.Value)) // return (SessionItem)null; // int num = (bool)putParameterValue.Value ? 1 : 0; //// object lockId = (object)(int)cmd.GetOutPutParameterValue(SqlParameterName.LockCookie).Value; // if (num != 0) // { // lockAge = new TimeSpan(0, 0, (int)cmd.GetOutPutParameterValue(SqlParameterName.LockAge).Value); // if (lockAge > new TimeSpan(0, 0, 31536000)) // lockAge = TimeSpan.Zero; // return new SessionItem((byte[])null, true, lockAge, lockId, actions); // } // actions = (SessionStateActions)cmd.GetOutPutParameterValue(SqlParameterName.ActionFlags).Value; // if (buf == null) // buf = (byte[])cmd.GetOutPutParameterValue(SqlParameterName.SessionItemLong).Value; return(new SessionItem(buf, true, lockAge, lockId, actions)); } }
public async Task <SessionItem> GetSessionStateItemAsync(string id, bool exclusive) { TimeSpan lockAge = TimeSpan.Zero; DateTime utcNow = DateTime.UtcNow; byte[] buf = (byte[])null; SessionStateActions actions = SessionStateActions.None; NpgsqlCommand cmd = (NpgsqlCommand)null; cmd = !exclusive?this._commandHelper.CreateGetStateItemCmd(SqlInMemoryTableSessionStateRepository.GetStateItemSql, id) : this._commandHelper.CreateGetStateItemExclusiveCmd(SqlInMemoryTableSessionStateRepository.GetStateItemExclusiveSql, id); using (NpgsqlConnection connection = new NpgsqlConnection(this._connectString)) { SqlDataReader reader = (SqlDataReader)await SqlSessionStateRepositoryUtil.SqlExecuteReaderWithRetryAsync(connection, cmd, new Func <RetryCheckParameter, bool>(this.CanRetry), CommandBehavior.Default); try { if (reader.ReadAsync().Result) { buf = (byte[])await(Task <byte[]>) reader.GetFieldValueAsync <byte[]>(0); } } finally { if (reader != null) { reader.Dispose(); } } reader = (SqlDataReader)null; NpgsqlParameter putParameterValue = cmd.GetOutPutParameterValue(SqlParameterName.Locked); if (putParameterValue == null || Convert.IsDBNull(putParameterValue.Value)) { return((SessionItem)null); } int num = (bool)putParameterValue.Value ? 1 : 0; object lockId = (object)(int)cmd.GetOutPutParameterValue(SqlParameterName.LockCookie).Value; if (num != 0) { lockAge = new TimeSpan(0, 0, (int)cmd.GetOutPutParameterValue(SqlParameterName.LockAge).Value); if (lockAge > new TimeSpan(0, 0, 31536000)) { lockAge = TimeSpan.Zero; } return(new SessionItem((byte[])null, true, lockAge, lockId, actions)); } actions = (SessionStateActions)cmd.GetOutPutParameterValue(SqlParameterName.ActionFlags).Value; return(new SessionItem(buf, true, lockAge, lockId, actions)); } }