Skip to content

Commit

Permalink
Fix preview7 break changes (#591)
Browse files Browse the repository at this point in the history
  • Loading branch information
JialinXin authored Jul 9, 2019
1 parent bf20f07 commit 6be0860
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/build-source.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ Building Azure SignalR Service SDK requires:
PS> ./eng/scripts/InstallVisualStudio.ps1
```
* Git. <https://git-scm.org>
* AspNetCore 3.0 SDK (Version >= 3.0.100-preview7-012802). Install from AspNetCore code repo before release <https://github.com/dotnet/core-sdk#installers-and-binaries>.
* AspNetCore 3.0 Preview Runtime (Version >= 3.0.0-preview3-27503-5) <https://dotnet.microsoft.com/download/dotnet-core/3.0>
* AspNetCore 3.0 SDK (Version >= 3.0.100-preview6-012264). Install from AspNetCore code repo before release <https://github.com/dotnet/core-sdk#installers-and-binaries>.

## Clone the source code

Expand Down
6 changes: 6 additions & 0 deletions run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ function Get-KoreBuild {
Add-Type -AssemblyName System.IO.Compression.FileSystem
[System.IO.Compression.ZipFile]::ExtractToDirectory($tmpfile, $korebuildPath)
}

# Hack to use preview7
Write-Host "!!! Hack to use .NET Core SDK 3.0.100-preview7-012802"
$sdkversion = Get-ChildItem -Path $korebuildPath -Include sdk.version -Recurse
$sdkpath = Join-Path $sdkversion.DirectoryName $sdkversion.Name
Set-Content -Path $sdkpath -Value "3.0.100-preview7-012802"
}
catch {
Remove-Item -Recurse -Force $korebuildPath -ErrorAction Ignore
Expand Down
4 changes: 4 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ get_korebuild() {
fi
rm "$tmpfile" || true
fi

echo "!!! Hack to use .NET Core SDK 3.0.100-preview7-012802"
local filePath=`find $korebuild_path -name sdk.version`
echo "3.0.100-preview7-012802" > $filePath

source "$korebuild_path/KoreBuild.sh"
} || {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,19 @@ internal class ServiceHubConnectionContext : HubConnectionContext
public const string ItemsUnavailableError = nameof(Items) + UnavailableErrorTemplate;
public const string ProtocolUnavailableError = nameof(Protocol) + UnavailableErrorTemplate;

#if NETCOREAPP3_0
public ServiceHubConnectionContext(HttpContext context)
: base(new DummyConnectionContext(context),
new HubConnectionContextOptions() { KeepAliveInterval = TimeSpan.MaxValue },
NullLoggerFactory.Instance)
{
}
#else
public ServiceHubConnectionContext(HttpContext context)
: base(new DummyConnectionContext(context), TimeSpan.MaxValue, NullLoggerFactory.Instance)
{
}
#endif

public override CancellationToken ConnectionAborted => throw new InvalidOperationException(ConnectionAbortedUnavailableError);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Runtime.Versioning;
using System.Threading;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Builder.Internal;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// 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.

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.SignalR.Protocol;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;

namespace Microsoft.AspNetCore.SignalR.Internal
{
// copied from https://github.com/aspnet/AspNetCore/blob/release/3.0-preview7/src/SignalR/server/Core/src/Internal/DefaultHubProtocolResolver.cs
internal class DefaultHubProtocolResolver : IHubProtocolResolver
{
private readonly ILogger<DefaultHubProtocolResolver> _logger;
private readonly List<IHubProtocol> _hubProtocols;
private readonly Dictionary<string, IHubProtocol> _availableProtocols;

public IReadOnlyList<IHubProtocol> AllProtocols => _hubProtocols;

public DefaultHubProtocolResolver(IEnumerable<IHubProtocol> availableProtocols, ILogger<DefaultHubProtocolResolver> logger)
{
_logger = logger ?? NullLogger<DefaultHubProtocolResolver>.Instance;
_availableProtocols = new Dictionary<string, IHubProtocol>(StringComparer.OrdinalIgnoreCase);

// We might get duplicates in _hubProtocols, but we're going to check it and overwrite in just a sec.
_hubProtocols = availableProtocols.ToList();
foreach (var protocol in _hubProtocols)
{
Log.RegisteredSignalRProtocol(_logger, protocol.Name, protocol.GetType());
_availableProtocols[protocol.Name] = protocol;
}
}

public virtual IHubProtocol GetProtocol(string protocolName, IReadOnlyList<string> supportedProtocols)
{
protocolName = protocolName ?? throw new ArgumentNullException(nameof(protocolName));

if (_availableProtocols.TryGetValue(protocolName, out var protocol) && (supportedProtocols == null || supportedProtocols.Contains(protocolName, StringComparer.OrdinalIgnoreCase)))
{
Log.FoundImplementationForProtocol(_logger, protocolName);
return protocol;
}

// null result indicates protocol is not supported
// result will be validated by the caller
return null;
}

private static class Log
{
// Category: DefaultHubProtocolResolver
private static readonly Action<ILogger, string, Type, Exception> _registeredSignalRProtocol =
LoggerMessage.Define<string, Type>(LogLevel.Debug, new EventId(1, "RegisteredSignalRProtocol"), "Registered SignalR Protocol: {ProtocolName}, implemented by {ImplementationType}.");

private static readonly Action<ILogger, string, Exception> _foundImplementationForProtocol =
LoggerMessage.Define<string>(LogLevel.Debug, new EventId(2, "FoundImplementationForProtocol"), "Found protocol implementation for requested protocol: {ProtocolName}.");

public static void RegisteredSignalRProtocol(ILogger logger, string protocolName, Type implementationType)
{
_registeredSignalRProtocol(logger, protocolName, implementationType, null);
}

public static void FoundImplementationForProtocol(ILogger logger, string protocolName)
{
_foundImplementationForProtocol(logger, protocolName, null);
}
}
}
}

0 comments on commit 6be0860

Please sign in to comment.