Skip to content

Commit 87d87e6

Browse files
committed
add sample/doc for blazor
1 parent 058647a commit 87d87e6

39 files changed

+2060
-0
lines changed

docs/images/blazorchat.gif

436 KB
Loading
2.44 KB
Loading
34.9 KB
Loading
7.83 KB
Loading

samples/BlazorChat/App.razor

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
<Router AppAssembly="@typeof(Program).Assembly">
3+
<Found Context="routeData">
4+
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
5+
</Found>
6+
<NotFound>
7+
<LayoutView Layout="@typeof(MainLayout)">
8+
<p>Sorry, there's nothing at this address.</p>
9+
</LayoutView>
10+
</NotFound>
11+
</Router>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="3.1.7" />
9+
<PackageReference Include="Microsoft.Azure.SignalR" Version="1.4.0" />
10+
</ItemGroup>
11+
12+
</Project>

samples/BlazorChat/BlazorChat.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.30404.54
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorChat", "BlazorChat.csproj", "{CB98C96E-8B22-41E2-84C7-89FE3507CAA5}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{CB98C96E-8B22-41E2-84C7-89FE3507CAA5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{CB98C96E-8B22-41E2-84C7-89FE3507CAA5}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{CB98C96E-8B22-41E2-84C7-89FE3507CAA5}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{CB98C96E-8B22-41E2-84C7-89FE3507CAA5}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {20B707F6-886D-4DC7-8D78-0F691346FA8E}
24+
EndGlobalSection
25+
EndGlobal

samples/BlazorChat/ChatHub.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
4+
using Microsoft.AspNetCore.SignalR;
5+
6+
namespace BlazorChat
7+
{
8+
public class ChatHub : Hub
9+
{
10+
public const string HubUrl = "/chat";
11+
12+
public async Task Broadcast(string username, string message)
13+
{
14+
await Clients.All.SendAsync("Broadcast", username, message);
15+
}
16+
17+
public override Task OnConnectedAsync()
18+
{
19+
Console.WriteLine($"{Context.ConnectionId} connected");
20+
return base.OnConnectedAsync();
21+
}
22+
23+
public override async Task OnDisconnectedAsync(Exception e)
24+
{
25+
Console.WriteLine($"Disconnected {e?.Message} {Context.ConnectionId}");
26+
await base.OnDisconnectedAsync(e);
27+
}
28+
}
29+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
3+
namespace BlazorChat.Data
4+
{
5+
public class WeatherForecast
6+
{
7+
public DateTime Date { get; set; }
8+
9+
public int TemperatureC { get; set; }
10+
11+
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
12+
13+
public string Summary { get; set; }
14+
}
15+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Linq;
3+
using System.Threading.Tasks;
4+
5+
namespace BlazorChat.Data
6+
{
7+
public class WeatherForecastService
8+
{
9+
private static readonly string[] Summaries = new[]
10+
{
11+
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
12+
};
13+
14+
public Task<WeatherForecast[]> GetForecastAsync(DateTime startDate)
15+
{
16+
var rng = new Random();
17+
return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast
18+
{
19+
Date = startDate.AddDays(index),
20+
TemperatureC = rng.Next(-20, 55),
21+
Summary = Summaries[rng.Next(Summaries.Length)]
22+
}).ToArray());
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)