Esempio n. 1
0
        protected override void Execute(UpdateStepContextWithPreconditions <UpdateDbStepType> context)
        {
            foreach (var statement in context.Step.AlternativeStatement)
            {
                _logger.LogInformation("Going to check whether statement for DbType={0} can be handled by this database", statement.DbType);

                if (!_databaseService.CanHandle(statement.DbType) && statement.DbType != "all")
                {
                    _logger.LogInformation("{0} for DbType={1} cannot be handled by this database", context, statement.DbType);

                    continue;
                }

                _transactionProvider.BeginTransaction();

                try
                {
                    foreach (var subStep in _scriptSplitter.SplitScript(statement.Value))
                    {
                        // TODO: add subcontext on script split?
                        _commandHandler.Execute(subStep);
                    }
                    _transactionProvider.CommitTransaction();
                }
                catch (Exception ex)
                {
                    // let's assume that the rollback is low chance to fail so we will not log the
                    // previous error first
                    _transactionProvider.RollbackTransaction();

                    throw new InvalidOperationException($"{context} failed with exception", ex);
                }
            }
        }
Esempio n. 2
0
        public void Execute(UpdateStepContextWithPreconditions context)
        {
            foreach (var updateStepHandler in _updateStepHandlers)
            {
                if (!updateStepHandler.CanHandle(context))
                {
                    continue;
                }

                _logger.LogInformation($"Going to execute {context}");

                updateStepHandler.Execute(context);

                _logger.LogInformation($"{context} was executed");

                if (context.Step.MarkAsExecuted)
                {
                    try
                    {
                        _transactionProvider.BeginTransaction();

                        _updateStepExecutedMarker.MarkAsExecuted(context.AssemblyName, context.UpdateVersion,
                                                                 context.StepNumber);

                        _logger.LogInformation($"{context} was marked as executed");

                        _transactionProvider.CommitTransaction();
                    }
                    catch (Exception ex)
                    {
                        _transactionProvider.RollbackTransaction();

                        throw new InvalidOperationException($"{context} couldn't be marked as executed", ex);
                    }
                }
            }
        }