Exemplo n.º 1
0
 /// <inheritdoc />
 public virtual DateTimeOffset ReadAsDateTimeOffset(CommandStringTypes command, int column, IDataReader reader, DateTimeOffset noValue = default(DateTimeOffset))
 {
     ValidColumn(column, command);
     if (!reader.IsDBNull(column))
     {
         return((DateTimeOffset)reader[column]);
     }
     return(noValue);
 }
Exemplo n.º 2
0
 /// <inheritdoc />
 public virtual byte[] ReadAsByteArray(CommandStringTypes command, int column, IDataReader reader, byte[] noValue = null)
 {
     ValidColumn(column, command);
     if (!reader.IsDBNull(column))
     {
         return((byte[])reader[column]);
     }
     return(noValue);
 }
        /// <inheritdoc />
        public void Handle(GetMessageErrorsQuery <T> query, IDbCommand dbCommand, CommandStringTypes commandType)
        {
            dbCommand.CommandText = _commandCache.GetCommand(commandType);

            var queueid = dbCommand.CreateParameter();

            queueid.ParameterName = "@QueueID";
            queueid.DbType        = DbType.Int64; //WARN should be T
            queueid.Value         = query.QueueId;
            dbCommand.Parameters.Add(queueid);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Reads as date time.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <param name="column">The column, if known. -1 if the caller has no idea.</param>
        /// <param name="reader">The reader.</param>
        /// <param name="noValue"></param>
        /// <returns></returns>
        public override DateTime ReadAsDateTime(CommandStringTypes command, int column, IDataReader reader, DateTime noValue = default(DateTime))
        {
            switch (command)
            {
            case CommandStringTypes.GetHeartBeatExpiredMessageIds:
                return(DateTime.FromBinary(reader.GetInt64(column)));

            default:
                return(base.ReadAsDateTime(command, column, reader, noValue));
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Reads as string.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <param name="column">The column, if known. -1 if the caller has no idea.</param>
        /// <param name="reader">The reader.</param>
        /// <param name="noValue"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public override string ReadAsString(CommandStringTypes command, int column, IDataReader reader, string noValue = null)
        {
            switch (command)
            {
            case CommandStringTypes.GetColumnNamesFromTable:
                return(reader.GetString(1));    //sqlite puts column name in column 1, not 0

            default:
                return(base.ReadAsString(command, column, reader, noValue));
            }
        }
        /// <inheritdoc />
        public void Handle(GetJobIdQuery <T> query, IDbCommand dbCommand, CommandStringTypes commandType)
        {
            dbCommand.CommandText = _commandCache.GetCommand(commandType);
            var param = dbCommand.CreateParameter();

            param.ParameterName = "@JobName";
            param.Size          = 255;
            param.DbType        = DbType.AnsiString;
            param.Value         = query.JobName;
            dbCommand.Parameters.Add(param);
        }
Exemplo n.º 7
0
        /// <inheritdoc />
        public void Handle(GetHeaderQuery query, IDbCommand dbCommand, CommandStringTypes commandType)
        {
            dbCommand.CommandText = _commandCache.GetCommand(commandType);

            var queueid = dbCommand.CreateParameter();

            queueid.ParameterName = "@queueID";
            queueid.DbType        = DbType.Int64;
            queueid.Value         = query.Id;
            dbCommand.Parameters.Add(queueid);
        }
Exemplo n.º 8
0
        /// <inheritdoc />
        public void Handle(GetColumnNamesFromTableQuery query, IDbCommand dbCommand, CommandStringTypes commandType)
        {
            dbCommand.CommandText =
                _commandCache.GetCommand(commandType, query.TableName);

            var parameter = dbCommand.CreateParameter();

            parameter.ParameterName = "@TableName";
            parameter.DbType        = DbType.AnsiString;
            parameter.Value         = query.TableName;
            dbCommand.Parameters.Add(parameter);
        }
        /// <inheritdoc />
        public void Handle(DeleteMetaDataCommand command, IDbCommand dbCommand, CommandStringTypes commandType)
        {
            dbCommand.CommandText =
                _commandCache.GetCommand(CommandStringTypes.DeleteFromMetaData);

            var param = dbCommand.CreateParameter();

            param.ParameterName = "@QueueID";
            param.DbType        = DbType.Int64;
            param.Value         = command.QueueId;
            dbCommand.Parameters.Add(param);
        }
Exemplo n.º 10
0
 /// <inheritdoc />
 public void Handle(DeleteMessageCommand command, IDbCommand dbCommand, CommandStringTypes commandType)
 {
     //set ID if not set
     if (!dbCommand.Parameters.Contains("@QueueID"))
     {
         var param = dbCommand.CreateParameter();
         param.ParameterName = "@QueueID";
         param.DbType        = DbType.Int64;
         param.Value         = command.QueueId;
         dbCommand.Parameters.Add(param);
     }
     dbCommand.CommandText = _commandCache.GetCommand(commandType);
 }
Exemplo n.º 11
0
        /// <inheritdoc />
        public override DateTimeOffset ReadAsDateTimeOffset(CommandStringTypes command, int column, IDataReader reader, DateTimeOffset noValue = default)
        {
            switch (command)
            {
            case CommandStringTypes.DoesJobExist:
            case CommandStringTypes.GetJobLastKnownEvent:
            case CommandStringTypes.GetJobLastScheduleTime:
                return(new DateTimeOffset(new DateTime(reader.GetInt64(column), DateTimeKind.Utc)));

            default:
                return(base.ReadAsDateTimeOffset(command, column, reader, noValue));
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Reads as a date time offset
        /// </summary>
        /// <param name="command">The command.</param>
        /// <param name="column">The column, if known. -1 if the caller has no idea.</param>
        /// <param name="reader">The reader.</param>
        /// <param name="noValue"></param>
        /// <returns></returns>
        public override DateTimeOffset ReadAsDateTimeOffset(CommandStringTypes command, int column, IDataReader reader, DateTimeOffset noValue = default(DateTimeOffset))
        {
            switch (command)
            {
            case CommandStringTypes.DoesJobExist:
            case CommandStringTypes.GetJobLastKnownEvent:
            case CommandStringTypes.GetJobLastScheduleTime:
                return(DateTimeOffset.Parse(reader.GetString(column),
                                            CultureInfo.InvariantCulture));

            default:
                return(base.ReadAsDateTimeOffset(command, column, reader, noValue));
            }
        }
        /// <inheritdoc />
        public void Handle(SetErrorCountCommand command, IDbCommand dbCommand, CommandStringTypes commandType)
        {
            dbCommand.CommandText = _commandCache.GetCommand(commandType);
            var param = dbCommand.CreateParameter();

            param.ParameterName = "@QueueID";
            param.DbType        = DbType.Int64;
            param.Value         = command.QueueId;
            dbCommand.Parameters.Add(param);

            param = dbCommand.CreateParameter();
            param.ParameterName = "@ExceptionType";
            param.DbType        = DbType.AnsiStringFixedLength;
            param.Size          = 500;
            param.Value         = command.ExceptionType;
            dbCommand.Parameters.Add(param);
        }
Exemplo n.º 14
0
 /// <summary>
 /// Gets the command for the indicated command type
 /// </summary>
 /// <param name="type">The command type.</param>
 /// <param name="input">The input.</param>
 /// <returns></returns>
 public string GetCommand(CommandStringTypes type, params object[] input)
 {
     if (_commandsBuilt && CommandCache.Count != 0)
     {
         return(string.Format(CommandCache[type], input));
     }
     lock (_commandBuilder)
     {
         if (CommandCache.Count != 0)
         {
             return(string.Format(CommandCache[type], input));
         }
         BuildCommands();
         _commandsBuilt = true;
     }
     return(CommandCache[type]);
 }
Exemplo n.º 15
0
 /// <summary>
 /// Gets the command for the indicated command type
 /// </summary>
 /// <param name="type">The command type.</param>
 /// <returns></returns>
 public string GetCommand(CommandStringTypes type)
 {
     if (_commandsBuilt && CommandCache.Count != 0)
     {
         return(CommandCache[type]);
     }
     lock (_commandBuilder)
     {
         if (CommandCache.Count != 0)
         {
             return(CommandCache[type]);
         }
         BuildCommands();
         _commandsBuilt = true;
     }
     return(CommandCache[type]);
 }
        /// <inheritdoc />
        public void Handle(GetTableExistsQuery query, IDbCommand dbCommand, CommandStringTypes commandType)
        {
            dbCommand.CommandText = _commandCache.GetCommand(commandType);

            var parameter = dbCommand.CreateParameter();

            parameter.ParameterName = "@Table";
            parameter.DbType        = DbType.AnsiString;
            parameter.Value         = query.TableName;
            dbCommand.Parameters.Add(parameter);

            var parameterDb = dbCommand.CreateParameter();

            parameterDb.ParameterName = "@Database";
            parameterDb.DbType        = DbType.AnsiString;
            parameterDb.Value         = _connectionInformation.Container;
            dbCommand.Parameters.Add(parameterDb);
        }
        /// <inheritdoc />
        public void Handle(GetErrorRecordExistsQuery query, IDbCommand dbCommand, CommandStringTypes commandType)
        {
            dbCommand.CommandText = _commandCache.GetCommand(commandType);

            var queueid = dbCommand.CreateParameter();

            queueid.ParameterName = "@QueueID";
            queueid.DbType        = DbType.Int64;
            queueid.Value         = query.QueueId;
            dbCommand.Parameters.Add(queueid);

            var exceptionType = dbCommand.CreateParameter();

            exceptionType.ParameterName = "@ExceptionType";
            exceptionType.DbType        = DbType.AnsiString;
            exceptionType.Size          = 500;
            exceptionType.Value         = query.ExceptionType;
            dbCommand.Parameters.Add(exceptionType);
        }
        /// <inheritdoc />
        public void Handle(GetTableExistsQuery query, IDbCommand dbCommand, CommandStringTypes commandType)
        {
            dbCommand.CommandText = _commandCache.GetCommand(commandType);
            var tableName = query.TableName;
            var parameter = dbCommand.CreateParameter();

            parameter.ParameterName = "@Table";
            parameter.DbType        = DbType.AnsiString;

            if (tableName.StartsWith(_schema.Schema))
            {
                tableName = tableName.Replace($"{_schema.Schema}.", string.Empty);
            }

            parameter.Value = tableName;
            dbCommand.Parameters.Add(parameter);

            var parameterDb = dbCommand.CreateParameter();

            parameterDb.ParameterName = "@Database";
            parameterDb.DbType        = DbType.AnsiString;
            parameterDb.Value         = _connectionInformation.Container;
            dbCommand.Parameters.Add(parameterDb);
        }
Exemplo n.º 19
0
        /// <summary>
        /// Handles the specified query.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <param name="dbCommand">The database command.</param>
        /// <param name="commandType">Type of the command.</param>
        public void Handle(FindMessagesToResetByHeartBeatQuery <long> query, IDbCommand dbCommand, CommandStringTypes commandType)
        {
            dbCommand.CommandText =
                _commandCache.GetCommand(commandType);

            var command = dbCommand;

            var param = command.CreateParameter();

            param.ParameterName = "@Time";
            param.DbType        = DbType.Int64;
            param.Value         = _getTime.GetCurrentUtcDate().AddSeconds(_configuration.HeartBeat.Time.TotalSeconds * -1).Ticks;
            command.Parameters.Add(param);

            param = command.CreateParameter();
            param.ParameterName = "@Status";
            param.DbType        = DbType.Int32;
            param.Value         = Convert.ToInt16(QueueStatuses.Processing);
            command.Parameters.Add(param);
        }
        /// <inheritdoc />
        public void Handle(FindErrorMessagesToDeleteQuery <long> query, IDbCommand dbCommand, CommandStringTypes commandType)
        {
            dbCommand.CommandText = _commandCache.GetCommand(commandType);

            var command = (NpgsqlCommand)dbCommand;

            command.Parameters.Add("@CurrentDate", NpgsqlDbType.Timestamp);
            command.Parameters["@CurrentDate"].Value = _getTime.GetCurrentUtcDate().Subtract(_configuration.MessageAge);
        }
        /// <summary>
        /// Handles the specified command.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <param name="dbCommand">The database command.</param>
        /// <param name="commandType">Type of the command.</param>
        public void Handle(MoveRecordToErrorQueueCommand <long> command, IDbCommand dbCommand, CommandStringTypes commandType)
        {
            dbCommand.CommandText = _buildSql.Create();
            var commandSql = dbCommand;

            var param = commandSql.CreateParameter();

            param.ParameterName = "@QueueID";
            param.DbType        = DbType.Int64;
            param.Value         = command.QueueId;
            commandSql.Parameters.Add(param);

            param = commandSql.CreateParameter();
            param.ParameterName = "@LastException";
            param.DbType        = DbType.String;
            param.Value         = command.Exception.ToString();
            commandSql.Parameters.Add(param);

            param = commandSql.CreateParameter();
            param.ParameterName = "@CurrentDateTime";
            param.DbType        = DbType.Int64;
            param.Value         = _getTime.GetCurrentUtcDate().Ticks;
            commandSql.Parameters.Add(param);
        }
        /// <summary>
        /// Handles the specified query.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <param name="dbCommand">The database command.</param>
        /// <param name="commandType">Type of the command.</param>
        public void Handle(FindMessagesToResetByHeartBeatQuery query, IDbCommand dbCommand, CommandStringTypes commandType)
        {
            dbCommand.CommandText =
                _commandCache.GetCommand(commandType);

            var command = (NpgsqlCommand)dbCommand;

            command.Parameters.Add("@Time", NpgsqlDbType.Bigint);
            var selectTime = _getTime.GetCurrentUtcDate().AddSeconds(_configuration.HeartBeat.Time.TotalSeconds * -1);

            command.Parameters["@time"].Value = selectTime.Ticks;
            command.Parameters.Add("@Status", NpgsqlDbType.Integer);
            command.Parameters["@Status"].Value = Convert.ToInt16(QueueStatuses.Processing);
        }
Exemplo n.º 23
0
 /// <inheritdoc />
 public void Handle(CreateJobTablesCommand <ITable> command, IDbCommand dbCommand, CommandStringTypes commandType)
 {
     dbCommand.CommandText = command.Tables.Aggregate(string.Empty, (current, table) => current + table.Script() + Environment.NewLine);
 }
Exemplo n.º 24
0
 /// <inheritdoc />
 public virtual long ReadAsInt64(CommandStringTypes command, int column, IDataReader reader, long noValue = 0)
 {
     ValidColumn(column, command);
     return(!reader.IsDBNull(column) ? reader.GetInt64(column) : noValue);
 }
Exemplo n.º 25
0
 /// <inheritdoc />
 public virtual DateTime ReadAsDateTime(CommandStringTypes command, int column, IDataReader reader, DateTime noValue = default(DateTime))
 {
     ValidColumn(column, command);
     return(!reader.IsDBNull(column) ? reader.GetDateTime(column) : noValue);
 }
Exemplo n.º 26
0
 /// <inheritdoc />
 public virtual string ReadAsString(CommandStringTypes command, int column, IDataReader reader, string noValue = null)
 {
     ValidColumn(column, command);
     return(!reader.IsDBNull(column) ? reader.GetString(column) : noValue);
 }
Exemplo n.º 27
0
        /// <summary>
        /// Handles the specified command.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <param name="dbCommand">The database command.</param>
        /// <param name="commandType">Type of the command.</param>
        public void Handle(ResetHeartBeatCommand <long> command, IDbCommand dbCommand, CommandStringTypes commandType)
        {
            dbCommand.CommandText = _commandCache.GetCommand(CommandStringTypes.ResetHeartbeat);

            var param = dbCommand.CreateParameter();

            param.ParameterName = "@QueueID";
            param.DbType        = DbType.Int64;
            param.Value         = command.MessageReset.QueueId;
            dbCommand.Parameters.Add(param);

            param = dbCommand.CreateParameter();
            param.ParameterName = "@SourceStatus";
            param.DbType        = DbType.Int32;
            param.Value         = Convert.ToInt16(QueueStatuses.Processing);
            dbCommand.Parameters.Add(param);

            param = dbCommand.CreateParameter();
            param.ParameterName = "@Status";
            param.DbType        = DbType.Int32;
            param.Value         = Convert.ToInt16(QueueStatuses.Waiting);
            dbCommand.Parameters.Add(param);

            param = dbCommand.CreateParameter();
            param.ParameterName = "@HeartBeat";
            param.DbType        = DbType.Int64;
            param.Value         = command.MessageReset.HeartBeat.Ticks;
            dbCommand.Parameters.Add(param);
        }
Exemplo n.º 28
0
 /// <inheritdoc />
 public void Handle(DeleteTableCommand command, IDbCommand dbCommand, CommandStringTypes commandType)
 {
     dbCommand.CommandText =
         _commandCache.GetCommand(commandType, command.Table.ToLowerInvariant());
 }
 /// <inheritdoc />
 public void Handle(GetErrorCountQuery query, IDbCommand dbCommand, CommandStringTypes commandType)
 {
     dbCommand.CommandText = _commandCache.GetCommand(CommandStringTypes.GetErrorCount);
 }
        /// <inheritdoc />
        public void Handle(FindErrorMessagesToDeleteQuery <long> query, IDbCommand dbCommand, CommandStringTypes commandType)
        {
            dbCommand.CommandText = _commandCache.GetCommand(commandType);

            var command = dbCommand;
            var param   = command.CreateParameter();

            param.ParameterName = "@CurrentDateTime";
            param.DbType        = DbType.Int64;
            param.Value         = _getTime.GetCurrentUtcDate().Ticks - _configuration.MessageAge.Ticks;
            command.Parameters.Add(param);
        }