Skip to content

Commit

Permalink
Address all IDE0251 warnings and naming inconsistencies. (#8617)
Browse files Browse the repository at this point in the history
* Address all IDE0251 warnings and naming inconsistencies.

* A few more naming issues

* Update src/Orleans.Serialization/Buffers/Writer.cs
  • Loading branch information
IEvangelist authored Sep 1, 2023
1 parent 7bd86bf commit 28256db
Show file tree
Hide file tree
Showing 27 changed files with 530 additions and 527 deletions.
184 changes: 92 additions & 92 deletions src/AWS/Shared/Storage/DynamoDBStorage.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,30 @@ namespace Orleans.Runtime.Membership
{
public class AdoNetGatewayListProvider : IGatewayListProvider
{
private readonly ILogger logger;
private readonly string clusterId;
private readonly AdoNetClusteringClientOptions options;
private RelationalOrleansQueries orleansQueries;
private readonly IServiceProvider serviceProvider;
private readonly TimeSpan maxStaleness;
private readonly ILogger _logger;
private readonly string _clusterId;
private readonly AdoNetClusteringClientOptions _options;
private RelationalOrleansQueries _orleansQueries;
private readonly IServiceProvider _serviceProvider;
private readonly TimeSpan _maxStaleness;

public AdoNetGatewayListProvider(
ILogger<AdoNetGatewayListProvider> logger,
IServiceProvider serviceProvider,
IOptions<AdoNetClusteringClientOptions> options,
IOptions<GatewayOptions> gatewayOptions,
IOptions<ClusterOptions> clusterOptions)
{
this.logger = logger;
this.serviceProvider = serviceProvider;
this.options = options.Value;
this.clusterId = clusterOptions.Value.ClusterId;
this.maxStaleness = gatewayOptions.Value.GatewayListRefreshPeriod;
this._logger = logger;
this._serviceProvider = serviceProvider;
this._options = options.Value;
this._clusterId = clusterOptions.Value.ClusterId;
this._maxStaleness = gatewayOptions.Value.GatewayListRefreshPeriod;
}

public TimeSpan MaxStaleness
{
get { return this.maxStaleness; }
get { return this._maxStaleness; }
}

public bool IsUpdatable
Expand All @@ -43,20 +44,20 @@ public bool IsUpdatable

public async Task InitializeGatewayListProvider()
{
if (logger.IsEnabled(LogLevel.Trace)) logger.LogTrace("AdoNetClusteringTable.InitializeGatewayListProvider called.");
orleansQueries = await RelationalOrleansQueries.CreateInstance(options.Invariant, options.ConnectionString);
if (_logger.IsEnabled(LogLevel.Trace)) _logger.LogTrace("AdoNetClusteringTable.InitializeGatewayListProvider called.");
_orleansQueries = await RelationalOrleansQueries.CreateInstance(_options.Invariant, _options.ConnectionString);
}

public async Task<IList<Uri>> GetGateways()
{
if (logger.IsEnabled(LogLevel.Trace)) logger.LogTrace("AdoNetClusteringTable.GetGateways called.");
if (_logger.IsEnabled(LogLevel.Trace)) _logger.LogTrace("AdoNetClusteringTable.GetGateways called.");
try
{
return await orleansQueries.ActiveGatewaysAsync(this.clusterId);
return await _orleansQueries.ActiveGatewaysAsync(this._clusterId);
}
catch (Exception ex)
{
if (logger.IsEnabled(LogLevel.Debug)) logger.LogDebug(ex, "AdoNetClusteringTable.Gateways failed");
if (_logger.IsEnabled(LogLevel.Debug)) _logger.LogDebug(ex, "AdoNetClusteringTable.Gateways failed");
throw;
}
}
Expand Down
55 changes: 27 additions & 28 deletions src/AdoNet/Shared/Storage/RelationalStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,34 @@ namespace Orleans.Tests.SqlUtils
/// A general purpose class to work with a given relational database and ADO.NET provider.
/// </summary>
[DebuggerDisplay("InvariantName = {InvariantName}, ConnectionString = {ConnectionString}")]
internal class RelationalStorage: IRelationalStorage
internal class RelationalStorage : IRelationalStorage
{
/// <summary>
/// The connection string to use.
/// </summary>
private readonly string connectionString;
private readonly string _connectionString;

/// <summary>
/// The invariant name of the connector for this database.
/// </summary>
private readonly string invariantName;
private readonly string _invariantName;

/// <summary>
/// If the ADO.NET provider of this storage supports cancellation or not. This
/// capability is queried and the result is cached here.
/// </summary>
private readonly bool supportsCommandCancellation;
private readonly bool _supportsCommandCancellation;

/// <summary>
/// If the underlying ADO.NET implementation is natively asynchronous
/// (the ADO.NET Db*.XXXAsync classes are overridden) or not.
/// </summary>
private readonly bool isSynchronousAdoNetImplementation;
private readonly bool _isSynchronousAdoNetImplementation;

/// <summary>
/// Command interceptor for the given data provider.
/// </summary>
private readonly ICommandInterceptor databaseCommandInterceptor;

private readonly ICommandInterceptor _databaseCommandInterceptor;

/// <summary>
/// The invariant name of the connector for this database.
Expand All @@ -60,7 +59,7 @@ public string InvariantName
{
get
{
return invariantName;
return _invariantName;
}
}

Expand All @@ -72,7 +71,7 @@ public string ConnectionString
{
get
{
return connectionString;
return _connectionString;
}
}

Expand All @@ -85,12 +84,12 @@ public string ConnectionString
/// <returns></returns>
public static IRelationalStorage CreateInstance(string invariantName, string connectionString)
{
if(string.IsNullOrWhiteSpace(invariantName))
if (string.IsNullOrWhiteSpace(invariantName))
{
throw new ArgumentException("The name of invariant must contain characters", nameof(invariantName));
}

if(string.IsNullOrWhiteSpace(connectionString))
if (string.IsNullOrWhiteSpace(connectionString))
{
throw new ArgumentException("Connection string must contain characters", nameof(connectionString));
}
Expand Down Expand Up @@ -151,12 +150,12 @@ public static IRelationalStorage CreateInstance(string invariantName, string con
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)
{
//If the query is something else that is not acceptable (e.g. an empty string), there will an appropriate database exception.
if(query == null)
if (query == null)
{
throw new ArgumentNullException(nameof(query));
}

if(selector == null)
if (selector == null)
{
throw new ArgumentNullException(nameof(selector));
}
Expand Down Expand Up @@ -189,7 +188,7 @@ public async Task<IEnumerable<TResult>> ReadAsync<TResult>(string query, Action<
public async Task<int> ExecuteAsync(string query, Action<IDbCommand> parameterProvider, CommandBehavior commandBehavior = CommandBehavior.Default, CancellationToken cancellationToken = default)
{
//If the query is something else that is not acceptable (e.g. an empty string), there will an appropriate database exception.
if(query == null)
if (query == null)
{
throw new ArgumentNullException(nameof(query));
}
Expand All @@ -204,20 +203,20 @@ public async Task<int> ExecuteAsync(string query, Action<IDbCommand> parameterPr
/// <param name="connectionString">The connection string this database should use for database operations.</param>
private RelationalStorage(string invariantName, string connectionString)
{
this.connectionString = connectionString;
this.invariantName = invariantName;
supportsCommandCancellation = DbConstantsStore.SupportsCommandCancellation(InvariantName);
isSynchronousAdoNetImplementation = DbConstantsStore.IsSynchronousAdoNetImplementation(InvariantName);
this.databaseCommandInterceptor = DbConstantsStore.GetDatabaseCommandInterceptor(InvariantName);
this._connectionString = connectionString;
this._invariantName = invariantName;
_supportsCommandCancellation = DbConstantsStore.SupportsCommandCancellation(InvariantName);
_isSynchronousAdoNetImplementation = DbConstantsStore.IsSynchronousAdoNetImplementation(InvariantName);
this._databaseCommandInterceptor = DbConstantsStore.GetDatabaseCommandInterceptor(InvariantName);
}

private static async Task<Tuple<IEnumerable<TResult>, int>> SelectAsync<TResult>(DbDataReader reader, Func<IDataReader, int, CancellationToken, Task<TResult>> selector, CancellationToken cancellationToken)
{
var results = new List<TResult>();
int resultSetCount = 0;
while(reader.HasRows)
while (reader.HasRows)
{
while(await reader.ReadAsync(cancellationToken).ConfigureAwait(continueOnCapturedContext: false))
while (await reader.ReadAsync(cancellationToken).ConfigureAwait(continueOnCapturedContext: false))
{
var obj = await selector(reader, resultSetCount, cancellationToken).ConfigureAwait(false);
results.Add(obj);
Expand All @@ -233,12 +232,12 @@ 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, CommandBehavior commandBehavior, CancellationToken cancellationToken)
{
using(var reader = await command.ExecuteReaderAsync(commandBehavior, cancellationToken).ConfigureAwait(continueOnCapturedContext: false))
using (var reader = await command.ExecuteReaderAsync(commandBehavior, cancellationToken).ConfigureAwait(continueOnCapturedContext: false))
{
CancellationTokenRegistration cancellationRegistration = default;
try
{
if(cancellationToken.CanBeCanceled && supportsCommandCancellation)
if (cancellationToken.CanBeCanceled && _supportsCommandCancellation)
{
cancellationRegistration = cancellationToken.Register(CommandCancellation, Tuple.Create(reader, command), useSynchronizationContext: false);
}
Expand All @@ -260,18 +259,18 @@ private async Task<Tuple<IEnumerable<TResult>, int>> ExecuteAsync<TResult>(
CommandBehavior commandBehavior,
CancellationToken cancellationToken)
{
using (var connection = DbConnectionFactory.CreateConnection(invariantName, connectionString))
using (var connection = DbConnectionFactory.CreateConnection(_invariantName, _connectionString))
{
await connection.OpenAsync(cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
using(var command = connection.CreateCommand())
using (var command = connection.CreateCommand())
{
parameterProvider?.Invoke(command);
command.CommandText = query;

databaseCommandInterceptor.Intercept(command);
_databaseCommandInterceptor.Intercept(command);

Task<Tuple<IEnumerable<TResult>, int>> ret;
if(isSynchronousAdoNetImplementation)
if (_isSynchronousAdoNetImplementation)
{
ret = Task.Run(() => executor(command, selector, commandBehavior, cancellationToken), cancellationToken);
}
Expand All @@ -293,7 +292,7 @@ private static void CommandCancellation(object state)
//despite the connection already closed. Source: https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.cancel(v=vs.110).aspx.
//Enforcing this behavior across all providers does not seem to hurt.
var stateTuple = (Tuple<DbDataReader, DbCommand>)state;
if(!stateTuple.Item1.IsClosed)
if (!stateTuple.Item1.IsClosed)
{
stateTuple.Item2.Cancel();
}
Expand Down
96 changes: 48 additions & 48 deletions src/Orleans.CodeGenerator/LibraryTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,18 @@ private LibraryTypes(Compilation compilation, CodeGeneratorOptions options)
Task = Type("System.Threading.Tasks.Task");
Task_1 = Type("System.Threading.Tasks.Task`1");
this.Type = Type("System.Type");
Uri = Type("System.Uri");
Int128 = TypeOrDefault("System.Int128");
UInt128 = TypeOrDefault("System.UInt128");
Half = TypeOrDefault("System.Half");
DateOnly = TypeOrDefault("System.DateOnly");
DateTimeOffset = Type("System.DateTimeOffset");
BitVector32 = Type("System.Collections.Specialized.BitVector32");
Guid = Type("System.Guid");
CompareInfo = Type("System.Globalization.CompareInfo");
CultureInfo = Type("System.Globalization.CultureInfo");
Version = Type("System.Version");
TimeOnly = TypeOrDefault("System.TimeOnly");
_uri = Type("System.Uri");
_int128 = TypeOrDefault("System.Int128");
_uInt128 = TypeOrDefault("System.UInt128");
_half = TypeOrDefault("System.Half");
_dateOnly = TypeOrDefault("System.DateOnly");
_dateTimeOffset = Type("System.DateTimeOffset");
_bitVector32 = Type("System.Collections.Specialized.BitVector32");
_guid = Type("System.Guid");
_compareInfo = Type("System.Globalization.CompareInfo");
_cultureInfo = Type("System.Globalization.CultureInfo");
_version = Type("System.Version");
_timeOnly = TypeOrDefault("System.TimeOnly");
ICodecProvider = Type("Orleans.Serialization.Serializers.ICodecProvider");
ValueSerializer = Type("Orleans.Serialization.Serializers.IValueSerializer`1");
ValueTask = Type("System.Threading.Tasks.ValueTask");
Expand Down Expand Up @@ -148,10 +148,10 @@ private LibraryTypes(Compilation compilation, CodeGeneratorOptions options)
Exception = Type("System.Exception");
ImmutableAttributes = options.ImmutableAttributes.Select(Type).ToArray();
TimeSpan = Type("System.TimeSpan");
IPAddress = Type("System.Net.IPAddress");
IPEndPoint = Type("System.Net.IPEndPoint");
CancellationToken = Type("System.Threading.CancellationToken");
ImmutableContainerTypes = new[]
_ipAddress = Type("System.Net.IPAddress");
_ipEndPoint = Type("System.Net.IPEndPoint");
_cancellationToken = Type("System.Threading.CancellationToken");
_immutableContainerTypes = new[]
{
compilation.GetSpecialType(SpecialType.System_Nullable_T),
Type("System.Tuple`1"),
Expand Down Expand Up @@ -227,10 +227,10 @@ INamedTypeSymbol Type(string metadataName)
public INamedTypeSymbol Task { get; private set; }
public INamedTypeSymbol Task_1 { get; private set; }
public INamedTypeSymbol Type { get; private set; }
private readonly INamedTypeSymbol Uri;
private readonly INamedTypeSymbol? DateOnly;
private readonly INamedTypeSymbol DateTimeOffset;
private readonly INamedTypeSymbol? TimeOnly;
private INamedTypeSymbol _uri;
private INamedTypeSymbol? _dateOnly;
private INamedTypeSymbol _dateTimeOffset;
private INamedTypeSymbol? _timeOnly;
public INamedTypeSymbol MethodInfo { get; private set; }
public INamedTypeSymbol ICodecProvider { get; private set; }
public INamedTypeSymbol ValueSerializer { get; private set; }
Expand All @@ -257,38 +257,38 @@ INamedTypeSymbol Type(string metadataName)
public INamedTypeSymbol CopyContext { get; private set; }
public Compilation Compilation { get; private set; }
public INamedTypeSymbol TimeSpan { get; private set; }
private readonly INamedTypeSymbol IPAddress;
private readonly INamedTypeSymbol IPEndPoint;
private readonly INamedTypeSymbol CancellationToken;
private readonly INamedTypeSymbol[] ImmutableContainerTypes;
private readonly INamedTypeSymbol Guid;
private readonly INamedTypeSymbol BitVector32;
private readonly INamedTypeSymbol CompareInfo;
private readonly INamedTypeSymbol CultureInfo;
private readonly INamedTypeSymbol Version;
private readonly INamedTypeSymbol? Int128;
private readonly INamedTypeSymbol? UInt128;
private readonly INamedTypeSymbol? Half;
private INamedTypeSymbol _ipAddress;
private INamedTypeSymbol _ipEndPoint;
private INamedTypeSymbol _cancellationToken;
private INamedTypeSymbol[] _immutableContainerTypes;
private INamedTypeSymbol _guid;
private INamedTypeSymbol _bitVector32;
private INamedTypeSymbol _compareInfo;
private INamedTypeSymbol _cultureInfo;
private INamedTypeSymbol _version;
private INamedTypeSymbol? _int128;
private INamedTypeSymbol? _uInt128;
private INamedTypeSymbol? _half;
private INamedTypeSymbol[]? _regularShallowCopyableTypes;
private INamedTypeSymbol[] RegularShallowCopyableType => _regularShallowCopyableTypes ??= new List<INamedTypeSymbol?>
{
TimeSpan,
DateOnly,
TimeOnly,
DateTimeOffset,
Guid,
BitVector32,
CompareInfo,
CultureInfo,
Version,
IPAddress,
IPEndPoint,
CancellationToken,
_dateOnly,
_timeOnly,
_dateTimeOffset,
_guid,
_bitVector32,
_compareInfo,
_cultureInfo,
_version,
_ipAddress,
_ipEndPoint,
_cancellationToken,
Type,
Uri,
UInt128,
Int128,
Half
_uri,
_uInt128,
_int128,
_half
}.Where(t => t is {}).ToArray()!;

public INamedTypeSymbol[] ImmutableAttributes { get; private set; }
Expand Down Expand Up @@ -368,7 +368,7 @@ public bool IsShallowCopyable(ITypeSymbol type)
else if (namedType.IsGenericType)
{
var def = namedType.ConstructedFrom;
foreach (var t in ImmutableContainerTypes)
foreach (var t in _immutableContainerTypes)
{
if (SymbolEqualityComparer.Default.Equals(t, def))
return _shallowCopyableTypes[type] = AreShallowCopyable(namedType.TypeArguments);
Expand Down
Loading

0 comments on commit 28256db

Please sign in to comment.