Skip to content

Commit

Permalink
Fix build warnings and add net6 samples (#1676)
Browse files Browse the repository at this point in the history
* Fix build warning

* Update docs

* Fix build failure

* Fix test failure
  • Loading branch information
vicancy authored Sep 7, 2022
1 parent cc356c1 commit 1bfba7d
Show file tree
Hide file tree
Showing 56 changed files with 44,332 additions and 14 deletions.
7 changes: 7 additions & 0 deletions AzureSignalR.sln
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.SignalR.Ser
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.SignalR.Serverless.Protocols.Tests", "test\Microsoft.Azure.SignalR.Serverless.Protocols.Tests\Microsoft.Azure.SignalR.Serverless.Protocols.Tests.csproj", "{82C1FF3D-EC6C-4B21-B6A4-E69E8D75D0D0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChatSample.Net60", "samples\ChatSample\ChatSample.Net60\ChatSample.Net60.csproj", "{594EC59A-7305-4A36-8BE6-4A928FBFD71B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -184,6 +186,10 @@ Global
{82C1FF3D-EC6C-4B21-B6A4-E69E8D75D0D0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{82C1FF3D-EC6C-4B21-B6A4-E69E8D75D0D0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{82C1FF3D-EC6C-4B21-B6A4-E69E8D75D0D0}.Release|Any CPU.Build.0 = Release|Any CPU
{594EC59A-7305-4A36-8BE6-4A928FBFD71B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{594EC59A-7305-4A36-8BE6-4A928FBFD71B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{594EC59A-7305-4A36-8BE6-4A928FBFD71B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{594EC59A-7305-4A36-8BE6-4A928FBFD71B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -216,6 +222,7 @@ Global
{870A10E3-D17A-4239-9715-5610FFE1FC76} = {2429FBD8-1FCE-4C42-AA28-DF32F7249E77}
{52944A80-44A9-48D4-919D-11AAAD55193E} = {DA69F624-5398-4884-87E4-B816698CDE65}
{82C1FF3D-EC6C-4B21-B6A4-E69E8D75D0D0} = {2429FBD8-1FCE-4C42-AA28-DF32F7249E77}
{594EC59A-7305-4A36-8BE6-4A928FBFD71B} = {C965ED06-6A17-4329-B3C6-811830F4F4ED}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7945A4E4-ACDB-4F6E-95CA-6AC6E7C2CD59}
Expand Down
15 changes: 10 additions & 5 deletions docs/run-asp-net-core.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
- [2. Configure Connection String](#2-configure-connection-string)
- [3. Configure Service Options](#3-configure-service-options)
- [`ConnectionString`](#connectionstring)
- [`ConnectionCount`](#connectioncount)
- [`InitialHubServerConnectionCount`](#initialhubserverconnectioncount)
- [`ApplicationName`](#applicationname)
- [`ClaimsProvider`](#claimsprovider)
- [`AccessTokenLifetime`](#accesstokenlifetime)
Expand All @@ -23,7 +23,7 @@
Run below command to install SignalR Service SDK to your ASP.NET Core project.

```bash
dotnet add package Microsoft.Azure.SignalR --version 1.0.*
dotnet add package Microsoft.Azure.SignalR
```

In your `Startup` class, use SignalR Service SDK as the following code snippet.
Expand All @@ -37,7 +37,7 @@ public void ConfigureServices(IServiceCollection services)

public void Configure(IApplicationBuilder app)
{
app.UseAzureSignalR(routes =>
app.UseEndpoints(routes =>
{
routes.MapHub<YourHubClass>("/path_for_your_hub");
});
Expand Down Expand Up @@ -73,11 +73,16 @@ There are a few options you can customize when using Azure SignalR Service SDK.
- Default value is the `Azure:SignalR:ConnectionString` `connectionString` or `appSetting` in `web.config` file.
- It can be reconfigured, but please make sure the value is **NOT** hard coded.

### `ConnectionCount`
### `InitialHubServerConnectionCount`

- Default value is `5`.
- This option controls the initial count of connections per hub between application server and Azure SignalR Service. Usually keep it as the default value is enough. During runtime, the SDK might start new server connections for performance tuning or load balancing. When you have big number of clients, you can give it a larger number for better throughput. For example, if you have 100,000 clients in total, the connection count can be increased to `10` or `15`.

### `MaxHubServerConnectionCount`

- Default value is `null`.
- This option controls the max count of connections allowed per hub between application server and Azure SignalR Service. During runtime, the SDK might start new server connections for performance tuning or load balancing. By default a new server connection starts whenever needed. When the max allowed server connection count is configured, the SDK does not start new connections when server connection count reaches the limit.

### `ApplicationName`

- Default value is `null`.
Expand Down Expand Up @@ -150,7 +155,7 @@ You can configure above options like the following sample code.
services.AddSignalR()
.AddAzureSignalR(options =>
{
options.ConnectionCount = 10;
options.InitialHubServerConnectionCount = 10;
options.AccessTokenLifetime = TimeSpan.FromDays(1);
options.ClaimsProvider = context => context.User.Claims;

Expand Down
11 changes: 8 additions & 3 deletions docs/run-asp-net.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
- [2. Configure Connection String](#2-configure-connection-string)
- [3. Configure Service Options](#3-configure-service-options)
- [`ConnectionString`](#connectionstring)
- [`ConnectionCount`](#connectioncount)
- [`InitialHubServerConnectionCount`](#initialhubserverconnectioncount)
- [`ApplicationName`](#applicationname)
- [`ClaimProvider`](#claimprovider)
- [`AccessTokenLifetime`](#accesstokenlifetime)
Expand Down Expand Up @@ -55,11 +55,16 @@ There are a few [options](https://github.com/Azure/azure-signalr/blob/dev/src/Mi
- Default value is the `Azure:SignalR:ConnectionString` `connectionString` or `appSetting` in `web.config` file.
- It can be reconfigured, but please make sure the value is **NOT** hard coded.

### `ConnectionCount`
### `InitialHubServerConnectionCount`

- Default value is `5`.
- This option controls the initial count of connections per hub between application server and Azure SignalR Service. Usually keep it as the default value is enough. During runtime, the SDK might start new server connections for performance tuning or load balancing. When you have big number of clients, you can give it a larger number for better throughput. For example, if you have 100,000 clients in total, the connection count can be increased to `10` or `15`.

### `MaxHubServerConnectionCount`

- Default value is `null`.
- This option controls the max count of connections allowed per hub between application server and Azure SignalR Service. During runtime, the SDK might start new server connections for performance tuning or load balancing. By default a new server connection starts whenever needed. When the max allowed server connection count is configured, the SDK does not start new connections when server connection count reaches the limit.

### `ApplicationName`

- Default value is `null`.
Expand Down Expand Up @@ -104,7 +109,7 @@ You can configure above options like the following sample code.
```csharp
app.Map("/signalr",subApp => subApp.RunAzureSignalR(this.GetType().FullName, new HubConfiguration(), options =>
{
options.ConnectionCount = 1;
options.InitialHubServerConnectionCount = 1;
options.AccessTokenLifetime = TimeSpan.FromDays(1);
options.ClaimProvider = context => context.Authentication?.User.Claims;
}));
Expand Down
6 changes: 6 additions & 0 deletions samples/ChatSample/ChatSample.Net60/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.min.css
*.rtl.css
*.esm.js
*.js.map
*.bundle.js
*.map
13 changes: 13 additions & 0 deletions samples/ChatSample/ChatSample.Net60/ChatSample.Net60.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\Microsoft.Azure.SignalR\Microsoft.Azure.SignalR.csproj" />
</ItemGroup>

</Project>
15 changes: 15 additions & 0 deletions samples/ChatSample/ChatSample.Net60/Hubs/ChatHub.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.AspNetCore.SignalR;

namespace ChatSample.Net60.Hubs
{
public class ChatHub : Hub
{
public async Task SendMessage(string user, string message)
{
await Clients.All.SendAsync("ReceiveMessage", user, message);
}
}
}
26 changes: 26 additions & 0 deletions samples/ChatSample/ChatSample.Net60/Pages/Error.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
@page
@model ErrorModel
@{
ViewData["Title"] = "Error";
}

<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>

@if (Model.ShowRequestId)
{
<p>
<strong>Request ID:</strong> <code>@Model.RequestId</code>
</p>
}

<h3>Development Mode</h3>
<p>
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
</p>
<p>
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
It can result in displaying sensitive information from exceptions to end users.
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
and restarting the app.
</p>
28 changes: 28 additions & 0 deletions samples/ChatSample/ChatSample.Net60/Pages/Error.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Diagnostics;

using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace ChatSample.Net60.Pages
{
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
[IgnoreAntiforgeryToken]
public class ErrorModel : PageModel
{
public string? RequestId { get; set; }

public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);

private readonly ILogger<ErrorModel> _logger;

public ErrorModel(ILogger<ErrorModel> logger)
{
_logger = logger;
}

public void OnGet()
{
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
}
}
}
30 changes: 30 additions & 0 deletions samples/ChatSample/ChatSample.Net60/Pages/Index.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
@page
<div class="container">
<div class="row">&nbsp;</div>
<div class="row">
<div class="col-2">User</div>
<div class="col-4"><input type="text" id="userInput" /></div>
</div>
<div class="row">
<div class="col-2">Message</div>
<div class="col-4"><input type="text" id="messageInput" /></div>
</div>
<div class="row">&nbsp;</div>
<div class="row">
<div class="col-6">
<input type="button" id="sendButton" value="Send Message" />
</div>
</div>
</div>
<div class="row">
<div class="col-12">
<hr />
</div>
</div>
<div class="row">
<div class="col-6">
<ul id="messagesList"></ul>
</div>
</div>
<script src="~/js/signalr/dist/browser/signalr.js"></script>
<script src="~/js/chat.js"></script>
20 changes: 20 additions & 0 deletions samples/ChatSample/ChatSample.Net60/Pages/Index.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace ChatSample.Net60.Pages
{
public class IndexModel : PageModel
{
private readonly ILogger<IndexModel> _logger;

public IndexModel(ILogger<IndexModel> logger)
{
_logger = logger;
}

public void OnGet()
{

}
}
}
8 changes: 8 additions & 0 deletions samples/ChatSample/ChatSample.Net60/Pages/Privacy.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@page
@model PrivacyModel
@{
ViewData["Title"] = "Privacy Policy";
}
<h1>@ViewData["Title"]</h1>

<p>Use this page to detail your site's privacy policy.</p>
19 changes: 19 additions & 0 deletions samples/ChatSample/ChatSample.Net60/Pages/Privacy.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace ChatSample.Net60.Pages
{
public class PrivacyModel : PageModel
{
private readonly ILogger<PrivacyModel> _logger;

public PrivacyModel(ILogger<PrivacyModel> logger)
{
_logger = logger;
}

public void OnGet()
{
}
}
}
51 changes: 51 additions & 0 deletions samples/ChatSample/ChatSample.Net60/Pages/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - ChatSample.Net60</title>
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
<link rel="stylesheet" href="~/ChatSample.Net60.styles.css" asp-append-version="true" />
</head>
<body>
<header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
<div class="container">
<a class="navbar-brand" asp-area="" asp-page="/Index">ChatSample.Net60</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
<ul class="navbar-nav flex-grow-1">
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-page="/Index">Home</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-page="/Privacy">Privacy</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
<div class="container">
<main role="main" class="pb-3">
@RenderBody()
</main>
</div>

<footer class="border-top footer text-muted">
<div class="container">
&copy; 2022 - ChatSample.Net60 - <a asp-area="" asp-page="/Privacy">Privacy</a>
</div>
</footer>

<script src="~/lib/jquery/dist/jquery.min.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="~/js/site.js" asp-append-version="true"></script>

@await RenderSectionAsync("Scripts", required: false)
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification
for details on configuring this project to bundle and minify static web assets. */

a.navbar-brand {
white-space: normal;
text-align: center;
word-break: break-all;
}

a {
color: #0077cc;
}

.btn-primary {
color: #fff;
background-color: #1b6ec2;
border-color: #1861ac;
}

.nav-pills .nav-link.active, .nav-pills .show > .nav-link {
color: #fff;
background-color: #1b6ec2;
border-color: #1861ac;
}

.border-top {
border-top: 1px solid #e5e5e5;
}
.border-bottom {
border-bottom: 1px solid #e5e5e5;
}

.box-shadow {
box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05);
}

button.accept-policy {
font-size: 1rem;
line-height: inherit;
}

.footer {
position: absolute;
bottom: 0;
width: 100%;
white-space: nowrap;
line-height: 60px;
}
Loading

0 comments on commit 1bfba7d

Please sign in to comment.