From 5a77c8be25f28811ff1b3dbbc5a85035b4b4b0bc Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Sun, 15 Apr 2018 00:23:26 +1200 Subject: [PATCH] API review Microsoft.AspNetCore.SignalR.Internal (#2022) --- .../HubConnectionContextBenchmark.cs | 2 +- .../{ => Protocol}/CancelInvocationMessage.cs | 0 .../{ => Protocol}/CloseMessage.cs | 0 .../{ => Protocol}/CompletionMessage.cs | 0 .../{ => Protocol}/HandshakeProtocol.cs | 0 .../{ => Protocol}/HandshakeRequestMessage.cs | 0 .../{ => Protocol}/HandshakeResponseMessage.cs | 0 .../{ => Protocol}/HubInvocationMessage.cs | 0 .../{ => Protocol}/HubMessage.cs | 0 .../{ => Protocol}/HubMethodInvocationMessage.cs | 0 .../{ => Protocol}/HubProtocolConstants.cs | 0 .../{ => Protocol}/HubProtocolExtensions.cs | 0 .../{ => Protocol}/IHubProtocol.cs | 0 .../{ => Protocol}/PingMessage.cs | 0 .../{ => Protocol}/StreamItemMessage.cs | 1 - .../HubConnectionContext.cs | 2 +- .../HubConnectionHandler.cs | 5 ++++- .../{Internal => }/IHubProtocolResolver.cs | 4 ++-- .../Internal/DefaultHubProtocolResolver.cs | 2 +- 19 files changed, 9 insertions(+), 7 deletions(-) rename src/Microsoft.AspNetCore.SignalR.Common/{ => Protocol}/CancelInvocationMessage.cs (100%) rename src/Microsoft.AspNetCore.SignalR.Common/{ => Protocol}/CloseMessage.cs (100%) rename src/Microsoft.AspNetCore.SignalR.Common/{ => Protocol}/CompletionMessage.cs (100%) rename src/Microsoft.AspNetCore.SignalR.Common/{ => Protocol}/HandshakeProtocol.cs (100%) rename src/Microsoft.AspNetCore.SignalR.Common/{ => Protocol}/HandshakeRequestMessage.cs (100%) rename src/Microsoft.AspNetCore.SignalR.Common/{ => Protocol}/HandshakeResponseMessage.cs (100%) rename src/Microsoft.AspNetCore.SignalR.Common/{ => Protocol}/HubInvocationMessage.cs (100%) rename src/Microsoft.AspNetCore.SignalR.Common/{ => Protocol}/HubMessage.cs (100%) rename src/Microsoft.AspNetCore.SignalR.Common/{ => Protocol}/HubMethodInvocationMessage.cs (100%) rename src/Microsoft.AspNetCore.SignalR.Common/{ => Protocol}/HubProtocolConstants.cs (100%) rename src/Microsoft.AspNetCore.SignalR.Common/{ => Protocol}/HubProtocolExtensions.cs (100%) rename src/Microsoft.AspNetCore.SignalR.Common/{ => Protocol}/IHubProtocol.cs (100%) rename src/Microsoft.AspNetCore.SignalR.Common/{ => Protocol}/PingMessage.cs (100%) rename src/Microsoft.AspNetCore.SignalR.Common/{ => Protocol}/StreamItemMessage.cs (99%) rename src/Microsoft.AspNetCore.SignalR.Core/{Internal => }/IHubProtocolResolver.cs (72%) diff --git a/benchmarks/Microsoft.AspNetCore.SignalR.Microbenchmarks/HubConnectionContextBenchmark.cs b/benchmarks/Microsoft.AspNetCore.SignalR.Microbenchmarks/HubConnectionContextBenchmark.cs index 6431052e45..0f13aba113 100644 --- a/benchmarks/Microsoft.AspNetCore.SignalR.Microbenchmarks/HubConnectionContextBenchmark.cs +++ b/benchmarks/Microsoft.AspNetCore.SignalR.Microbenchmarks/HubConnectionContextBenchmark.cs @@ -92,7 +92,7 @@ namespace Microsoft.AspNetCore.SignalR.Microbenchmarks _instance = instance; } - public IHubProtocol GetProtocol(string protocolName, IList supportedProtocols) + public IHubProtocol GetProtocol(string protocolName, IReadOnlyList supportedProtocols) { return _instance; } diff --git a/src/Microsoft.AspNetCore.SignalR.Common/CancelInvocationMessage.cs b/src/Microsoft.AspNetCore.SignalR.Common/Protocol/CancelInvocationMessage.cs similarity index 100% rename from src/Microsoft.AspNetCore.SignalR.Common/CancelInvocationMessage.cs rename to src/Microsoft.AspNetCore.SignalR.Common/Protocol/CancelInvocationMessage.cs diff --git a/src/Microsoft.AspNetCore.SignalR.Common/CloseMessage.cs b/src/Microsoft.AspNetCore.SignalR.Common/Protocol/CloseMessage.cs similarity index 100% rename from src/Microsoft.AspNetCore.SignalR.Common/CloseMessage.cs rename to src/Microsoft.AspNetCore.SignalR.Common/Protocol/CloseMessage.cs diff --git a/src/Microsoft.AspNetCore.SignalR.Common/CompletionMessage.cs b/src/Microsoft.AspNetCore.SignalR.Common/Protocol/CompletionMessage.cs similarity index 100% rename from src/Microsoft.AspNetCore.SignalR.Common/CompletionMessage.cs rename to src/Microsoft.AspNetCore.SignalR.Common/Protocol/CompletionMessage.cs diff --git a/src/Microsoft.AspNetCore.SignalR.Common/HandshakeProtocol.cs b/src/Microsoft.AspNetCore.SignalR.Common/Protocol/HandshakeProtocol.cs similarity index 100% rename from src/Microsoft.AspNetCore.SignalR.Common/HandshakeProtocol.cs rename to src/Microsoft.AspNetCore.SignalR.Common/Protocol/HandshakeProtocol.cs diff --git a/src/Microsoft.AspNetCore.SignalR.Common/HandshakeRequestMessage.cs b/src/Microsoft.AspNetCore.SignalR.Common/Protocol/HandshakeRequestMessage.cs similarity index 100% rename from src/Microsoft.AspNetCore.SignalR.Common/HandshakeRequestMessage.cs rename to src/Microsoft.AspNetCore.SignalR.Common/Protocol/HandshakeRequestMessage.cs diff --git a/src/Microsoft.AspNetCore.SignalR.Common/HandshakeResponseMessage.cs b/src/Microsoft.AspNetCore.SignalR.Common/Protocol/HandshakeResponseMessage.cs similarity index 100% rename from src/Microsoft.AspNetCore.SignalR.Common/HandshakeResponseMessage.cs rename to src/Microsoft.AspNetCore.SignalR.Common/Protocol/HandshakeResponseMessage.cs diff --git a/src/Microsoft.AspNetCore.SignalR.Common/HubInvocationMessage.cs b/src/Microsoft.AspNetCore.SignalR.Common/Protocol/HubInvocationMessage.cs similarity index 100% rename from src/Microsoft.AspNetCore.SignalR.Common/HubInvocationMessage.cs rename to src/Microsoft.AspNetCore.SignalR.Common/Protocol/HubInvocationMessage.cs diff --git a/src/Microsoft.AspNetCore.SignalR.Common/HubMessage.cs b/src/Microsoft.AspNetCore.SignalR.Common/Protocol/HubMessage.cs similarity index 100% rename from src/Microsoft.AspNetCore.SignalR.Common/HubMessage.cs rename to src/Microsoft.AspNetCore.SignalR.Common/Protocol/HubMessage.cs diff --git a/src/Microsoft.AspNetCore.SignalR.Common/HubMethodInvocationMessage.cs b/src/Microsoft.AspNetCore.SignalR.Common/Protocol/HubMethodInvocationMessage.cs similarity index 100% rename from src/Microsoft.AspNetCore.SignalR.Common/HubMethodInvocationMessage.cs rename to src/Microsoft.AspNetCore.SignalR.Common/Protocol/HubMethodInvocationMessage.cs diff --git a/src/Microsoft.AspNetCore.SignalR.Common/HubProtocolConstants.cs b/src/Microsoft.AspNetCore.SignalR.Common/Protocol/HubProtocolConstants.cs similarity index 100% rename from src/Microsoft.AspNetCore.SignalR.Common/HubProtocolConstants.cs rename to src/Microsoft.AspNetCore.SignalR.Common/Protocol/HubProtocolConstants.cs diff --git a/src/Microsoft.AspNetCore.SignalR.Common/HubProtocolExtensions.cs b/src/Microsoft.AspNetCore.SignalR.Common/Protocol/HubProtocolExtensions.cs similarity index 100% rename from src/Microsoft.AspNetCore.SignalR.Common/HubProtocolExtensions.cs rename to src/Microsoft.AspNetCore.SignalR.Common/Protocol/HubProtocolExtensions.cs diff --git a/src/Microsoft.AspNetCore.SignalR.Common/IHubProtocol.cs b/src/Microsoft.AspNetCore.SignalR.Common/Protocol/IHubProtocol.cs similarity index 100% rename from src/Microsoft.AspNetCore.SignalR.Common/IHubProtocol.cs rename to src/Microsoft.AspNetCore.SignalR.Common/Protocol/IHubProtocol.cs diff --git a/src/Microsoft.AspNetCore.SignalR.Common/PingMessage.cs b/src/Microsoft.AspNetCore.SignalR.Common/Protocol/PingMessage.cs similarity index 100% rename from src/Microsoft.AspNetCore.SignalR.Common/PingMessage.cs rename to src/Microsoft.AspNetCore.SignalR.Common/Protocol/PingMessage.cs diff --git a/src/Microsoft.AspNetCore.SignalR.Common/StreamItemMessage.cs b/src/Microsoft.AspNetCore.SignalR.Common/Protocol/StreamItemMessage.cs similarity index 99% rename from src/Microsoft.AspNetCore.SignalR.Common/StreamItemMessage.cs rename to src/Microsoft.AspNetCore.SignalR.Common/Protocol/StreamItemMessage.cs index 350275c17a..cf885e837f 100644 --- a/src/Microsoft.AspNetCore.SignalR.Common/StreamItemMessage.cs +++ b/src/Microsoft.AspNetCore.SignalR.Common/Protocol/StreamItemMessage.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - namespace Microsoft.AspNetCore.SignalR.Protocol { public class StreamItemMessage : HubInvocationMessage diff --git a/src/Microsoft.AspNetCore.SignalR.Core/HubConnectionContext.cs b/src/Microsoft.AspNetCore.SignalR.Core/HubConnectionContext.cs index 55fed6489b..9724db8259 100644 --- a/src/Microsoft.AspNetCore.SignalR.Core/HubConnectionContext.cs +++ b/src/Microsoft.AspNetCore.SignalR.Core/HubConnectionContext.cs @@ -273,7 +273,7 @@ namespace Microsoft.AspNetCore.SignalR Task.Factory.StartNew(_abortedCallback, this); } - internal async Task HandshakeAsync(TimeSpan timeout, IList supportedProtocols, IHubProtocolResolver protocolResolver, + internal async Task HandshakeAsync(TimeSpan timeout, IReadOnlyList supportedProtocols, IHubProtocolResolver protocolResolver, IUserIdProvider userIdProvider, bool enableDetailedErrors) { try diff --git a/src/Microsoft.AspNetCore.SignalR.Core/HubConnectionHandler.cs b/src/Microsoft.AspNetCore.SignalR.Core/HubConnectionHandler.cs index 5e128d4e7e..e9bcbf64bb 100644 --- a/src/Microsoft.AspNetCore.SignalR.Core/HubConnectionHandler.cs +++ b/src/Microsoft.AspNetCore.SignalR.Core/HubConnectionHandler.cs @@ -2,6 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.SignalR.Core; @@ -61,7 +63,8 @@ namespace Microsoft.AspNetCore.SignalR var connectionContext = new HubConnectionContext(connection, keepAlive, _loggerFactory); - if (!await connectionContext.HandshakeAsync(handshakeTimeout, supportedProtocols, _protocolResolver, _userIdProvider, _enableDetailedErrors)) + var resolvedSupportedProtocols = (supportedProtocols as IReadOnlyList) ?? supportedProtocols.ToList(); + if (!await connectionContext.HandshakeAsync(handshakeTimeout, resolvedSupportedProtocols, _protocolResolver, _userIdProvider, _enableDetailedErrors)) { return; } diff --git a/src/Microsoft.AspNetCore.SignalR.Core/Internal/IHubProtocolResolver.cs b/src/Microsoft.AspNetCore.SignalR.Core/IHubProtocolResolver.cs similarity index 72% rename from src/Microsoft.AspNetCore.SignalR.Core/Internal/IHubProtocolResolver.cs rename to src/Microsoft.AspNetCore.SignalR.Core/IHubProtocolResolver.cs index 861acbe5d8..5444720d4f 100644 --- a/src/Microsoft.AspNetCore.SignalR.Core/Internal/IHubProtocolResolver.cs +++ b/src/Microsoft.AspNetCore.SignalR.Core/IHubProtocolResolver.cs @@ -4,11 +4,11 @@ using System.Collections.Generic; using Microsoft.AspNetCore.SignalR.Protocol; -namespace Microsoft.AspNetCore.SignalR.Internal +namespace Microsoft.AspNetCore.SignalR { public interface IHubProtocolResolver { IReadOnlyList AllProtocols { get; } - IHubProtocol GetProtocol(string protocolName, IList supportedProtocols); + IHubProtocol GetProtocol(string protocolName, IReadOnlyList supportedProtocols); } } diff --git a/src/Microsoft.AspNetCore.SignalR.Core/Internal/DefaultHubProtocolResolver.cs b/src/Microsoft.AspNetCore.SignalR.Core/Internal/DefaultHubProtocolResolver.cs index c44b303878..614d3c65df 100644 --- a/src/Microsoft.AspNetCore.SignalR.Core/Internal/DefaultHubProtocolResolver.cs +++ b/src/Microsoft.AspNetCore.SignalR.Core/Internal/DefaultHubProtocolResolver.cs @@ -36,7 +36,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal } } - public IHubProtocol GetProtocol(string protocolName, IList supportedProtocols) + public virtual IHubProtocol GetProtocol(string protocolName, IReadOnlyList supportedProtocols) { protocolName = protocolName ?? throw new ArgumentNullException(nameof(protocolName));