public void Create_Default() { var tables = new List <Table>(); var test = new CreateQueueTablesAndSaveConfigurationCommand <Table>(tables); Assert.Equal(tables, test.Tables); }
public QueueCreationResult Handle(CreateQueueTablesAndSaveConfigurationCommand <ITable> command) { if (!_databaseExists.Exists(_connectionInformation.ConnectionString)) { //no db file, create var fileName = _getFileNameFromConnection.GetFileName(_connectionInformation.ConnectionString); using (File.Create(fileName.FileName)) { } } try { return(_decorated.Handle(command)); } //if the queue already exists, return that status; otherwise, bubble the error catch (SQLiteException error) { if (error.ResultCode == SQLiteErrorCode.Error && error.Message.Contains("table") && error.Message.Contains("already exists")) { return(new QueueCreationResult(QueueCreationStatus.AttemptedToCreateAlreadyExists)); } throw new DotNetWorkQueueException("Failed to create table", error); } }
/// <inheritdoc /> public QueueCreationResult Handle(CreateQueueTablesAndSaveConfigurationCommand <ITable> command) { //create database and enforce UTC date de-serialization using (var db = _connectionInformation.GetDatabase()) { db.Database.Pragma("UTC_DATE", true); //create all tables foreach (var table in command.Tables) { table.Create(_connectionInformation, _options.Value, _tableNameHelper); } //save configuration foreach (var table in command.Tables) { if (table is ConfigurationTable configTable) { var col = db.Database.GetCollection <ConfigurationTable>(_tableNameHelper.ConfigurationName); configTable.Configuration = _serializer.ConvertToBytes(_options.Value); col.Insert(configTable); break; } } return(new QueueCreationResult(QueueCreationStatus.Success)); } }
/// <inheritdoc /> public QueueCreationResult Handle(CreateQueueTablesAndSaveConfigurationCommand <ITable> command) { try { return(_decorated.Handle(command)); } //if the queue already exists, return that status; otherwise, bubble the error catch (PostgresException error) { if (error.SqlState == "42P07" || error.SqlState == "42710") { return(new QueueCreationResult(QueueCreationStatus.AttemptedToCreateAlreadyExists)); } throw new DotNetWorkQueueException($"Failed to create job table(s). SQL script was {error.Statement}", error); } }
public QueueCreationResult Handle(CreateQueueTablesAndSaveConfigurationCommand <ITable> command) { try { return(_decorated.Handle(command)); } //if the queue already exists, return that status; otherwise, bubble the error catch (SqlException error) { if (error.Number == 2714) { return(new QueueCreationResult(QueueCreationStatus.AttemptedToCreateAlreadyExists)); } throw new DotNetWorkQueueException("Failed to create queue", error); } }
public QueueCreationResult Handle(CreateQueueTablesAndSaveConfigurationCommand <ITable> command) { using (var conn = _connectionFactory.Create()) { conn.Open(); using (var trans = _transactionFactory.Create(conn).BeginTransaction()) { using (var commandSql = conn.CreateCommand()) { commandSql.Transaction = trans; _prepareCommand.Handle(command, commandSql, CommandStringTypes.CreateQueueTables); commandSql.ExecuteNonQuery(); } //save the configuration SaveConfiguration(conn, trans); trans.Commit(); } } return(new QueueCreationResult(QueueCreationStatus.Success)); }
/// <inheritdoc /> public void Handle(CreateQueueTablesAndSaveConfigurationCommand <ITable> command, IDbCommand dbCommand, CommandStringTypes commandType) { dbCommand.CommandText = command.Tables.Aggregate(string.Empty, (current, table) => current + table.Script() + Environment.NewLine); }