Esempio n. 1
0
        private LastBlockRequest CreateRequest(LastBlockOrder lastBlockOrder)
        {
            var request = new LastBlockRequest(new TaskId(TestConstants.ApplicationName, TestConstants.TaskName), BlockType.NumericRange);

            request.LastBlockOrder = lastBlockOrder;

            return(request);
        }
Esempio n. 2
0
        private LastBlockRequest CreateRequest()
        {
            var request = new LastBlockRequest(new TaskId(TestConstants.ApplicationName, TestConstants.TaskName), BlockType.Object);

            request.LastBlockOrder = LastBlockOrder.LastCreated;

            return(request);
        }
Esempio n. 3
0
        public IListBlock <T> GetLastListBlock <T>(LastBlockRequest lastBlockRequest)
        {
            var lastProtoListBlock = _listBlockRepository.GetLastListBlock(lastBlockRequest);

            if (lastProtoListBlock == null)
            {
                return(null);
            }

            return(Convert <T>(lastProtoListBlock, true));
        }
Esempio n. 4
0
        public async Task <IListBlock <T> > GetLastListBlockAsync <T>(LastBlockRequest lastBlockRequest)
        {
            var lastProtoListBlock = await _listBlockRepository.GetLastListBlockAsync(lastBlockRequest).ConfigureAwait(false);

            if (lastProtoListBlock == null)
            {
                return(null);
            }

            return(Convert <T>(lastProtoListBlock, true));
        }
Esempio n. 5
0
        public IObjectBlock <T> GetLastObjectBlock <T>()
        {
            if (!IsExecutionContextActive)
            {
                throw new ExecutionException(NotActiveMessage);
            }

            var request = new LastBlockRequest(new TaskId(_taskExecutionInstance.ApplicationName, _taskExecutionInstance.TaskName),
                                               BlockType.Object);

            return(_objectBlockRepository.GetLastObjectBlock <T>(request));
        }
Esempio n. 6
0
        public IListBlock <TItem, THeader> GetLastListBlock <TItem, THeader>()
        {
            if (!IsExecutionContextActive)
            {
                throw new ExecutionException(NotActiveMessage);
            }

            var request = new LastBlockRequest(new TaskId(_taskExecutionInstance.ApplicationName, _taskExecutionInstance.TaskName),
                                               BlockType.List);

            return(_blockFactory.GetLastListBlock <TItem, THeader>(request));
        }
        public async Task <IObjectBlock <T> > GetLastObjectBlockAsync <T>()
        {
            if (!IsExecutionContextActive)
            {
                throw new ExecutionException(NotActiveMessage);
            }

            var request = new LastBlockRequest(new TaskId(_taskExecutionInstance.ApplicationName, _taskExecutionInstance.TaskName),
                                               BlockType.Object);

            return(await _objectBlockRepository.GetLastObjectBlockAsync <T>(request).ConfigureAwait(false));
        }
Esempio n. 8
0
        public INumericRangeBlock GetLastNumericRangeBlock(LastBlockOrder lastBlockOrder)
        {
            if (!IsExecutionContextActive)
            {
                throw new ExecutionException(NotActiveMessage);
            }

            var request = new LastBlockRequest(new TaskId(_taskExecutionInstance.ApplicationName, _taskExecutionInstance.TaskName),
                                               BlockType.NumericRange);

            request.LastBlockOrder = lastBlockOrder;

            return(_rangeBlockRepository.GetLastRangeBlock(request));
        }
        public async Task <INumericRangeBlock> GetLastNumericRangeBlockAsync(LastBlockOrder lastBlockOrder)
        {
            if (!IsExecutionContextActive)
            {
                throw new ExecutionException(NotActiveMessage);
            }

            var request = new LastBlockRequest(new TaskId(_taskExecutionInstance.ApplicationName, _taskExecutionInstance.TaskName),
                                               BlockType.NumericRange);

            request.LastBlockOrder = lastBlockOrder;

            return(await _rangeBlockRepository.GetLastRangeBlockAsync(request).ConfigureAwait(false));
        }
Esempio n. 10
0
        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);
        }
Esempio n. 11
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. 12
0
        public async Task <RangeBlock> GetLastRangeBlockAsync(LastBlockRequest lastRangeBlockRequest)
        {
            var taskDefinition = await _taskRepository.EnsureTaskDefinitionAsync(lastRangeBlockRequest.TaskId).ConfigureAwait(false);

            var query = string.Empty;

            if (lastRangeBlockRequest.BlockType == BlockType.DateRange)
            {
                query = RangeBlockQueryBuilder.GetLastDateRangeBlock(lastRangeBlockRequest.LastBlockOrder);
            }
            else if (lastRangeBlockRequest.BlockType == BlockType.NumericRange)
            {
                query = RangeBlockQueryBuilder.GetLastNumericRangeBlock(lastRangeBlockRequest.LastBlockOrder);
            }
            else
            {
                throw new ArgumentException("An invalid BlockType was supplied: " + lastRangeBlockRequest.BlockType);
            }

            try
            {
                using (var connection = await CreateNewConnectionAsync(lastRangeBlockRequest.TaskId).ConfigureAwait(false))
                {
                    var command = connection.CreateCommand();
                    command.CommandText    = query;
                    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  rangeBlockId = reader["BlockId"].ToString();
                            long rangeBegin;
                            long rangeEnd;

                            if (lastRangeBlockRequest.BlockType == BlockType.DateRange)
                            {
                                rangeBegin = reader.GetDateTime(2).Ticks; //DateTime.Parse(reader["FromDate"].ToString()).Ticks;
                                rangeEnd   = reader.GetDateTime(3).Ticks; //DateTime.Parse(reader["ToDate"].ToString()).Ticks;
                            }
                            else
                            {
                                rangeBegin = long.Parse(reader["FromNumber"].ToString());
                                rangeEnd   = long.Parse(reader["ToNumber"].ToString());
                            }

                            return(new RangeBlock(rangeBlockId, 0, rangeBegin, rangeEnd, lastRangeBlockRequest.BlockType));
                        }
                    }
                }
            }
            catch (SqlException sqlEx)
            {
                if (TransientErrorDetector.IsTransient(sqlEx))
                {
                    throw new TransientException("A transient exception has occurred", sqlEx);
                }

                throw;
            }

            return(null);
        }
Esempio n. 13
0
        public IListBlock <TItem, THeader> GetLastListBlock <TItem, THeader>(LastBlockRequest lastBlockRequest)
        {
            var lastProtoListBlock = _listBlockRepository.GetLastListBlock(lastBlockRequest);

            return(Convert <TItem, THeader>(lastProtoListBlock, true));
        }
Esempio n. 14
0
        public async Task <IListBlock <TItem, THeader> > GetLastListBlockAsync <TItem, THeader>(LastBlockRequest lastBlockRequest)
        {
            var lastProtoListBlock = await _listBlockRepository.GetLastListBlockAsync(lastBlockRequest).ConfigureAwait(false);

            return(Convert <TItem, THeader>(lastProtoListBlock, true));
        }