Exemplo n.º 1
0
        /// <inheritdoc />
        public override void Commit()
        {
            if (Interlocked.Exchange(ref _cleanup, 1L) != 0L)
            {
                return;
            }

            _command.SafelyDispose();
            _transaction.SafelyCommit();
            _transaction.SafelyDispose();
            _connection.SafelyClose();
            _connection.SafelyDispose();
        }
Exemplo n.º 2
0
        /// <inheritdoc />
        public ICollectionSaver CreateCollectionSaver()
        {
            if (_targetController.Cleanup(out var border))
            {
                //something were deleted from the file system
                //so we need to delete obsolete records from the DB

                CleanupDatabase(border);
            }

            SqlConnection? connection  = null;
            SqlTransaction?transaction = null;

            try
            {
                connection = new SqlConnection(_connectionString);
                connection.Open();

                transaction = connection.BeginTransaction();

                return(new SqlServerCollectionSaver(
                           connection,
                           transaction,
                           _tableName,
                           _targetController
                           ));
            }
            catch
            {
                transaction?.SafelyDispose();
                connection?.SafelyDispose();

                throw;
            }
        }