Skip to content

Commit

Permalink
Move CancellationToken arguments to the end (#8525)
Browse files Browse the repository at this point in the history
* Move CancellationToken arguments to the end

* Move type arguments in one method to align with new signatures.

Also a few more nameof() that somehow weren't caught before.
  • Loading branch information
cybertyche committed Jul 7, 2023
1 parent 10493a0 commit ea3372c
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public async Task ClearStateAsync<T>(string grainType, GrainId grainReference, I
command.AddParameter("GrainIdExtensionString", grainId.StringKey);
command.AddParameter("ServiceId", serviceId);
command.AddParameter("GrainStateVersion", !string.IsNullOrWhiteSpace(grainState.ETag) ? int.Parse(grainState.ETag, CultureInfo.InvariantCulture) : default(int?));
}, (selector, resultSetCount, token) => Task.FromResult(selector.GetValue(0).ToString()), CancellationToken.None).ConfigureAwait(false));
}, (selector, resultSetCount, token) => Task.FromResult(selector.GetValue(0).ToString()), cancellationToken: CancellationToken.None).ConfigureAwait(false));
storageVersion = clearRecord.SingleOrDefault();
}
catch(Exception ex)
Expand Down Expand Up @@ -272,7 +272,7 @@ public async Task ReadStateAsync<T>(string grainType, GrainId grainReference, IG
var result = Tuple.Create(storageState, version?.ToString(CultureInfo.InvariantCulture));
return Task.FromResult(result);
},
CancellationToken.None, commandBehavior).ConfigureAwait(false)).SingleOrDefault();
commandBehavior, CancellationToken.None).ConfigureAwait(false)).SingleOrDefault();

T state = readRecords != null ? (T) readRecords.Item1 : default;
string etag = readRecords != null ? readRecords.Item2 : null;
Expand Down Expand Up @@ -361,7 +361,7 @@ public async Task WriteStateAsync<T>(string grainType, GrainId grainReference, I
command.AddParameter("GrainStateVersion", !string.IsNullOrWhiteSpace(grainState.ETag) ? int.Parse(grainState.ETag, CultureInfo.InvariantCulture) : default(int?));
command.AddParameter("PayloadBinary", serialized.ToArray());
}, (selector, resultSetCount, token) =>
{ return Task.FromResult(selector.GetNullableInt32("NewGrainStateVersion").ToString()); }, CancellationToken.None).ConfigureAwait(false);
{ return Task.FromResult(selector.GetNullableInt32("NewGrainStateVersion").ToString()); }, cancellationToken: CancellationToken.None).ConfigureAwait(false);
storageVersion = writeRecord.SingleOrDefault();
}
catch(Exception ex)
Expand Down
18 changes: 9 additions & 9 deletions src/AdoNet/Shared/Storage/IRelationalStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ internal interface IRelationalStorage
/// <param name="query">The query to execute.</param>
/// <param name="parameterProvider">Adds parameters to the query. The parameters must be in the same order with same names as defined in the query.</param>
/// <param name="selector">This function transforms the raw <see cref="IDataRecord"/> results to type <see paramref="TResult"/> the <see cref="int"/> parameter being the resultset number.</param>
/// <param name="cancellationToken">The cancellation token. Defaults to <see cref="CancellationToken.None"/>.</param>
/// <param name="commandBehavior">The command behavior that should be used. Defaults to <see cref="CommandBehavior.Default"/>.</param>
/// <param name="cancellationToken">The cancellation token. Defaults to <see cref="CancellationToken.None"/>.</param>
/// <returns>A list of objects as a result of the <see paramref="query"/>.</returns>
/// <example>This sample shows how to make a hand-tuned database call.
/// <code>
Expand All @@ -58,7 +58,7 @@ internal interface IRelationalStorage
/// tp1.DbType = DbType.String;
/// tp1.Direction = ParameterDirection.Input;
/// command.Parameters.Add(tp1);
///
///
/// //The selector is used to select the results within the result set. In this case there are two homogenous
/// //result sets, so there is actually no need to check which result set the selector holds and it could
/// //marked with by convention by underscore (_).
Expand All @@ -70,19 +70,19 @@ internal interface IRelationalStorage
/// {
/// TABLE_CATALOG = selector.GetValueOrDefault&lt;string&gt;("TABLE_CATALOG"),
/// TABLE_NAME = selector.GetValueOrDefault&lt;string&gt;("TABLE_NAME")
/// }
///}).ConfigureAwait(continueOnCapturedContext: false);
/// </code>
/// }
///}).ConfigureAwait(continueOnCapturedContext: false);
/// </code>
/// </example>
Task<IEnumerable<TResult>> ReadAsync<TResult>(string query, Action<IDbCommand> parameterProvider, Func<IDataRecord, int, CancellationToken, Task<TResult>> selector, CancellationToken cancellationToken = default(CancellationToken), CommandBehavior commandBehavior = CommandBehavior.Default);
Task<IEnumerable<TResult>> ReadAsync<TResult>(string query, Action<IDbCommand> parameterProvider, Func<IDataRecord, int, CancellationToken, Task<TResult>> selector, CommandBehavior commandBehavior = CommandBehavior.Default, CancellationToken cancellationToken = default(CancellationToken));

/// <summary>
/// Executes a given statement. Especially intended to use with <em>INSERT</em>, <em>UPDATE</em>, <em>DELETE</em> or <em>DDL</em> queries.
/// </summary>
/// <param name="query">The query to execute.</param>
/// <param name="parameterProvider">Adds parameters to the query. Parameter names must match those defined in the query.</param>
/// <param name="cancellationToken">The cancellation token. Defaults to <see cref="CancellationToken.None"/>.</param>
/// <param name="commandBehavior">The command behavior that should be used. Defaults to <see cref="CommandBehavior.Default"/>.</param>
/// <param name="cancellationToken">The cancellation token. Defaults to <see cref="CancellationToken.None"/>.</param>
/// <returns>Affected rows count.</returns>
/// <example>This sample shows how to make a hand-tuned database call.
/// <code>
Expand All @@ -94,10 +94,10 @@ internal interface IRelationalStorage
/// //There aren't parameters here, but they'd be added like when reading.
/// //As the affected rows count is the only thing returned, there isn't
/// //facilities to read anything.
/// }).ConfigureAwait(continueOnCapturedContext: false);
/// }).ConfigureAwait(continueOnCapturedContext: false);
/// </code>
/// </example>
Task<int> ExecuteAsync(string query, Action<IDbCommand> parameterProvider, CancellationToken cancellationToken = default(CancellationToken), CommandBehavior commandBehavior = CommandBehavior.Default);
Task<int> ExecuteAsync(string query, Action<IDbCommand> parameterProvider, CommandBehavior commandBehavior = CommandBehavior.Default, CancellationToken cancellationToken = default(CancellationToken));

/// <summary>
/// The well known invariant name of the underlying database.
Expand Down
38 changes: 19 additions & 19 deletions src/AdoNet/Shared/Storage/RelationalStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Orleans.Tests.SqlUtils
{
/// <summary>
/// A general purpose class to work with a given relational database and ADO.NET provider.
/// </summary>
/// </summary>
[DebuggerDisplay("InvariantName = {InvariantName}, ConnectionString = {ConnectionString}")]
internal class RelationalStorage: IRelationalStorage
{
Expand Down Expand Up @@ -103,11 +103,11 @@ public static IRelationalStorage CreateInstance(string invariantName, string con
/// Executes a given statement. Especially intended to use with <em>SELECT</em> statement.
/// </summary>
/// <typeparam name="TResult">The result type.</typeparam>
/// <param name="query">Executes a given statement. Especially intended to use with <em>SELECT</em> statement.</param>
/// <param name="query">Executes a given statement. Especially intended to use with <em>SELECT</em> statement.</param>
/// <param name="parameterProvider">Adds parameters to the query. Parameter names must match those defined in the query.</param>
/// <param name="selector">This function transforms the raw <see cref="IDataRecord"/> results to type <see paramref="TResult"/> the <see cref="int"/> parameter being the resultset number.</param>
/// <param name="cancellationToken">The cancellation token. Defaults to <see cref="CancellationToken.None"/>.</param>
/// <param name="commandBehavior">The command behavior that should be used. Defaults to <see cref="CommandBehavior.Default"/>.</param>
/// <param name="cancellationToken">The cancellation token. Defaults to <see cref="CancellationToken.None"/>.</param>
/// <returns>A list of objects as a result of the <see paramref="query"/>.</returns>
/// <example>This sample shows how to make a hand-tuned database call.
/// <code>
Expand All @@ -132,7 +132,7 @@ public static IRelationalStorage CreateInstance(string invariantName, string con
/// tp1.DbType = DbType.String;
/// tp1.Direction = ParameterDirection.Input;
/// command.Parameters.Add(tp1);
///
///
/// //The selector is used to select the results within the result set. In this case there are two homogenous
/// //result sets, so there is actually no need to check which result set the selector holds and it could
/// //marked with by convention by underscore (_).
Expand All @@ -144,11 +144,11 @@ public static IRelationalStorage CreateInstance(string invariantName, string con
/// {
/// TABLE_CATALOG = selector.GetValueOrDefault&lt;string&gt;("TABLE_CATALOG"),
/// TABLE_NAME = selector.GetValueOrDefault&lt;string&gt;("TABLE_NAME")
/// }
///}).ConfigureAwait(continueOnCapturedContext: false);
/// }
///}).ConfigureAwait(continueOnCapturedContext: false);
/// </code>
/// </example>
public async Task<IEnumerable<TResult>> ReadAsync<TResult>(string query, Action<IDbCommand> parameterProvider, Func<IDataRecord, int, CancellationToken, Task<TResult>> selector, CancellationToken cancellationToken = default(CancellationToken), CommandBehavior commandBehavior = CommandBehavior.Default)
public async Task<IEnumerable<TResult>> ReadAsync<TResult>(string query, Action<IDbCommand> parameterProvider, Func<IDataRecord, int, CancellationToken, Task<TResult>> selector, CommandBehavior commandBehavior = CommandBehavior.Default, CancellationToken cancellationToken = default(CancellationToken))
{
//If the query is something else that is not acceptable (e.g. an empty string), there will an appropriate database exception.
if(query == null)
Expand All @@ -161,7 +161,7 @@ public static IRelationalStorage CreateInstance(string invariantName, string con
throw new ArgumentNullException(nameof(selector));
}

return (await ExecuteAsync(query, parameterProvider, ExecuteReaderAsync, selector, cancellationToken, commandBehavior).ConfigureAwait(false)).Item1;
return (await ExecuteAsync(query, parameterProvider, ExecuteReaderAsync, selector, commandBehavior, cancellationToken).ConfigureAwait(false)).Item1;
}


Expand All @@ -170,8 +170,8 @@ public static IRelationalStorage CreateInstance(string invariantName, string con
/// </summary>
/// <param name="query">The query to execute.</param>
/// <param name="parameterProvider">Adds parameters to the query. Parameter names must match those defined in the query.</param>
/// <param name="cancellationToken">The cancellation token. Defaults to <see cref="CancellationToken.None"/>.</param>
/// <param name="commandBehavior">The command behavior that should be used. Defaults to <see cref="CommandBehavior.Default"/>.</param>
/// <param name="cancellationToken">The cancellation token. Defaults to <see cref="CancellationToken.None"/>.</param>
/// <returns>Affected rows count.</returns>
/// <example>This sample shows how to make a hand-tuned database call.
/// <code>
Expand All @@ -183,18 +183,18 @@ public static IRelationalStorage CreateInstance(string invariantName, string con
/// //There aren't parameters here, but they'd be added like when reading.
/// //As the affected rows count is the only thing returned, there isn't
/// //facilities to read anything.
/// }).ConfigureAwait(continueOnCapturedContext: false);
/// }).ConfigureAwait(continueOnCapturedContext: false);
/// </code>
/// </example>
public async Task<int> ExecuteAsync(string query, Action<IDbCommand> parameterProvider, CancellationToken cancellationToken = default(CancellationToken), CommandBehavior commandBehavior = CommandBehavior.Default)
public async Task<int> ExecuteAsync(string query, Action<IDbCommand> parameterProvider, CommandBehavior commandBehavior = CommandBehavior.Default, CancellationToken cancellationToken = default(CancellationToken))
{
//If the query is something else that is not acceptable (e.g. an empty string), there will an appropriate database exception.
if(query == null)
{
throw new ArgumentNullException(nameof(query));
}

return (await ExecuteAsync(query, parameterProvider, ExecuteReaderAsync, (unit, id, c) => Task.FromResult(unit), cancellationToken, commandBehavior).ConfigureAwait(false)).Item2;
return (await ExecuteAsync(query, parameterProvider, ExecuteReaderAsync, (unit, id, c) => Task.FromResult(unit), commandBehavior, cancellationToken).ConfigureAwait(false)).Item2;
}

/// <summary>
Expand Down Expand Up @@ -231,7 +231,7 @@ private static async Task<Tuple<IEnumerable<TResult>, int>> SelectAsync<TResult>
}


private async Task<Tuple<IEnumerable<TResult>, int>> ExecuteReaderAsync<TResult>(DbCommand command, Func<IDataRecord, int, CancellationToken, Task<TResult>> selector, CancellationToken cancellationToken, CommandBehavior commandBehavior)
private async Task<Tuple<IEnumerable<TResult>, int>> ExecuteReaderAsync<TResult>(DbCommand command, Func<IDataRecord, int, CancellationToken, Task<TResult>> selector, CommandBehavior commandBehavior, CancellationToken cancellationToken)
{
using(var reader = await command.ExecuteReaderAsync(commandBehavior, cancellationToken).ConfigureAwait(continueOnCapturedContext: false))
{
Expand All @@ -250,15 +250,15 @@ private async Task<Tuple<IEnumerable<TResult>, int>> ExecuteReaderAsync<TResult>
}
}
}


private async Task<Tuple<IEnumerable<TResult>, int>> ExecuteAsync<TResult>(
string query,
Action<DbCommand> parameterProvider,
Func<DbCommand, Func<IDataRecord, int, CancellationToken, Task<TResult>>, CancellationToken, CommandBehavior, Task<Tuple<IEnumerable<TResult>, int>>> executor,
Func<DbCommand, Func<IDataRecord, int, CancellationToken, Task<TResult>>, CommandBehavior, CancellationToken, Task<Tuple<IEnumerable<TResult>, int>>> executor,
Func<IDataRecord, int, CancellationToken, Task<TResult>> selector,
CancellationToken cancellationToken,
CommandBehavior commandBehavior)
CommandBehavior commandBehavior,
CancellationToken cancellationToken)
{
using (var connection = DbConnectionFactory.CreateConnection(invariantName, connectionString))
{
Expand All @@ -273,11 +273,11 @@ private async Task<Tuple<IEnumerable<TResult>, int>> ExecuteAsync<TResult>(
Task<Tuple<IEnumerable<TResult>, int>> ret;
if(isSynchronousAdoNetImplementation)
{
ret = Task.Run(() => executor(command, selector, cancellationToken, commandBehavior), cancellationToken);
ret = Task.Run(() => executor(command, selector, commandBehavior, cancellationToken), cancellationToken);
}
else
{
ret = executor(command, selector, cancellationToken, commandBehavior);
ret = executor(command, selector, commandBehavior, cancellationToken);
}

return await ret.ConfigureAwait(continueOnCapturedContext: false);
Expand Down
Loading

0 comments on commit ea3372c

Please sign in to comment.