Downgraded language version to 8

Hasn't seem to cause any issues in older .NET versions yet (only used new syntax features), but this will prevent using most unsupported new features for .NET Standard 2.0
This commit is contained in:
Mark van Renswoude 2022-02-13 10:36:04 +01:00
parent 927485f1cd
commit d6138e2cfa
15 changed files with 50 additions and 52 deletions

View File

@ -20,7 +20,7 @@ namespace Tapeti.Connection
internal class TapetiChannel
{
private readonly Func<IModel> modelFactory;
private readonly object taskQueueLock = new();
private readonly object taskQueueLock = new object();
private SingleThreadTaskQueue taskQueue;
private readonly ModelProvider modelProvider;

View File

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
@ -50,7 +50,7 @@ namespace Tapeti.Connection
private readonly HttpClient managementClient;
// These fields must be locked using connectionLock
private readonly object connectionLock = new();
private readonly object connectionLock = new object();
private long connectionReference;
private RabbitMQ.Client.IConnection connection;
private IModel consumeChannelModel;
@ -61,12 +61,12 @@ namespace Tapeti.Connection
// These fields are for use in a single TapetiChannel's queue only!
private ulong lastDeliveryTag;
private readonly HashSet<string> deletedQueues = new();
private readonly HashSet<string> deletedQueues = new HashSet<string>();
// These fields must be locked using confirmLock, since the callbacks for BasicAck/BasicReturn can run in a different thread
private readonly object confirmLock = new();
private readonly Dictionary<ulong, ConfirmMessageInfo> confirmMessages = new();
private readonly Dictionary<string, ReturnInfo> returnRoutingKeys = new();
private readonly object confirmLock = new object();
private readonly Dictionary<ulong, ConfirmMessageInfo> confirmMessages = new Dictionary<ulong, ConfirmMessageInfo>();
private readonly Dictionary<string, ReturnInfo> returnRoutingKeys = new Dictionary<string, ReturnInfo>();
private class ConfirmMessageInfo
@ -184,18 +184,15 @@ namespace Tapeti.Connection
var replyCode = publishResultTask.Result;
switch (replyCode)
{
// There is no RabbitMQ.Client.Framing.Constants value for this "No route" reply code
// at the time of writing...
case 312:
throw new NoRouteException(
$"Mandatory message with exchange '{exchange}' and routing key '{routingKey}' does not have a route");
case > 0:
throw new NoRouteException(
$"Mandatory message with exchange '{exchange}' and routing key '{routingKey}' could not be delivered, reply code: {replyCode}");
}
// There is no RabbitMQ.Client.Framing.Constants value for this "No route" reply code
// at the time of writing...
if (replyCode == 312)
throw new NoRouteException(
$"Mandatory message with exchange '{exchange}' and routing key '{routingKey}' does not have a route");
if (replyCode > 0)
throw new NoRouteException(
$"Mandatory message with exchange '{exchange}' and routing key '{routingKey}' could not be delivered, reply code: {replyCode}");
});
}
@ -526,7 +523,7 @@ namespace Tapeti.Connection
}
private static readonly List<HttpStatusCode> TransientStatusCodes = new()
private static readonly List<HttpStatusCode> TransientStatusCodes = new List<HttpStatusCode>()
{
HttpStatusCode.GatewayTimeout,
HttpStatusCode.RequestTimeout,
@ -663,7 +660,7 @@ namespace Tapeti.Connection
}
catch (WebException e)
{
if (e.Response is not HttpWebResponse response)
if (!(e.Response is HttpWebResponse response))
throw;
if (!TransientStatusCodes.Contains(response.StatusCode))
@ -678,7 +675,7 @@ namespace Tapeti.Connection
}
private readonly HashSet<string> declaredExchanges = new();
private readonly HashSet<string> declaredExchanges = new HashSet<string>();
private void DeclareExchange(IModel channel, string exchange)
{
@ -845,7 +842,7 @@ namespace Tapeti.Connection
GetTapetiChannel(TapetiChannelType.Consume).QueueRetryable(_ => { });
};
capturedPublishChannelModel.ModelShutdown += (_, _) =>
capturedPublishChannelModel.ModelShutdown += (sender, args) =>
{
lock (connectionLock)
{

View File

@ -172,7 +172,8 @@ namespace Tapeti.Connection
return e switch
{
AggregateException aggregateException => aggregateException.InnerExceptions.Any(IgnoreExceptionDuringShutdown),
TaskCanceledException or OperationCanceledException => true,
TaskCanceledException _ => true,
OperationCanceledException _ => true,
_ => e.InnerException != null && IgnoreExceptionDuringShutdown(e.InnerException)
};
}

View File

@ -13,7 +13,7 @@ namespace Tapeti.Connection
private readonly Func<ITapetiClient> clientFactory;
private readonly ITapetiConfig config;
private bool consuming;
private readonly List<TapetiConsumerTag> consumerTags = new();
private readonly List<TapetiConsumerTag> consumerTags = new List<TapetiConsumerTag>();
private CancellationTokenSource initializeCancellationTokenSource;
@ -167,7 +167,7 @@ namespace Tapeti.Connection
public List<Type> MessageClasses;
}
private readonly Dictionary<string, List<DynamicQueueInfo>> dynamicQueues = new();
private readonly Dictionary<string, List<DynamicQueueInfo>> dynamicQueues = new Dictionary<string, List<DynamicQueueInfo>>();
protected CustomBindingTarget(Func<ITapetiClient> clientFactory, IRoutingKeyStrategy routingKeyStrategy, IExchangeStrategy exchangeStrategy, CancellationToken cancellationToken)
@ -278,8 +278,8 @@ namespace Tapeti.Connection
private class DeclareDurableQueuesBindingTarget : CustomBindingTarget
{
private readonly Dictionary<string, List<Type>> durableQueues = new();
private readonly HashSet<string> obsoleteDurableQueues = new();
private readonly Dictionary<string, List<Type>> durableQueues = new Dictionary<string, List<Type>>();
private readonly HashSet<string> obsoleteDurableQueues = new HashSet<string>();
public DeclareDurableQueuesBindingTarget(Func<ITapetiClient> clientFactory, IRoutingKeyStrategy routingKeyStrategy, IExchangeStrategy exchangeStrategy, CancellationToken cancellationToken) : base(clientFactory, routingKeyStrategy, exchangeStrategy, cancellationToken)
@ -359,7 +359,7 @@ namespace Tapeti.Connection
private class PassiveDurableQueuesBindingTarget : CustomBindingTarget
{
private readonly HashSet<string> durableQueues = new();
private readonly HashSet<string> durableQueues = new HashSet<string>();
public PassiveDurableQueuesBindingTarget(Func<ITapetiClient> clientFactory, IRoutingKeyStrategy routingKeyStrategy, IExchangeStrategy exchangeStrategy, CancellationToken cancellationToken) : base(clientFactory, routingKeyStrategy, exchangeStrategy, cancellationToken)

View File

@ -9,7 +9,7 @@ namespace Tapeti.Default
internal class ControllerBindingContext : IControllerBindingContext
{
private BindingTargetMode? bindingTargetMode;
private readonly List<IControllerMiddlewareBase> middleware = new();
private readonly List<IControllerMiddlewareBase> middleware = new List<IControllerMiddlewareBase>();
private readonly List<ControllerBindingParameter> parameters;
private readonly ControllerBindingResult result;

View File

@ -16,8 +16,8 @@ namespace Tapeti.Default
private const string ClassTypeHeader = "classType";
private readonly ConcurrentDictionary<string, Type> deserializedTypeNames = new();
private readonly ConcurrentDictionary<Type, string> serializedTypeNames = new();
private readonly ConcurrentDictionary<string, Type> deserializedTypeNames = new ConcurrentDictionary<string, Type>();
private readonly ConcurrentDictionary<Type, string> serializedTypeNames = new ConcurrentDictionary<Type, string>();
private readonly JsonSerializerSettings serializerSettings;
@ -49,7 +49,7 @@ namespace Tapeti.Default
/// <inheritdoc />
public object Deserialize(byte[] body, IMessageProperties properties)
{
if (properties.ContentType is not ContentType)
if (!(properties.ContentType is ContentType))
throw new ArgumentException($"content_type must be {ContentType}");
var typeName = properties.GetHeader(ClassTypeHeader);

View File

@ -8,7 +8,7 @@ namespace Tapeti.Default
{
internal class MessageContext : IMessageContext
{
private readonly Dictionary<Type, IMessageContextPayload> payloads = new();
private readonly Dictionary<Type, IMessageContextPayload> payloads = new Dictionary<Type, IMessageContextPayload>();
/// <inheritdoc />
@ -117,7 +117,7 @@ namespace Tapeti.Default
// ReSharper disable once InconsistentNaming
public class KeyValuePayload : IMessageContextPayload, IDisposable, IAsyncDisposable
{
private readonly Dictionary<string, object> items = new();
private readonly Dictionary<string, object> items = new Dictionary<string, object>();
public KeyValuePayload(string key, object value)

View File

@ -10,7 +10,7 @@ namespace Tapeti.Default
/// </summary>
public class MessageProperties : IMessageProperties
{
private readonly Dictionary<string, string> headers = new();
private readonly Dictionary<string, string> headers = new Dictionary<string, string>();
/// <inheritdoc />

View File

@ -13,7 +13,7 @@ namespace Tapeti.Default
/// </example>
public class NamespaceMatchExchangeStrategy : IExchangeStrategy
{
private static readonly Regex NamespaceRegex = new("^(Messaging\\.)?(?<exchange>[^\\.]+)", RegexOptions.Compiled | RegexOptions.Singleline);
private static readonly Regex NamespaceRegex = new Regex("^(Messaging\\.)?(?<exchange>[^\\.]+)", RegexOptions.Compiled | RegexOptions.Singleline);
/// <inheritdoc />

View File

@ -28,9 +28,9 @@ namespace Tapeti.Default
(?(?<=[A-Z])[A-Z](?=[a-z])|[A-Z])
)";
private static readonly Regex SeparatorRegex = new(SeparatorPattern, RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled);
private static readonly Regex SeparatorRegex = new Regex(SeparatorPattern, RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled);
private static readonly ConcurrentDictionary<Type, string> RoutingKeyCache = new();
private static readonly ConcurrentDictionary<Type, string> RoutingKeyCache = new ConcurrentDictionary<Type, string>();
/// <inheritdoc />

View File

@ -10,7 +10,7 @@ namespace Tapeti.Helpers
/// </summary>
public class ConnectionStringParser
{
private readonly TapetiConnectionParams result = new();
private readonly TapetiConnectionParams result = new TapetiAppSettingsConnectionParams();
private readonly string connectionstring;
private int pos = -1;

View File

@ -11,7 +11,7 @@
<PackageLicenseExpression>Unlicense</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/MvRens/Tapeti</PackageProjectUrl>
<PackageIcon>Tapeti.png</PackageIcon>
<LangVersion>latest</LangVersion>
<LangVersion>8</LangVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

View File

@ -18,7 +18,7 @@ namespace Tapeti
public class TapetiConfig : ITapetiConfigBuilder, ITapetiConfigBuilderAccess
{
private Config config;
private readonly List<IControllerBindingMiddleware> bindingMiddleware = new();
private readonly List<IControllerBindingMiddleware> bindingMiddleware = new List<IControllerBindingMiddleware>();
/// <inheritdoc />
@ -189,7 +189,7 @@ namespace Tapeti
/// </summary>
protected void RegisterDefaults()
{
if (DependencyResolver is not IDependencyContainer container)
if (!(DependencyResolver is IDependencyContainer container))
return;
if (ConsoleHelper.IsAvailable())
@ -225,9 +225,9 @@ namespace Tapeti
/// <inheritdoc />
internal class Config : ITapetiConfig
{
private readonly ConfigFeatures features = new();
private readonly ConfigMiddleware middleware = new();
private readonly ConfigBindings bindings = new();
private readonly ConfigFeatures features = new ConfigFeatures();
private readonly ConfigMiddleware middleware = new ConfigMiddleware();
private readonly ConfigBindings bindings = new ConfigBindings();
public IDependencyResolver DependencyResolver { get; }
public ITapetiConfigFeatues Features => features;
@ -291,8 +291,8 @@ namespace Tapeti
internal class ConfigMiddleware : ITapetiConfigMiddleware
{
private readonly List<IMessageMiddleware> messageMiddleware = new();
private readonly List<IPublishMiddleware> publishMiddleware = new();
private readonly List<IMessageMiddleware> messageMiddleware = new List<IMessageMiddleware>();
private readonly List<IPublishMiddleware> publishMiddleware = new List<IPublishMiddleware>();
public IReadOnlyList<IMessageMiddleware> Message => messageMiddleware;

View File

@ -79,7 +79,7 @@ namespace Tapeti
}
var methodQueueInfo = GetQueueInfo(method) ?? controllerQueueInfo;
if (methodQueueInfo is not { IsValid: true })
if (!(methodQueueInfo is { IsValid: true }))
throw new TopologyConfigurationException(
$"Method {method.Name} or controller {controller.Name} requires a queue attribute");

View File

@ -12,10 +12,10 @@ namespace Tapeti.Tasks
/// </summary>
public class SingleThreadTaskQueue : IDisposable
{
private readonly object previousTaskLock = new();
private readonly object previousTaskLock = new object();
private Task previousTask = Task.CompletedTask;
private readonly Lazy<SingleThreadTaskScheduler> singleThreadScheduler = new();
private readonly Lazy<SingleThreadTaskScheduler> singleThreadScheduler = new Lazy<SingleThreadTaskScheduler>();
/// <summary>
@ -70,7 +70,7 @@ namespace Tapeti.Tasks
public override int MaximumConcurrencyLevel => 1;
private readonly Queue<Task> scheduledTasks = new();
private readonly Queue<Task> scheduledTasks = new Queue<Task>();
private bool disposed;