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 ThenReturnLastCreated()
        {
            // ARRANGE
            InsertBlocks();

            // ACT
            var sut   = CreateSut();
            var block = await sut.GetLastListBlockAsync(CreateRequest());

            // ASSERT
            Assert.Equal(_block5, block.ListBlockId);
            Assert.Equal(new DateTime(2016, 1, 1).AddMinutes(-60), JsonGenericSerializer.Deserialize <DateRange>(block.Header).FromDate);
            Assert.Equal(new DateTime(2016, 1, 1), JsonGenericSerializer.Deserialize <DateRange>(block.Header).ToDate);
        }
Ejemplo n.º 3
0
        public TaskExecutionMeta <TExecutionHeader> GetLastExecutionMeta <TExecutionHeader>()
        {
            var request = CreateTaskExecutionMetaRequest(1);

            var response = _taskExecutionRepository.GetLastExecutionMetas(request);

            if (response.Executions != null && response.Executions.Any())
            {
                var meta = response.Executions.First();
                return(new TaskExecutionMeta <TExecutionHeader>(meta.StartedAt,
                                                                meta.CompletedAt,
                                                                meta.Status,
                                                                JsonGenericSerializer.Deserialize <TExecutionHeader>(meta.Header, true),
                                                                meta.ReferenceValue));
            }

            return(null);
        }
Ejemplo n.º 4
0
        public static T ReadValue <T>(SqlDataReader reader, string valueColumn, string compressedColum)
        {
            if (reader[valueColumn] == DBNull.Value && reader[compressedColum] == DBNull.Value)
            {
                return(default(T));
            }
            else if (reader[valueColumn] != DBNull.Value)
            {
                return(JsonGenericSerializer.Deserialize <T>(reader[valueColumn].ToString()));
            }
            else if (reader[compressedColum] != DBNull.Value)
            {
                var compressedBytes  = (byte[])reader[compressedColum];
                var uncompressedText = LargeValueCompressor.Unzip(compressedBytes);
                return(JsonGenericSerializer.Deserialize <T>(uncompressedText));
            }

            throw new ExecutionException("The stored value is null which is not a valid state");
        }
Ejemplo n.º 5
0
        private ListBlock <TItem, THeader> Convert <TItem, THeader>(ProtoListBlock protoListBlock, bool fillBlock = false)
        {
            if (protoListBlock == null)
            {
                return(null);
            }

            var block = new ListBlock <TItem, THeader>();

            block.Attempt = protoListBlock.Attempt;

            if (fillBlock)
            {
                block.Items = Convert <TItem>(protoListBlock.Items);
            }

            block.ListBlockId = protoListBlock.ListBlockId;
            block.Header      = JsonGenericSerializer.Deserialize <THeader>(protoListBlock.Header);

            return(block);
        }
Ejemplo n.º 6
0
        private IList <IListBlockItem <T> > Convert <T>(IList <ProtoListBlockItem> protoListBlockItems)
        {
            if (protoListBlockItems == null)
            {
                return(null);
            }

            var items = new List <IListBlockItem <T> >();

            foreach (var protoItem in protoListBlockItems)
            {
                var item = new ListBlockItem <T>();
                item.LastUpdated     = protoItem.LastUpdated;
                item.ListBlockItemId = protoItem.ListBlockItemId;
                item.Status          = protoItem.Status;
                item.StatusReason    = protoItem.StatusReason;
                item.Step            = protoItem.Step;
                item.Value           = JsonGenericSerializer.Deserialize <T>(protoItem.Value);

                items.Add(item);
            }

            return(items);
        }
Ejemplo n.º 7
0
        public List <ListBlockItem <T> > GetListBlockItems <T>(string blockId, ItemStatus status)
        {
            var items = new List <ListBlockItem <T> >();

            using (var connection = new SqlConnection(TestConstants.TestConnectionString))
            {
                connection.Open();
                var command = connection.CreateCommand();
                command.CommandText = GetListBlockItemsQuery;
                command.Parameters.Add("@BlockId", SqlDbType.BigInt).Value = long.Parse(blockId);
                command.Parameters.Add("@Status", SqlDbType.TinyInt).Value = (byte)status;

                var reader = command.ExecuteReader();
                while (reader.Read())
                {
                    var item = new ListBlockItem <T>();
                    item.ListBlockItemId = reader.GetInt64(0).ToString();
                    item.Value           = JsonGenericSerializer.Deserialize <T>(reader.GetString(1));
                    item.Status          = (ItemStatus)reader.GetByte(2);

                    if (reader[4] != DBNull.Value)
                    {
                        item.StatusReason = reader.GetString(4);
                    }

                    if (reader[5] != DBNull.Value)
                    {
                        item.Step = reader.GetByte(5);
                    }

                    items.Add(item);
                }
            }

            return(items);
        }
Ejemplo n.º 8
0
        public IList <TaskExecutionMeta <TExecutionHeader> > GetLastExecutionMetas <TExecutionHeader>(int numberToRetrieve)
        {
            var request = CreateTaskExecutionMetaRequest(numberToRetrieve);

            var response = _taskExecutionRepository.GetLastExecutionMetas(request);

            if (response.Executions != null && response.Executions.Any())
            {
                return(response.Executions.Select(x => new TaskExecutionMeta <TExecutionHeader>(x.StartedAt,
                                                                                                x.CompletedAt,
                                                                                                x.Status,
                                                                                                JsonGenericSerializer.Deserialize <TExecutionHeader>(x.Header, true),
                                                                                                x.ReferenceValue))
                       .ToList());
            }

            return(new List <TaskExecutionMeta <TExecutionHeader> >());
        }