Ejemplo n.º 1
0
        /// <inheritdoc />
        public IDictionary <string, object> Handle(GetHeaderQuery query)
        {
            using (var connection = _connectionFactory.Create())
            {
                connection.Open();
                using (var command = connection.CreateCommand())
                {
                    _prepareQuery.Handle(query, command, CommandStringTypes.GetHeader);
                    using (var reader = command.ExecuteReader())
                    {
                        if (!reader.Read())
                        {
                            return(null);
                        }
                        var headerRaw = _readColumn.ReadAsByteArray(CommandStringTypes.GetHeader, 0, reader);
                        if (headerRaw != null)
                        {
                            return(_serialization.InternalSerializer
                                   .ConvertBytesTo <IDictionary <string, object> >(
                                       headerRaw));
                        }
                    }
                }
            }

            return(null);
        }
 /// <inheritdoc />
 public bool Handle(GetTableExistsTransactionQuery query)
 {
     using (var command = query.Connection.CreateCommand())
     {
         command.Transaction = query.Trans;
         _prepareQuery.Handle(query, command, CommandStringTypes.GetTableExists);
         using (var reader = command.ExecuteReader())
         {
             return(reader.Read());
         }
     }
 }
        public IEnumerable <MessageToReset <T> > Handle(FindMessagesToResetByHeartBeatQuery <T> query)
        {
            var results = new List <MessageToReset <T> >();

            if (query.Cancellation.IsCancellationRequested)
            {
                return(results);
            }

            using (var connection = _dbConnectionFactory.Create())
            {
                connection.Open();

                //before executing a query, double check that we aren't stopping
                //otherwise, there is a chance that the tables no longer exist in memory mode
                if (query.Cancellation.IsCancellationRequested)
                {
                    return(results);
                }

                using (var command = connection.CreateCommand())
                {
                    _prepareQuery.Handle(query, command, CommandStringTypes.GetHeartBeatExpiredMessageIds);
                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            if (query.Cancellation.IsCancellationRequested)
                            {
                                break;
                            }

                            var headers = _readColumn.ReadAsByteArray(CommandStringTypes.GetHeartBeatExpiredMessageIds, 2,
                                                                      reader);
                            if (headers != null)
                            {
                                var allheaders = _serialization.InternalSerializer.ConvertBytesTo <IDictionary <string, object> >(headers);
                                results.Add(new MessageToReset <T>(_readColumn.ReadAsType <T>(CommandStringTypes.GetHeartBeatExpiredMessageIds, 0, reader), _readColumn.ReadAsDateTime(CommandStringTypes.GetHeartBeatExpiredMessageIds, 1, reader), new ReadOnlyDictionary <string, object>(allheaders)));
                            }
                            else
                            {
                                results.Add(new MessageToReset <T>(_readColumn.ReadAsType <T>(CommandStringTypes.GetHeartBeatExpiredMessageIds, 0, reader), _readColumn.ReadAsDateTime(CommandStringTypes.GetHeartBeatExpiredMessageIds, 1, reader), null));
                            }
                        }
                    }
                }
            }
            return(results);
        }
 public bool Handle(GetErrorRecordExistsQuery <T> query)
 {
     using (var connection = _connectionFactory.Create())
     {
         connection.Open();
         using (var command = connection.CreateCommand())
         {
             _prepareQuery.Handle(query, command, CommandStringTypes.GetErrorRecordExists);
             using (var reader = command.ExecuteReader())
             {
                 return(reader.Read());
             }
         }
     }
 }
 /// <inheritdoc />
 public DateTimeOffset Handle(GetJobLastKnownEventQuery query)
 {
     using (var connection = _dbConnectionFactory.Create())
     {
         connection.Open();
         using (var command = connection.CreateCommand())
         {
             _prepareQuery.Handle(query, command, CommandStringTypes.GetJobLastKnownEvent);
             using (var reader = command.ExecuteReader())
             {
                 return(reader.Read() ? _readColumn.ReadAsDateTimeOffset(CommandStringTypes.GetJobLastKnownEvent, 0, reader) : default(DateTimeOffset));
             }
         }
     }
 }
Ejemplo n.º 6
0
 /// <inheritdoc />
 public T Handle(GetJobIdQuery <T> query)
 {
     using (var connection = _dbConnectionFactory.Create())
     {
         connection.Open();
         using (var command = connection.CreateCommand())
         {
             _prepareQuery.Handle(query, command, CommandStringTypes.GetJobId);
             using (var reader = command.ExecuteReader())
             {
                 if (reader.Read())
                 {
                     return(_readColumn.ReadAsType <T>(CommandStringTypes.GetJobId, 0, reader));
                 }
             }
         }
     }
     return(default);
Ejemplo n.º 7
0
 /// <inheritdoc />
 public long Handle(GetJobIdQuery query)
 {
     using (var connection = _dbConnectionFactory.Create())
     {
         connection.Open();
         using (var command = connection.CreateCommand())
         {
             _prepareQuery.Handle(query, command, CommandStringTypes.GetJobId);
             using (var reader = command.ExecuteReader())
             {
                 if (reader.Read())
                 {
                     return(_readColumn.ReadAsInt64(CommandStringTypes.GetJobId, 0, reader, -1));
                 }
             }
         }
     }
     return(-1);
 }
 /// <inheritdoc />
 public DateTime Handle(GetUtcDateQuery query)
 {
     using (var connection = _dbConnectionFactory.Create())
     {
         connection.Open();
         using (var command = connection.CreateCommand())
         {
             _prepareQuery.Handle(query, command, CommandStringTypes.GetUtcDate);
             using (var reader = command.ExecuteReader())
             {
                 if (reader.Read())
                 {
                     return(_readColumn.ReadAsDateTime(CommandStringTypes.GetUtcDate, 0, reader));
                 }
                 throw new DotNetWorkQueueException("Failed to obtain the UTC date from the server");
             }
         }
     }
 }
Ejemplo n.º 9
0
 /// <inheritdoc />
 public int Handle(GetErrorRetryCountQuery <T> query)
 {
     using (var connection = _connectionFactory.Create())
     {
         connection.Open();
         using (var command = connection.CreateCommand())
         {
             _prepareQuery.Handle(query, command, CommandStringTypes.GetErrorRetryCount);
             using (var reader = command.ExecuteReader())
             {
                 if (reader.Read())
                 {
                     return(_readColumn.ReadAsInt32(CommandStringTypes.GetErrorRetryCount, 0, reader));
                 }
             }
         }
     }
     return(0);
 }
Ejemplo n.º 10
0
        public IEnumerable <T> Handle(FindExpiredMessagesToDeleteQuery <T> query)
        {
            if (query.Cancellation.IsCancellationRequested)
            {
                return(Enumerable.Empty <T>());
            }

            var results     = new List <T>();
            var commandType = _options.Value.EnableStatus
                ? CommandStringTypes.FindExpiredRecordsWithStatusToDelete
                : CommandStringTypes.FindExpiredRecordsToDelete;

            using (var connection = _dbConnectionFactory.Create())
            {
                connection.Open();

                //before executing a query, double check that we aren't stopping
                //otherwise, there is a chance that the tables no longer exist in memory mode
                if (query.Cancellation.IsCancellationRequested)
                {
                    return(Enumerable.Empty <T>());
                }

                using (var command = connection.CreateCommand())
                {
                    _prepareQuery.Handle(query, command, commandType);
                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            if (query.Cancellation.IsCancellationRequested)
                            {
                                break;
                            }
                            results.Add(_readColumn.ReadAsType <T>(commandType, 0, reader));
                        }
                    }
                }
            }
            return(results);
        }
        private QueueStatuses RunQuery(DoesJobExistQuery <TConnection, TTransaction> query, IDbConnection connection, IDbTransaction transaction)
        {
            var returnStatus = QueueStatuses.NotQueued;

            using (var command = connection.CreateCommand())
            {
                command.Transaction = transaction;
                _prepareQuery.Handle(query, command, CommandStringTypes.DoesJobExist);
                using (var reader = command.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        returnStatus =
                            (QueueStatuses)_readColumn.ReadAsInt32(CommandStringTypes.DoesJobExist, 0, reader);
                    }
                }

                if (returnStatus == QueueStatuses.NotQueued &&
                    _tableExists.Handle(new GetTableExistsQuery(_connectionInformation.ConnectionString,
                                                                _tableNameHelper.JobTableName)))
                {
                    command.CommandText =
                        _commandCache.GetCommand(CommandStringTypes.GetJobLastScheduleTime);
                    command.Transaction = transaction;
                    using (var reader = command.ExecuteReader())
                    {
                        if (!reader.Read())
                        {
                            return(returnStatus);
                        }
                        var scheduleTime =
                            _readColumn.ReadAsDateTimeOffset(CommandStringTypes.GetJobLastScheduleTime, 0, reader);
                        if (scheduleTime == query.ScheduledTime)
                        {
                            return(QueueStatuses.Processed);
                        }
                    }
                }
            }
            return(returnStatus);
        }
Ejemplo n.º 12
0
        public List <string> Handle(GetColumnNamesFromTableQuery query)
        {
            var columns = new List <string>();

            using (var connection = _dbConnectionFactory.Create())
            {
                connection.Open();
                using (var command = connection.CreateCommand())
                {
                    _prepareQuery.Handle(query, command, CommandStringTypes.GetColumnNamesFromTable);
                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            columns.Add(_readColumn.ReadAsString(CommandStringTypes.GetColumnNamesFromTable, 0, reader));
                        }
                    }
                }
            }
            return(columns);
        }
Ejemplo n.º 13
0
        public TTransportOptions Handle(GetQueueOptionsQuery <TTransportOptions> query)
        {
            if (!_tableExists.Handle(new GetTableExistsQuery(_connectionInformation.ConnectionString,
                                                             _tableNameHelper.ConfigurationName)))
            {
                return(null);
            }

            using (var conn = _dbConnectionFactory.Create())
            {
                conn.Open();
                using (var command = conn.CreateCommand())
                {
                    _prepareQuery.Handle(query, command, CommandStringTypes.GetConfiguration);
                    using (var reader = command.ExecuteReader())
                    {
                        return(!reader.Read() ? null : _serializer.ConvertBytesTo <TTransportOptions>(_readColumn.ReadAsByteArray(CommandStringTypes.GetConfiguration, 0, reader)));
                    }
                }
            }
        }
        /// <inheritdoc />
        public IEnumerable <long> Handle(FindErrorMessagesToDeleteQuery query)
        {
            if (query.Cancellation.IsCancellationRequested)
            {
                return(Enumerable.Empty <long>());
            }

            var results = new List <long>();

            using (var connection = _dbConnectionFactory.Create())
            {
                connection.Open();

                //before executing a query, double check that we aren't stopping
                //otherwise, there is a chance that the tables no longer exist in memory mode
                if (query.Cancellation.IsCancellationRequested)
                {
                    return(Enumerable.Empty <long>());
                }

                using (var command = connection.CreateCommand())
                {
                    _prepareQuery.Handle(query, command, CommandStringTypes.FindErrorRecordsToDelete);
                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            if (query.Cancellation.IsCancellationRequested)
                            {
                                break;
                            }
                            results.Add(_readColumn.ReadAsInt64(CommandStringTypes.FindErrorRecordsToDelete, 0, reader));
                        }
                    }
                }
            }
            return(results);
        }
        public IEnumerable <MessageToReset> Handle(FindMessagesToResetByHeartBeatQuery query)
        {
            var results = new List <MessageToReset>();

            if (query.Cancellation.IsCancellationRequested)
            {
                return(results);
            }

            using (var connection = _dbConnectionFactory.Create())
            {
                connection.Open();

                //before executing a query, double check that we aren't stopping
                //otherwise, there is a chance that the tables no longer exist in memory mode
                if (query.Cancellation.IsCancellationRequested)
                {
                    return(results);
                }

                using (var command = connection.CreateCommand())
                {
                    _prepareQuery.Handle(query, command, CommandStringTypes.GetHeartBeatExpiredMessageIds);
                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            if (query.Cancellation.IsCancellationRequested)
                            {
                                break;
                            }
                            results.Add(new MessageToReset(_readColumn.ReadAsInt64(CommandStringTypes.GetHeartBeatExpiredMessageIds, 0, reader), _readColumn.ReadAsDateTime(CommandStringTypes.GetHeartBeatExpiredMessageIds, 1, reader)));
                        }
                    }
                }
            }
            return(results);
        }
        /// <inheritdoc />
        public Dictionary <string, int> Handle(GetMessageErrorsQuery <T> query)
        {
            var returnData = new Dictionary <string, int>();

            using (var connection = _connectionFactory.Create())
            {
                connection.Open();
                using (var command = connection.CreateCommand())
                {
                    _prepareQuery.Handle(query, command, CommandStringTypes.GetMessageErrors);
                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var errorType = _readColumn.ReadAsString(CommandStringTypes.GetMessageErrors, 0, reader).Trim();
                            var count     = _readColumn.ReadAsInt32(CommandStringTypes.GetMessageErrors, 1, reader);
                            returnData.Add(errorType, count);
                        }
                    }
                }
            }

            return(returnData);
        }
 /// <inheritdoc />
 public void Handle(GetTableExistsQuery query, IDbCommand dbCommand, CommandStringTypes commandType)
 {
     //table name needs to be lower case
     _decorated.Handle(new GetTableExistsQuery(query.ConnectionString, query.TableName.ToLowerInvariant()), dbCommand, commandType);
 }