Skip to content

Commit 8b985c8

Browse files
authored
Session 0206 (#69)
* WIP * Added timer feature * Added content after conclusion of the live stream
1 parent 4c18753 commit 8b985c8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+41112
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
// Use IntelliSense to find out which attributes exist for C# debugging
3+
// Use hover for the description of the existing attributes
4+
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": ".NET Core Launch (web)",
9+
"type": "coreclr",
10+
"request": "launch",
11+
"preLaunchTask": "build",
12+
// If you have changed target frameworks, make sure to update the program path.
13+
"program": "${workspaceFolder}/src/Session0206/bin/Debug/net5.0/Session0206.dll",
14+
"args": [],
15+
"cwd": "${workspaceFolder}/src/Session0206",
16+
"stopAtEntry": false,
17+
// Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
18+
"serverReadyAction": {
19+
"action": "openExternally",
20+
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
21+
},
22+
"env": {
23+
"ASPNETCORE_ENVIRONMENT": "Development"
24+
},
25+
"sourceFileMap": {
26+
"/Views": "${workspaceFolder}/Views"
27+
}
28+
},
29+
{
30+
"name": ".NET Core Attach",
31+
"type": "coreclr",
32+
"request": "attach",
33+
"processId": "${command:pickProcess}"
34+
}
35+
]
36+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"label": "build",
6+
"command": "dotnet",
7+
"type": "process",
8+
"args": [
9+
"build",
10+
"${workspaceFolder}/src/Session0206/Session0206.csproj",
11+
"/property:GenerateFullPaths=true",
12+
"/consoleloggerparameters:NoSummary"
13+
],
14+
"problemMatcher": "$msCompile"
15+
},
16+
{
17+
"label": "publish",
18+
"command": "dotnet",
19+
"type": "process",
20+
"args": [
21+
"publish",
22+
"${workspaceFolder}/src/Session0206/Session0206.csproj",
23+
"/property:GenerateFullPaths=true",
24+
"/consoleloggerparameters:NoSummary"
25+
],
26+
"problemMatcher": "$msCompile"
27+
},
28+
{
29+
"label": "watch",
30+
"command": "dotnet",
31+
"type": "process",
32+
"args": [
33+
"watch",
34+
"run",
35+
"${workspaceFolder}/src/Session0206/Session0206.csproj",
36+
"/property:GenerateFullPaths=true",
37+
"/consoleloggerparameters:NoSummary"
38+
],
39+
"problemMatcher": "$msCompile"
40+
}
41+
]
42+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Session 0206 - Build for the Live Web with ASP.NET Core SignalR
2+
3+
Emote demo: https://fritzsignalr.azurewebsites.net/Emote
4+
5+
What is SignalR: https://docs.microsoft.com/en-us/aspnet/signalr/overview/getting-started/introduction-to-signalr
6+
7+
Ovserview: https://docs.microsoft.com/en-us/aspnet/core/signalr/introduction?view=aspnetcore-5.0
8+
9+
JavaScript client
10+
npm install @microsoft/signalr
11+
12+
13+
Add WithAutomaticReconnect([1000,2000,3000])
14+
15+
16+
#error {
17+
border: 1px solid red;
18+
padding: 10px;
19+
margin: 10px;
20+
color: red;
21+
font-weight: bold;
22+
display: none;
23+
}
24+
25+
<div id="error"></div>
26+
27+
28+
connection.onreconnecting(e => {
29+
console.log("Reconnecting...");
30+
document.getElementById("error").innerText = "Connection lost... Attempting to reconnect";
31+
document.getElementById("error").style.display = "block";
32+
});
33+
34+
connection.onreconnected(e => {
35+
document.getElementById("error").innerText = "";
36+
document.getElementById("error").style.display = "none";
37+
});
38+
39+
connection.onclose(e => {
40+
document.getElementById("error").innerText = "Connection lost... Refresh to attempt reconnection";
41+
document.getElementById("error").style.display("block");
42+
});
43+
44+
45+
Scaleout: Azure SignalR Service or Redis Backplane
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System;
2+
using System.Threading;
3+
using System.Threading.Tasks;
4+
using Microsoft.AspNetCore.SignalR;
5+
6+
namespace Session0206.Hubs
7+
{
8+
9+
public class EmoteHub : Hub
10+
{
11+
12+
private static int _Count = 0;
13+
private static long _EmoteClicks = 0;
14+
15+
public override async Task OnConnectedAsync()
16+
{
17+
18+
var group = Context.GetHttpContext().Request.Query["group"].ToString();
19+
Console.WriteLine($"Connecting group {group}");
20+
if (!string.IsNullOrEmpty(group)) Groups.AddToGroupAsync(Context.ConnectionId, group);
21+
22+
Interlocked.Increment(ref _Count);
23+
await Clients.All.SendAsync("Count", _Count);
24+
base.OnConnectedAsync();
25+
}
26+
27+
public override async Task OnDisconnectedAsync(Exception exception)
28+
{
29+
Interlocked.Decrement(ref _Count);
30+
await Clients.All.SendAsync("Count", _Count);
31+
}
32+
33+
34+
35+
public async Task SendEmote(int emoteId)
36+
{
37+
38+
Interlocked.Increment(ref _EmoteClicks);
39+
await Clients.Group("obs").SendAsync("FlyEmote", emoteId);
40+
await Clients.All.SendAsync("clicks", _EmoteClicks);
41+
42+
}
43+
44+
45+
}
46+
47+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using Microsoft.AspNetCore.SignalR;
4+
5+
namespace Session0206.Hubs
6+
{
7+
8+
public class ShapeHub : Hub
9+
{
10+
11+
public async Task ServerMoveShape(int x, int y)
12+
{
13+
14+
await Clients.Others.SendAsync("ClientMoveShape", x, y);
15+
16+
}
17+
18+
private static int _Count;
19+
20+
public override async Task OnConnectedAsync()
21+
{
22+
_Count++;
23+
await Clients.All.SendAsync("Count", _Count);
24+
}
25+
26+
public override async Task OnDisconnectedAsync(Exception exception)
27+
{
28+
_Count--;
29+
await Clients.All.SendAsync("Count", _Count);
30+
}
31+
32+
33+
34+
}
35+
36+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
@page
2+
3+
<h1>Interactive Emotes Demo</h1>
4+
5+
<h3>Click a button to send that emote to Fritz's screen LIVE!</h3>
6+
<button data-id="1"><img src="/img/1.png" /></button>
7+
<button data-id="2"><img src="/img/2.png" /></button>
8+
<button data-id="3"><img src="/img/3.png" /></button>
9+
<br/>
10+
<button data-id="4"><img src="/img/4.png" /></button>
11+
<button data-id="5"><img src="/img/5.png" /></button>
12+
<button data-id="6"><img src="/img/6.png" /></button>
13+
<br/>
14+
<button data-id="7"><img src="/img/7.png" /></button>
15+
<button data-id="8"><img src="/img/8.png" /></button>
16+
<button data-id="9"><img src="/img/9.png" /></button>
17+
18+
<h2>Some stats</h2>
19+
<dl>
20+
<dt>Connections:</dt>
21+
<dd id="count"></dd>
22+
<dt>Emote Clicks:</dt>
23+
<dd id="clicks"></dd>
24+
</dl>
25+
26+
27+
@section Scripts {
28+
29+
<script type="text/javascript">
30+
31+
(function () {
32+
33+
const connection = new signalR.HubConnectionBuilder()
34+
.withUrl("/hub/emote")
35+
.configureLogging(signalR.LogLevel.Information)
36+
.build();
37+
38+
const count = document.getElementById("count");
39+
const clicks = document.getElementById("clicks");
40+
41+
const theButtons = document.querySelectorAll("button");
42+
theButtons.forEach((b) => {
43+
b.onclick = function() {
44+
connection.invoke("SendEmote", parseInt(b.getAttribute("data-id")));
45+
}
46+
});
47+
48+
connection.on("count", c => {
49+
count.textContent = c;
50+
})
51+
52+
connection.on("clicks", c => {
53+
clicks.textContent = c;
54+
})
55+
56+
57+
58+
connection.start();
59+
60+
})();
61+
62+
63+
</script>
64+
65+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
@page
2+
@model ErrorModel
3+
@{
4+
ViewData["Title"] = "Error";
5+
}
6+
7+
<h1 class="text-danger">Error.</h1>
8+
<h2 class="text-danger">An error occurred while processing your request.</h2>
9+
10+
@if (Model.ShowRequestId)
11+
{
12+
<p>
13+
<strong>Request ID:</strong> <code>@Model.RequestId</code>
14+
</p>
15+
}
16+
17+
<h3>Development Mode</h3>
18+
<p>
19+
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
20+
</p>
21+
<p>
22+
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
23+
It can result in displaying sensitive information from exceptions to end users.
24+
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
25+
and restarting the app.
26+
</p>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
using Microsoft.AspNetCore.Mvc;
7+
using Microsoft.AspNetCore.Mvc.RazorPages;
8+
using Microsoft.Extensions.Logging;
9+
10+
namespace Session0206.Pages
11+
{
12+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
13+
[IgnoreAntiforgeryToken]
14+
public class ErrorModel : PageModel
15+
{
16+
public string RequestId { get; set; }
17+
18+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
19+
20+
private readonly ILogger<ErrorModel> _logger;
21+
22+
public ErrorModel(ILogger<ErrorModel> logger)
23+
{
24+
_logger = logger;
25+
}
26+
27+
public void OnGet()
28+
{
29+
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
30+
}
31+
}
32+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
@page
2+
@model IndexModel
3+
@{
4+
ViewData["Title"] = "Home page";
5+
}
6+
7+
<div class="text-center">
8+
<h1 class="display-4">Welcome</h1>
9+
10+
<ul>
11+
<li><a href="/MoveShape">Move Shape Demo</a></li>
12+
<li><a href="/Emote">Emote Demo</a></li>
13+
</ul>
14+
15+
</div>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Mvc;
6+
using Microsoft.AspNetCore.Mvc.RazorPages;
7+
using Microsoft.Extensions.Logging;
8+
9+
namespace Session0206.Pages
10+
{
11+
public class IndexModel : PageModel
12+
{
13+
private readonly ILogger<IndexModel> _logger;
14+
15+
public IndexModel(ILogger<IndexModel> logger)
16+
{
17+
_logger = logger;
18+
}
19+
20+
public void OnGet()
21+
{
22+
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)