示例#1
0
    private void CreateAndExecuteInitializers()
    {
        IJob[] initializers;

        using (var creatorScope = Context.BeginScope(this, TransactionScopeKind.Suppress, LogSeverity.Information))
        {
            var builder = new ResilientSqlScopeProcessBuilder()
            {
                Scope = this
            };
            Initializers.Invoke(builder);
            initializers = builder.Jobs.Where(x => x != null).ToArray();

            Context.Log(LogSeverity.Information, this, "created {InitializerCount} initializers", initializers?.Length ?? 0);
        }

        if (initializers?.Length > 0)
        {
            Context.Log(LogSeverity.Information, this, "starting initializers");

            foreach (var process in initializers)
            {
                var preExceptionCount = Context.ExceptionCount;

                process.Execute(this);

                if (Context.ExceptionCount > preExceptionCount)
                {
                    break;
                }
            }
        }
    }
    private void CreateAndExecutePostFinalizers()
    {
        if (PostFinalizers != null)
        {
            IJob[] processes;

            using (var creatorScope = Context.BeginScope(this, TransactionScopeKind.Suppress, LogSeverity.Information))
            {
                var builder = new ResilientSqlScopeProcessBuilder()
                {
                    Scope = this
                };
                PostFinalizers.Invoke(builder);
                processes = builder.Jobs.Where(x => x != null).ToArray();
            }

            if (processes?.Length > 0)
            {
                Context.Log(LogSeverity.Debug, this, "created {PostFinalizerCount} post-finalizer(s)",
                            processes?.Length ?? 0);

                foreach (var process in processes)
                {
                    var preExceptionCount = Context.ExceptionCount;

                    process.Execute(this);

                    if (Context.ExceptionCount > preExceptionCount)
                    {
                        break;
                    }
                }
            }
        }
    }
示例#3
0
    public static ResilientSqlScopeProcessBuilder CustomJob(this ResilientSqlScopeProcessBuilder builder, string name, Action <CustomJob> action)
    {
        builder.Jobs.Add(new CustomJob(builder.Scope.Context)
        {
            Name   = name,
            Action = action,
        });

        return(builder);
    }
示例#4
0
    public static ResilientSqlScopeProcessBuilder MsSqlEnableForeignKeys(this ResilientSqlScopeProcessBuilder builder)
    {
        if (builder.Scope.Tables.Count > 1)
        {
            builder.Jobs.Add(new MsSqlEnableConstraintCheck(builder.Scope.Context)
            {
                Name             = "enable foreign keys",
                ConnectionString = builder.Scope.ConnectionString,
                TableNames       = builder.Scope.Tables.Select(x => x.TableName)
                                   .Concat(builder.Scope.Tables.Where(x => x.AdditionalTables != null).SelectMany(x => x.AdditionalTables.Select(at => at.TableName)))
                                   .ToArray(),
            });
        }

        return(builder);
    }