private async Task <CriticalSectionState> GetCriticalSectionStateAsync(int taskDefinitionId, CriticalSectionType criticalSectionType, SqlCommand command)
{
command.Parameters.Clear();
if (criticalSectionType == CriticalSectionType.User)
{
command.CommandText = TokensQueryBuilder.GetUserCriticalSectionStateQuery;
}
else
{
command.CommandText = TokensQueryBuilder.GetClientCriticalSectionStateQuery;
}
command.Parameters.Add("@TaskDefinitionId", SqlDbType.Int).Value = taskDefinitionId;
using (var reader = await command.ExecuteReaderAsync().ConfigureAwait(false))
{
var readSuccess = await reader.ReadAsync().ConfigureAwait(false);
if (readSuccess)
{
var csState = new CriticalSectionState();
csState.IsGranted = int.Parse(reader[GetCsStatusColumnName(criticalSectionType)].ToString()) == 0;
csState.GrantedToExecution = reader[GetGrantedToColumnName(criticalSectionType)].ToString();
csState.SetQueue(reader[GetQueueColumnName(criticalSectionType)].ToString());
csState.StartTrackingModifications();
return(csState);
}
}
throw new CriticalSectionException("No Task exists with id " + taskDefinitionId);
}