/// <summary>
        /// Internal create scope info table routine
        /// </summary>
        internal async Task <(SyncContext context, bool created)> InternalCreateScopeInfoTableAsync(SyncContext context, DbScopeType scopeType, DbConnection connection, DbTransaction transaction, CancellationToken cancellationToken, IProgress <ProgressArgs> progress)
        {
            var scopeBuilder = this.GetScopeBuilder(this.Options.ScopeInfoTableName);

            var scopeCommandType = scopeType switch
            {
                DbScopeType.Client => DbScopeCommandType.CreateClientScopeInfoTable,
                DbScopeType.Server => DbScopeCommandType.CreateServerScopeInfoTable,
                DbScopeType.ServerHistory => DbScopeCommandType.CreateServerHistoryScopeInfoTable,
                _ => throw new NotImplementedException()
            };

            using var command = scopeBuilder.GetCommandAsync(scopeCommandType, connection, transaction);

            if (command == null)
            {
                return(context, false);
            }

            var action = new ScopeTableCreatingArgs(context, scopeBuilder.ScopeInfoTableName.ToString(), scopeType, command, connection, transaction);

            await this.InterceptAsync(action, progress, cancellationToken).ConfigureAwait(false);

            if (action.Cancel || action.Command == null)
            {
                return(context, false);
            }

            await this.InterceptAsync(new DbCommandArgs(context, action.Command, connection, transaction), progress, cancellationToken).ConfigureAwait(false);

            await action.Command.ExecuteNonQueryAsync().ConfigureAwait(false);

            await this.InterceptAsync(new ScopeTableCreatedArgs(context, scopeBuilder.ScopeInfoTableName.ToString(), scopeType, connection, transaction), progress, cancellationToken).ConfigureAwait(false);

            action.Command.Dispose();

            return(context, true);
        }
    }
Пример #2
0
        /// <summary>
        /// Internal create scope info table routine
        /// </summary>
        internal async Task <bool> InternalCreateScopeInfoTableAsync(SyncContext ctx, DbScopeType scopeType, DbScopeBuilder scopeBuilder, DbConnection connection, DbTransaction transaction, CancellationToken cancellationToken, IProgress <ProgressArgs> progress)
        {
            var command = scopeBuilder.GetCommandAsync(DbScopeCommandType.CreateScopeTable, scopeType, connection, transaction);

            if (command == null)
            {
                return(false);
            }

            var action = new ScopeTableCreatingArgs(ctx, scopeBuilder.ScopeInfoTableName.ToString(), scopeType, command, connection, transaction);

            await this.InterceptAsync(action, cancellationToken).ConfigureAwait(false);

            if (action.Cancel || action.Command == null)
            {
                return(false);
            }

            await action.Command.ExecuteNonQueryAsync();

            await this.InterceptAsync(new ScopeTableCreatedArgs(ctx, scopeBuilder.ScopeInfoTableName.ToString(), scopeType, connection, transaction), cancellationToken).ConfigureAwait(false);

            return(true);
        }