public ObjectBlock <T> GetLastObjectBlock <T>(LastBlockRequest lastRangeBlockRequest) { var taskDefinition = _taskRepository.EnsureTaskDefinition(lastRangeBlockRequest.TaskId); try { using (var connection = CreateNewConnection(lastRangeBlockRequest.TaskId)) { var command = connection.CreateCommand(); command.CommandText = ObjectBlockQueryBuilder.GetLastObjectBlock; command.CommandTimeout = ConnectionStore.Instance.GetConnection(lastRangeBlockRequest.TaskId).QueryTimeoutSeconds; command.Parameters.Add("@TaskDefinitionId", SqlDbType.Int).Value = taskDefinition.TaskDefinitionId; using (var reader = command.ExecuteReader()) { while (reader.Read()) { var blockId = reader["BlockId"].ToString(); var objectDataXml = reader["ObjectData"].ToString(); T objectData = SerializedValueReader.ReadValue <T>(reader, "ObjectData", "CompressedObjectData"); return(new ObjectBlock <T>() { Object = objectData, ObjectBlockId = blockId }); } } } } catch (SqlException sqlEx) { if (TransientErrorDetector.IsTransient(sqlEx)) { throw new TransientException("A transient exception has occurred", sqlEx); } throw; } return(null); }
public async Task <ProtoListBlock> GetLastListBlockAsync(LastBlockRequest lastRangeBlockRequest) { var taskDefinition = await _taskRepository.EnsureTaskDefinitionAsync(lastRangeBlockRequest.TaskId).ConfigureAwait(false); try { using (var connection = await CreateNewConnectionAsync(lastRangeBlockRequest.TaskId).ConfigureAwait(false)) { var command = connection.CreateCommand(); command.CommandText = ListBlockQueryBuilder.GetLastListBlock; command.CommandTimeout = ConnectionStore.Instance.GetConnection(lastRangeBlockRequest.TaskId).QueryTimeoutSeconds; command.Parameters.Add("@TaskDefinitionId", SqlDbType.Int).Value = taskDefinition.TaskDefinitionId; using (var reader = await command.ExecuteReaderAsync().ConfigureAwait(false)) { while (await reader.ReadAsync().ConfigureAwait(false)) { var listBlock = new ProtoListBlock(); listBlock.ListBlockId = reader["BlockId"].ToString(); listBlock.Items = await GetListBlockItemsAsync(lastRangeBlockRequest.TaskId, listBlock.ListBlockId).ConfigureAwait(false); listBlock.Header = SerializedValueReader.ReadValueAsString(reader, "ObjectData", "CompressedObjectData"); return(listBlock); } } } } catch (SqlException sqlEx) { if (TransientErrorDetector.IsTransient(sqlEx)) { throw new TransientException("A transient exception has occurred", sqlEx); } throw; } return(null); }
public async Task <IList <ProtoListBlockItem> > GetListBlockItemsAsync(TaskId taskId, string listBlockId) { var results = new List <ProtoListBlockItem>(); try { using (var connection = await CreateNewConnectionAsync(taskId).ConfigureAwait(false)) { var command = connection.CreateCommand(); command.CommandText = ListBlockQueryBuilder.GetListBlockItems; command.CommandTimeout = ConnectionStore.Instance.GetConnection(taskId).QueryTimeoutSeconds; command.Parameters.Add("@BlockId", SqlDbType.BigInt).Value = long.Parse(listBlockId); using (var reader = await command.ExecuteReaderAsync().ConfigureAwait(false)) { while (await reader.ReadAsync().ConfigureAwait(false)) { var listBlock = new ProtoListBlockItem(); listBlock.ListBlockItemId = reader["ListBlockItemId"].ToString(); listBlock.Value = SerializedValueReader.ReadValueAsString(reader, "Value", "CompressedValue"); listBlock.Status = (ItemStatus)int.Parse(reader["Status"].ToString()); if (reader["LastUpdated"] == DBNull.Value) { listBlock.LastUpdated = DateTime.MinValue; } else { listBlock.LastUpdated = reader.GetDateTime(5); } if (reader["StatusReason"] == DBNull.Value) { listBlock.StatusReason = null; } else { listBlock.StatusReason = reader.GetString(6); } if (reader["Step"] == DBNull.Value) { listBlock.Step = null; } else { listBlock.Step = reader.GetByte(7); } results.Add(listBlock); } } } } catch (SqlException sqlEx) { if (TransientErrorDetector.IsTransient(sqlEx)) { throw new TransientException("A transient exception has occurred", sqlEx); } throw; } return(results); }