public void MarkAsExecuted(string assembly, string version, int stepNumber)
        {
            using (var cmd = _connection.GetOpenConnection().CreateCommand())
            {
                cmd.Transaction = _transactionProvider.GetTransaction();

                cmd.CommandText = "DbKeeperNetSetStepExecuted";
                cmd.CommandType = CommandType.StoredProcedure;

                var param = cmd.CreateParameter();
                param.ParameterName = "@assembly";
                param.Value         = assembly;
                cmd.Parameters.Add(param);

                param = cmd.CreateParameter();
                param.ParameterName = "@version";
                param.Value         = version;
                cmd.Parameters.Add(param);

                param = cmd.CreateParameter();
                param.ParameterName = "@step";
                param.Value         = stepNumber;
                cmd.Parameters.Add(param);

                cmd.ExecuteNonQuery();
            }
        }
Example #2
0
        public void MarkAsExecuted(string assemblyName, string version, int stepNumber)
        {
            var transaction = _transactionProvider.GetTransaction();

            _assemblyInsert.Transaction = transaction;
            _assemblySelect.Transaction = transaction;
            _versionInsert.Transaction  = transaction;
            _versionSelect.Transaction  = transaction;
            _stepInsert.Transaction     = transaction;
            _stepSelect.Transaction     = transaction;

            var connection = _databaseService.GetOpenConnection();

            if (connection == null)
            {
                throw new InvalidOperationException();
            }

            _assemblyInsert.Connection = connection;
            _assemblySelect.Connection = connection;
            _versionInsert.Connection  = connection;
            _versionSelect.Connection  = connection;
            _stepInsert.Connection     = connection;
            _stepSelect.Connection     = connection;

            _assemblySelect.Parameters[0].Value = assemblyName;
            var assemblyId = (int?)_assemblySelect.ExecuteScalar();

            if (!assemblyId.HasValue)
            {
                _assemblyInsert.Parameters[0].Value = assemblyName;
                assemblyId = Convert.ToInt32(_assemblyInsert.ExecuteScalar(), CultureInfo.InvariantCulture);
            }

            _versionSelect.Parameters[0].Value = assemblyId.Value;
            _versionSelect.Parameters[1].Value = version;
            var versionId = (int?)_versionSelect.ExecuteScalar();

            if (!versionId.HasValue)
            {
                _versionInsert.Parameters[0].Value = assemblyId.Value;
                _versionInsert.Parameters[1].Value = version;
                versionId = Convert.ToInt32(_versionInsert.ExecuteScalar(), CultureInfo.InvariantCulture);
            }

            // TODO: should throw exception?

            _stepSelect.Parameters[0].Value = versionId.Value;
            _stepSelect.Parameters[1].Value = stepNumber;
            var stepId = (int?)_stepSelect.ExecuteScalar();

            if (!stepId.HasValue)
            {
                _stepInsert.Parameters[0].Value = versionId.Value;
                _stepInsert.Parameters[1].Value = stepNumber;
                _stepInsert.ExecuteNonQuery();
            }
        }
 public void Execute(string command)
 {
     using (var databaseCommand = _databaseService.GetOpenConnection().CreateCommand())
     {
         databaseCommand.Transaction = _transactionProvider.GetTransaction();
         databaseCommand.CommandText = command;
         databaseCommand.CommandType = CommandType.Text;
         databaseCommand.ExecuteNonQuery();
     }
 }