InternalSaveServerHistoryScopeAsync(ServerHistoryScopeInfo serverHistoryScopeInfo, SyncContext context, DbConnection connection, DbTransaction transaction, CancellationToken cancellationToken, IProgress <ProgressArgs> progress) { var scopeBuilder = this.GetScopeBuilder(this.Options.ScopeInfoTableName); bool scopeExists; (context, scopeExists) = await InternalExistsServerHistoryScopeInfoAsync(serverHistoryScopeInfo.Id.ToString(), serverHistoryScopeInfo.Name, context, connection, transaction, cancellationToken, progress).ConfigureAwait(false); DbCommand command; if (scopeExists) { command = scopeBuilder.GetCommandAsync(DbScopeCommandType.UpdateServerHistoryScopeInfo, connection, transaction); } else { command = scopeBuilder.GetCommandAsync(DbScopeCommandType.InsertServerHistoryScopeInfo, connection, transaction); } if (command == null) { return(context, null); } InternalSetSaveServerHistoryScopeParameters(serverHistoryScopeInfo, command); var action = new ScopeSavingArgs(context, scopeBuilder.ScopeInfoTableName.ToString(), DbScopeType.ServerHistory, serverHistoryScopeInfo, command, connection, transaction); await this.InterceptAsync(action, progress, cancellationToken).ConfigureAwait(false); if (action.Cancel || action.Command == null) { return(default);
InternalSaveClientScopeInfoAsync(ClientScopeInfo clientScopeInfo, SyncContext context, DbConnection connection, DbTransaction transaction, CancellationToken cancellationToken, IProgress <ProgressArgs> progress) { var scopeBuilder = this.GetScopeBuilder(this.Options.ScopeInfoTableName); bool scopeExists; (context, scopeExists) = await InternalExistsClientScopeInfoAsync(clientScopeInfo.Name, context, connection, transaction, cancellationToken, progress).ConfigureAwait(false); DbCommand command; if (scopeExists) { command = scopeBuilder.GetCommandAsync(DbScopeCommandType.UpdateClientScopeInfo, connection, transaction); } else { command = scopeBuilder.GetCommandAsync(DbScopeCommandType.InsertClientScopeInfo, connection, transaction); } if (command == null) { return(context, null); } command = InternalSetSaveClientScopeInfoParameters(clientScopeInfo, command); var action = new ScopeSavingArgs(context, scopeBuilder.ScopeInfoTableName.ToString(), DbScopeType.Client, clientScopeInfo, command, connection, transaction); await this.InterceptAsync(action, progress, cancellationToken).ConfigureAwait(false); if (action.Cancel || action.Command == null) { return(context, null); } await this.InterceptAsync(new DbCommandArgs(context, action.Command, connection, transaction), progress, cancellationToken).ConfigureAwait(false); using DbDataReader reader = await action.Command.ExecuteReaderAsync().ConfigureAwait(false); reader.Read(); clientScopeInfo = InternalReadClientScopeInfo(reader); reader.Close(); await this.InterceptAsync(new ScopeSavedArgs(context, scopeBuilder.ScopeInfoTableName.ToString(), DbScopeType.Client, clientScopeInfo, connection, transaction), progress, cancellationToken).ConfigureAwait(false); action.Command.Dispose(); return(context, clientScopeInfo); }
/// <summary> /// Internal upsert scope info in a scope table /// </summary> internal async Task <T> InternalSaveScopeAsync <T>(SyncContext ctx, DbScopeType scopeType, T scopeInfo, DbScopeBuilder scopeBuilder, DbConnection connection, DbTransaction transaction, CancellationToken cancellationToken, IProgress <ProgressArgs> progress) where T : class { var scopeId = scopeType switch { DbScopeType.Client => (scopeInfo as ScopeInfo).Id.ToString(), DbScopeType.Server => (scopeInfo as ServerScopeInfo).Name, DbScopeType.ServerHistory => (scopeInfo as ServerHistoryScopeInfo).Id.ToString(), _ => throw new NotImplementedException($"Can't set parameters to scope command type {scopeType}.") }; var scopeExists = await InternalExistsScopeInfoAsync(ctx, scopeType, scopeId, scopeBuilder, connection, transaction, cancellationToken, progress).ConfigureAwait(false); DbCommand command; if (scopeExists) { command = scopeBuilder.GetCommandAsync(DbScopeCommandType.UpdateScope, scopeType, connection, transaction); } else { command = scopeBuilder.GetCommandAsync(DbScopeCommandType.InsertScope, scopeType, connection, transaction); } if (command == null) { return(null); } command = scopeType switch { DbScopeType.Client => SetSaveScopeParameters(scopeInfo as ScopeInfo, command), DbScopeType.Server => SetSaveScopeParameters(scopeInfo as ServerScopeInfo, command), DbScopeType.ServerHistory => SetSaveScopeParameters(scopeInfo as ServerHistoryScopeInfo, command), _ => throw new NotImplementedException($"Can't set parameters to scope command type {scopeType}.") }; var action = new ScopeSavingArgs(ctx, scopeBuilder.ScopeInfoTableName.ToString(), scopeType, scopeInfo, command, connection, transaction); await this.InterceptAsync(action, cancellationToken).ConfigureAwait(false); if (action.Cancel || action.Command == null) { return(default);
InternalDeleteClientScopeInfoAsync(ClientScopeInfo clientScopeInfo, SyncContext context, DbConnection connection, DbTransaction transaction, CancellationToken cancellationToken, IProgress <ProgressArgs> progress) { var scopeBuilder = this.GetScopeBuilder(this.Options.ScopeInfoTableName); bool scopeExists; (context, scopeExists) = await InternalExistsClientScopeInfoAsync(clientScopeInfo.Name, context, connection, transaction, cancellationToken, progress).ConfigureAwait(false); if (!scopeExists) { return(context, true); } using var command = scopeBuilder.GetCommandAsync(DbScopeCommandType.DeleteClientScopeInfo, connection, transaction); InternalSetDeleteClientScopeInfoParameters(clientScopeInfo, command); var action = new ScopeSavingArgs(context, scopeBuilder.ScopeInfoTableName.ToString(), DbScopeType.Client, clientScopeInfo, 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 ScopeSavedArgs(context, scopeBuilder.ScopeInfoTableName.ToString(), DbScopeType.Client, clientScopeInfo, connection, transaction), progress, cancellationToken).ConfigureAwait(false); action.Command.Dispose(); return(context, true); }