/// <summary>
        /// Internal rename tracking table routine
        /// </summary>
        internal async Task <(SyncContext context, bool renamed)> InternalRenameTrackingTableAsync(
            IScopeInfo scopeInfo, SyncContext context, ParserName oldTrackingTableName, DbTableBuilder tableBuilder, DbConnection connection, DbTransaction transaction, CancellationToken cancellationToken, IProgress <ProgressArgs> progress)
        {
            await using var runner = await this.GetConnectionAsync(context, SyncMode.Writing, SyncStage.Provisioning, connection, transaction, cancellationToken, progress).ConfigureAwait(false);

            if (tableBuilder.TableDescription.Columns.Count <= 0)
            {
                throw new MissingsColumnException(tableBuilder.TableDescription.GetFullName());
            }

            if (tableBuilder.TableDescription.PrimaryKeys.Count <= 0)
            {
                throw new MissingPrimaryKeyException(tableBuilder.TableDescription.GetFullName());
            }

            using var command = await tableBuilder.GetRenameTrackingTableCommandAsync(oldTrackingTableName, connection, transaction).ConfigureAwait(false);

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

            var(_, trackingTableName) = this.Provider.GetParsers(tableBuilder.TableDescription, scopeInfo.Setup);


            var action = await this.InterceptAsync(new TrackingTableRenamingArgs(context, tableBuilder.TableDescription, trackingTableName, oldTrackingTableName, command, connection, transaction), 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 TrackingTableRenamedArgs(context, tableBuilder.TableDescription, trackingTableName, oldTrackingTableName, connection, transaction), progress, cancellationToken).ConfigureAwait(false);

            await runner.CommitAsync().ConfigureAwait(false);

            action.Command.Dispose();

            return(context, true);
        }
Пример #2
0
        /// <summary>
        /// Internal rename tracking table routine
        /// </summary>
        internal async Task <bool> InternalRenameTrackingTableAsync(SyncContext ctx, SyncSetup setup, ParserName oldTrackingTableName, DbTableBuilder tableBuilder, DbConnection connection, DbTransaction transaction, CancellationToken cancellationToken, IProgress <ProgressArgs> progress)
        {
            if (tableBuilder.TableDescription.Columns.Count <= 0)
            {
                throw new MissingsColumnException(tableBuilder.TableDescription.GetFullName());
            }

            if (tableBuilder.TableDescription.PrimaryKeys.Count <= 0)
            {
                throw new MissingPrimaryKeyException(tableBuilder.TableDescription.GetFullName());
            }

            var command = await tableBuilder.GetRenameTrackingTableCommandAsync(oldTrackingTableName, connection, transaction).ConfigureAwait(false);

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

            var(_, trackingTableName) = this.Provider.GetParsers(tableBuilder.TableDescription, setup);

            var action = new TrackingTableRenamingArgs(ctx, tableBuilder.TableDescription, trackingTableName, oldTrackingTableName, command, connection, transaction);

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

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

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

            await this.InterceptAsync(new TrackingTableRenamedArgs(ctx, tableBuilder.TableDescription, trackingTableName, oldTrackingTableName, connection, transaction), cancellationToken).ConfigureAwait(false);

            return(true);
        }