Exemplo 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);
                }
            }
        }
Exemplo n.º 2
0
        protected override void Execute(UpdateStepContextWithPreconditions <CustomUpdateStepType> context)
        {
            var castedStep = context.Step;

            var type = Type.GetType(castedStep.Type);

            if (type == null)
            {
                throw new ArgumentException($"Custom step {context} type '{castedStep.Type}' not found");
            }

            _logger.LogInformation("Going to create instance of {0}", type);

            var customStep = (ICustomUpdateStep)Activator.CreateInstance(type);

            _logger.LogInformation("Instance of {0} created [{1}] - going to execute step", type, customStep);

            try
            {
                customStep.ExecuteUpdate(context, castedStep.Param);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException($"{context} failed with exception", ex);
            }
        }
        protected override void Execute(UpdateStepContextWithPreconditions <AspNetRoleCreateUpdateStepType> context)
        {
            var castedStep = context.Step;

            // context.Logger.TraceInformation(AspNetMembershipAdapterMessages.GoingToUseAdapter, _aspNetMembershipAdapter);
            // context.Logger.TraceInformation(AspNetMembershipAdapterMessages.AddingRole, castedStep.RoleName);
            _aspNetMembershipAdapter.CreateRole(castedStep.RoleName);
            // context.Logger.TraceInformation(AspNetMembershipAdapterMessages.AddedRole, castedStep.RoleName);
        }
Exemplo n.º 4
0
        public void Execute(UpdateStepContextWithPreconditions context)
        {
            if (!(context.Step is T))
            {
                throw new InvalidCastException();
            }

            Execute(new UpdateStepContextWithPreconditions <T>(context));
        }
Exemplo n.º 5
0
        protected override void Execute(UpdateStepContextWithPreconditions <AspNetAccountDeleteUpdateStepType> context)
        {
            var castedStep = context.Step;

            //context.Logger.TraceInformation(AspNetMembershipAdapterMessages.GoingToUseAdapter, _aspNetMembershipAdapter);
            //context.Logger.TraceInformation(AspNetMembershipAdapterMessages.DeletingUser, castedStep.UserName);

            if (_aspNetMembershipAdapter.DeleteUser(castedStep.UserName))
            {
                //    context.Logger.TraceInformation(AspNetMembershipAdapterMessages.DeletedUser, castedStep.UserName);
            }
            else
            {
                //    context.Logger.TraceWarning(AspNetMembershipAdapterMessages.UserNotDeleted, castedStep.UserName);
            }
        }
        protected override void Execute(UpdateStepContextWithPreconditions <AspNetAccountCreateUpdateStepType> context)
        {
            // context.Logger.TraceInformation(AspNetMembershipAdapterMessages.GoingToUseAdapter, _aspNetMembershipAdapter);

            // context.Logger.TraceInformation(AspNetMembershipAdapterMessages.AddingUser, castedStep.UserName);
            var castedStep = context.Step;

            _aspNetMembershipAdapter.CreateUser(castedStep.UserName, castedStep.Password, castedStep.Mail);
            // context.Logger.TraceInformation(AspNetMembershipAdapterMessages.AddedUser, castedStep.UserName);

            if (castedStep.Role != null && castedStep.Role.Length != 0)
            {
                // context.Logger.TraceInformation(AspNetMembershipAdapterMessages.AddingUserToRoles, castedStep.UserName, string.Join(@",", castedStep.Role));
                _aspNetMembershipAdapter.AddUserToRoles(castedStep.UserName, castedStep.Role);
                //  context.Logger.TraceInformation(AspNetMembershipAdapterMessages.UserAddedToRoles, castedStep.UserName);
            }
        }
        protected override void Execute(UpdateStepContextWithPreconditions <MsSqlMembershipAndRolesSetupType> context)
        {
            using (var connection = _databaseService.CreateOpenConnection())
            {
                using (var command = connection.CreateCommand())
                {
                    using (var script = new StreamReader(typeof(MsSqlMembershipAndRolesSetupTypeHandlerService).Assembly.GetManifestResourceStream("DbKeeperNet.Extensions.MsSqlMembershipAndRolesSetup.MsSqlMembershipAndRolesSetup.sql")))
                    {
                        var scriptText        = script.ReadToEnd();
                        var sqlScriptSplitter = new MsSqlScriptSplitter();

                        foreach (var scriptPart in sqlScriptSplitter.SplitScript(scriptText))
                        {
                            command.CommandText = scriptPart;
                            command.Transaction = null;
                            command.ExecuteNonQuery();
                        }
                    }
                }
            }
        }
Exemplo n.º 8
0
 protected virtual bool CanHandle(UpdateStepContextWithPreconditions <T> context)
 {
     return(context.IsTyped);
 }
Exemplo n.º 9
0
 protected abstract void Execute(UpdateStepContextWithPreconditions <T> context);
Exemplo n.º 10
0
 public bool CanHandle(UpdateStepContextWithPreconditions context)
 {
     return(CanHandle(new UpdateStepContextWithPreconditions <T>(context)));
 }
 public UpdateStepContextPrecondition(UpdateStepContextWithPreconditions context, PreconditionType precondition) : base(context)
 {
     Precondition = precondition;
 }