From d6138e2cfa220919d25eb385becf532977414928 Mon Sep 17 00:00:00 2001 From: Mark van Renswoude Date: Sun, 13 Feb 2022 10:36:04 +0100 Subject: [PATCH] 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 --- Tapeti/Connection/TapetiChannel.cs | 2 +- Tapeti/Connection/TapetiClient.cs | 41 +++++++++---------- Tapeti/Connection/TapetiConsumer.cs | 3 +- Tapeti/Connection/TapetiSubscriber.cs | 10 ++--- Tapeti/Default/ControllerBindingContext.cs | 2 +- Tapeti/Default/JsonMessageSerializer.cs | 6 +-- Tapeti/Default/MessageContext.cs | 4 +- Tapeti/Default/MessageProperties.cs | 2 +- .../Default/NamespaceMatchExchangeStrategy.cs | 2 +- Tapeti/Default/TypeNameRoutingKeyStrategy.cs | 4 +- Tapeti/Helpers/ConnectionstringParser.cs | 2 +- Tapeti/Tapeti.csproj | 2 +- Tapeti/TapetiConfig.cs | 14 +++---- Tapeti/TapetiConfigControllers.cs | 2 +- Tapeti/Tasks/SingleThreadTaskQueue.cs | 6 +-- 15 files changed, 50 insertions(+), 52 deletions(-) diff --git a/Tapeti/Connection/TapetiChannel.cs b/Tapeti/Connection/TapetiChannel.cs index 0efe5c3..902b5cf 100644 --- a/Tapeti/Connection/TapetiChannel.cs +++ b/Tapeti/Connection/TapetiChannel.cs @@ -20,7 +20,7 @@ namespace Tapeti.Connection internal class TapetiChannel { private readonly Func modelFactory; - private readonly object taskQueueLock = new(); + private readonly object taskQueueLock = new object(); private SingleThreadTaskQueue taskQueue; private readonly ModelProvider modelProvider; diff --git a/Tapeti/Connection/TapetiClient.cs b/Tapeti/Connection/TapetiClient.cs index c465944..9ff960f 100644 --- a/Tapeti/Connection/TapetiClient.cs +++ b/Tapeti/Connection/TapetiClient.cs @@ -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 deletedQueues = new(); + private readonly HashSet deletedQueues = new HashSet(); // 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 confirmMessages = new(); - private readonly Dictionary returnRoutingKeys = new(); + private readonly object confirmLock = new object(); + private readonly Dictionary confirmMessages = new Dictionary(); + private readonly Dictionary returnRoutingKeys = new Dictionary(); 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 TransientStatusCodes = new() + private static readonly List TransientStatusCodes = new List() { 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 declaredExchanges = new(); + private readonly HashSet declaredExchanges = new HashSet(); 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) { diff --git a/Tapeti/Connection/TapetiConsumer.cs b/Tapeti/Connection/TapetiConsumer.cs index fba63dd..a010fcf 100644 --- a/Tapeti/Connection/TapetiConsumer.cs +++ b/Tapeti/Connection/TapetiConsumer.cs @@ -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) }; } diff --git a/Tapeti/Connection/TapetiSubscriber.cs b/Tapeti/Connection/TapetiSubscriber.cs index a46d1c8..0c026ab 100644 --- a/Tapeti/Connection/TapetiSubscriber.cs +++ b/Tapeti/Connection/TapetiSubscriber.cs @@ -13,7 +13,7 @@ namespace Tapeti.Connection private readonly Func clientFactory; private readonly ITapetiConfig config; private bool consuming; - private readonly List consumerTags = new(); + private readonly List consumerTags = new List(); private CancellationTokenSource initializeCancellationTokenSource; @@ -167,7 +167,7 @@ namespace Tapeti.Connection public List MessageClasses; } - private readonly Dictionary> dynamicQueues = new(); + private readonly Dictionary> dynamicQueues = new Dictionary>(); protected CustomBindingTarget(Func clientFactory, IRoutingKeyStrategy routingKeyStrategy, IExchangeStrategy exchangeStrategy, CancellationToken cancellationToken) @@ -278,8 +278,8 @@ namespace Tapeti.Connection private class DeclareDurableQueuesBindingTarget : CustomBindingTarget { - private readonly Dictionary> durableQueues = new(); - private readonly HashSet obsoleteDurableQueues = new(); + private readonly Dictionary> durableQueues = new Dictionary>(); + private readonly HashSet obsoleteDurableQueues = new HashSet(); public DeclareDurableQueuesBindingTarget(Func 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 durableQueues = new(); + private readonly HashSet durableQueues = new HashSet(); public PassiveDurableQueuesBindingTarget(Func clientFactory, IRoutingKeyStrategy routingKeyStrategy, IExchangeStrategy exchangeStrategy, CancellationToken cancellationToken) : base(clientFactory, routingKeyStrategy, exchangeStrategy, cancellationToken) diff --git a/Tapeti/Default/ControllerBindingContext.cs b/Tapeti/Default/ControllerBindingContext.cs index 57ee673..9318c98 100644 --- a/Tapeti/Default/ControllerBindingContext.cs +++ b/Tapeti/Default/ControllerBindingContext.cs @@ -9,7 +9,7 @@ namespace Tapeti.Default internal class ControllerBindingContext : IControllerBindingContext { private BindingTargetMode? bindingTargetMode; - private readonly List middleware = new(); + private readonly List middleware = new List(); private readonly List parameters; private readonly ControllerBindingResult result; diff --git a/Tapeti/Default/JsonMessageSerializer.cs b/Tapeti/Default/JsonMessageSerializer.cs index bad6c47..61b5252 100644 --- a/Tapeti/Default/JsonMessageSerializer.cs +++ b/Tapeti/Default/JsonMessageSerializer.cs @@ -16,8 +16,8 @@ namespace Tapeti.Default private const string ClassTypeHeader = "classType"; - private readonly ConcurrentDictionary deserializedTypeNames = new(); - private readonly ConcurrentDictionary serializedTypeNames = new(); + private readonly ConcurrentDictionary deserializedTypeNames = new ConcurrentDictionary(); + private readonly ConcurrentDictionary serializedTypeNames = new ConcurrentDictionary(); private readonly JsonSerializerSettings serializerSettings; @@ -49,7 +49,7 @@ namespace Tapeti.Default /// 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); diff --git a/Tapeti/Default/MessageContext.cs b/Tapeti/Default/MessageContext.cs index 3b72e77..ca98640 100644 --- a/Tapeti/Default/MessageContext.cs +++ b/Tapeti/Default/MessageContext.cs @@ -8,7 +8,7 @@ namespace Tapeti.Default { internal class MessageContext : IMessageContext { - private readonly Dictionary payloads = new(); + private readonly Dictionary payloads = new Dictionary(); /// @@ -117,7 +117,7 @@ namespace Tapeti.Default // ReSharper disable once InconsistentNaming public class KeyValuePayload : IMessageContextPayload, IDisposable, IAsyncDisposable { - private readonly Dictionary items = new(); + private readonly Dictionary items = new Dictionary(); public KeyValuePayload(string key, object value) diff --git a/Tapeti/Default/MessageProperties.cs b/Tapeti/Default/MessageProperties.cs index 8227934..3184da9 100644 --- a/Tapeti/Default/MessageProperties.cs +++ b/Tapeti/Default/MessageProperties.cs @@ -10,7 +10,7 @@ namespace Tapeti.Default /// public class MessageProperties : IMessageProperties { - private readonly Dictionary headers = new(); + private readonly Dictionary headers = new Dictionary(); /// diff --git a/Tapeti/Default/NamespaceMatchExchangeStrategy.cs b/Tapeti/Default/NamespaceMatchExchangeStrategy.cs index 54d16d0..3c4465e 100644 --- a/Tapeti/Default/NamespaceMatchExchangeStrategy.cs +++ b/Tapeti/Default/NamespaceMatchExchangeStrategy.cs @@ -13,7 +13,7 @@ namespace Tapeti.Default /// public class NamespaceMatchExchangeStrategy : IExchangeStrategy { - private static readonly Regex NamespaceRegex = new("^(Messaging\\.)?(?[^\\.]+)", RegexOptions.Compiled | RegexOptions.Singleline); + private static readonly Regex NamespaceRegex = new Regex("^(Messaging\\.)?(?[^\\.]+)", RegexOptions.Compiled | RegexOptions.Singleline); /// diff --git a/Tapeti/Default/TypeNameRoutingKeyStrategy.cs b/Tapeti/Default/TypeNameRoutingKeyStrategy.cs index 35ee8d8..f31af08 100644 --- a/Tapeti/Default/TypeNameRoutingKeyStrategy.cs +++ b/Tapeti/Default/TypeNameRoutingKeyStrategy.cs @@ -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 RoutingKeyCache = new(); + private static readonly ConcurrentDictionary RoutingKeyCache = new ConcurrentDictionary(); /// diff --git a/Tapeti/Helpers/ConnectionstringParser.cs b/Tapeti/Helpers/ConnectionstringParser.cs index c872a79..906618a 100644 --- a/Tapeti/Helpers/ConnectionstringParser.cs +++ b/Tapeti/Helpers/ConnectionstringParser.cs @@ -10,7 +10,7 @@ namespace Tapeti.Helpers /// public class ConnectionStringParser { - private readonly TapetiConnectionParams result = new(); + private readonly TapetiConnectionParams result = new TapetiAppSettingsConnectionParams(); private readonly string connectionstring; private int pos = -1; diff --git a/Tapeti/Tapeti.csproj b/Tapeti/Tapeti.csproj index b58e8d9..8d9d274 100644 --- a/Tapeti/Tapeti.csproj +++ b/Tapeti/Tapeti.csproj @@ -11,7 +11,7 @@ Unlicense https://github.com/MvRens/Tapeti Tapeti.png - latest + 8 diff --git a/Tapeti/TapetiConfig.cs b/Tapeti/TapetiConfig.cs index 8d225e8..be4d4e1 100644 --- a/Tapeti/TapetiConfig.cs +++ b/Tapeti/TapetiConfig.cs @@ -18,7 +18,7 @@ namespace Tapeti public class TapetiConfig : ITapetiConfigBuilder, ITapetiConfigBuilderAccess { private Config config; - private readonly List bindingMiddleware = new(); + private readonly List bindingMiddleware = new List(); /// @@ -189,7 +189,7 @@ namespace Tapeti /// protected void RegisterDefaults() { - if (DependencyResolver is not IDependencyContainer container) + if (!(DependencyResolver is IDependencyContainer container)) return; if (ConsoleHelper.IsAvailable()) @@ -225,9 +225,9 @@ namespace Tapeti /// 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 messageMiddleware = new(); - private readonly List publishMiddleware = new(); + private readonly List messageMiddleware = new List(); + private readonly List publishMiddleware = new List(); public IReadOnlyList Message => messageMiddleware; diff --git a/Tapeti/TapetiConfigControllers.cs b/Tapeti/TapetiConfigControllers.cs index f4e6b32..7d11b38 100644 --- a/Tapeti/TapetiConfigControllers.cs +++ b/Tapeti/TapetiConfigControllers.cs @@ -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"); diff --git a/Tapeti/Tasks/SingleThreadTaskQueue.cs b/Tapeti/Tasks/SingleThreadTaskQueue.cs index c08a1d4..9272a1e 100644 --- a/Tapeti/Tasks/SingleThreadTaskQueue.cs +++ b/Tapeti/Tasks/SingleThreadTaskQueue.cs @@ -12,10 +12,10 @@ namespace Tapeti.Tasks /// public class SingleThreadTaskQueue : IDisposable { - private readonly object previousTaskLock = new(); + private readonly object previousTaskLock = new object(); private Task previousTask = Task.CompletedTask; - private readonly Lazy singleThreadScheduler = new(); + private readonly Lazy singleThreadScheduler = new Lazy(); /// @@ -70,7 +70,7 @@ namespace Tapeti.Tasks public override int MaximumConcurrencyLevel => 1; - private readonly Queue scheduledTasks = new(); + private readonly Queue scheduledTasks = new Queue(); private bool disposed;