Ejemplo n.º 1
0
 protected IListBlockItem <TItem> Convert(ProtoListBlockItem listBlockItem)
 {
     return(new ListBlockItem <TItem>()
     {
         LastUpdated = listBlockItem.LastUpdated,
         ListBlockItemId = listBlockItem.ListBlockItemId,
         Status = listBlockItem.Status,
         StatusReason = listBlockItem.StatusReason,
         Step = listBlockItem.Step,
         Value = JsonGenericSerializer.Deserialize <TItem>(listBlockItem.Value)
     });
 }
Ejemplo n.º 2
0
        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);
        }