Esempio n. 1
0
        private ListBlock <T> Convert <T>(ProtoListBlock protoListBlock, bool fillBlock = false)
        {
            if (protoListBlock == null)
            {
                return(null);
            }

            var block = new ListBlock <T>();

            block.Attempt = protoListBlock.Attempt;

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

            block.ListBlockId = protoListBlock.ListBlockId;

            return(block);
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        private IListBlockContext <TItem, THeader> CreateListBlockContext <TItem, THeader>(ListBlockRequest blockRequest, ProtoListBlock listBlock, int forcedBlockQueueId = 0)
        {
            var attempt       = listBlock.Attempt + 1;
            var createRequest = new BlockExecutionCreateRequest(new TaskId(blockRequest.ApplicationName, blockRequest.TaskName),
                                                                blockRequest.TaskExecutionId,
                                                                blockRequest.BlockType,
                                                                listBlock.ListBlockId,
                                                                attempt);

            var blockExecutionId = _blockRepository.AddListBlockExecution(createRequest);

            var listBlockOfT = Convert <TItem, THeader>(listBlock);
            var blockContext = new ListBlockContext <TItem, THeader>(_listBlockRepository,
                                                                     _taskExecutionRepository,
                                                                     blockRequest.ApplicationName,
                                                                     blockRequest.TaskName,
                                                                     blockRequest.TaskExecutionId,
                                                                     blockRequest.ListUpdateMode,
                                                                     blockRequest.UncommittedItemsThreshold,
                                                                     listBlockOfT,
                                                                     blockExecutionId,
                                                                     blockRequest.MaxStatusReasonLength,
                                                                     forcedBlockQueueId.ToString());

            return(blockContext);
        }
Esempio n. 5
0
        private async Task <IListBlockContext <T> > CreateListBlockContextAsync <T>(ListBlockRequest blockRequest, ProtoListBlock listBlock, int forcedBlockQueueId = 0)
        {
            var attempt       = listBlock.Attempt + 1;
            var createRequest = new BlockExecutionCreateRequest(new TaskId(blockRequest.ApplicationName, blockRequest.TaskName),
                                                                blockRequest.TaskExecutionId,
                                                                BlockType.List,
                                                                listBlock.ListBlockId,
                                                                attempt);

            var blockExecutionId = await _blockRepository.AddListBlockExecutionAsync(createRequest).ConfigureAwait(false);

            var listBlockOfT = Convert <T>(listBlock);
            var blockContext = new ListBlockContext <T>(_listBlockRepository,
                                                        _taskExecutionRepository,
                                                        blockRequest.ApplicationName,
                                                        blockRequest.TaskName,
                                                        blockRequest.TaskExecutionId,
                                                        blockRequest.ListUpdateMode,
                                                        blockRequest.UncommittedItemsThreshold,
                                                        listBlockOfT,
                                                        blockExecutionId,
                                                        blockRequest.MaxStatusReasonLength,
                                                        forcedBlockQueueId.ToString());

            return(blockContext);
        }