Skip to content

Commit e27dd98

Browse files
authored
0306 errata (#76)
* First * Final demos for session * After session
1 parent f19b270 commit e27dd98

File tree

110 files changed

+4665
-0
lines changed

Some content is hidden

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

110 files changed

+4665
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Session 0306 - Errata
2+
3+
Let's cover a bunch of smaller topics that we skipped in earlier sessions
4+
5+
## Agenda
6+
7+
- Debugging Web Assembly
8+
- Form Components + Validation
9+
- State Management
10+
- Globalization + Localization
11+
- Web Assembly Pre-Rendering
12+
13+
## Debugging
14+
15+
https://docs.microsoft.com/aspnet/core/blazor/debug?view=aspnetcore-5.0&tabs=visual-studio
16+
17+
## Form Components
18+
19+
https://docs.microsoft.com/aspnet/core/blazor/forms-validation?view=aspnetcore-5.0
20+
21+
## State with Browser
22+
23+
https://docs.microsoft.com/aspnet/core/blazor/state-management?view=aspnetcore-5.0&pivots=webassembly#browser-storage-wasm
24+
25+
Blazored Localstorage:
26+
https://github.com/blazored/LocalStorage
27+
28+
## Globalization / Localization
29+
30+
https://docs.microsoft.com/aspnet/core/blazor/globalization-localization?view=aspnetcore-5.0
31+
32+
Localization: https://github.com/jsakamoto/Toolbelt.Blazor.I18nText
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.6.30114.105
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FormComponents", "FormComponents\FormComponents.csproj", "{FA7D165D-0A95-4ECE-8113-B7269706E9F1}"
7+
EndProject
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MyServerApp", "MyServerApp\MyServerApp.csproj", "{EE5F446D-3234-42AF-BCD5-C8FA5F867FF9}"
9+
EndProject
10+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HostedAssembly.Client", "HostedAssembly.Client\HostedAssembly.Client.csproj", "{3D0C0BF4-6AD5-43DC-87C0-30C3C0A19911}"
11+
EndProject
12+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HostedAssembly.Shared", "HostedAssembly.Shared\HostedAssembly.Shared.csproj", "{FD9C4368-5E20-4ECD-A010-2AC111BFCB5F}"
13+
EndProject
14+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HostedAssembly.Server", "HostedAssembly.Server\HostedAssembly.Server.csproj", "{3557A52A-96DD-4791-8D40-AE81D141B4D2}"
15+
EndProject
16+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "1-Forms", "1-Forms", "{ECF6AED3-BBB2-436D-A15F-3A37109DF26B}"
17+
EndProject
18+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "2-HostedAssembly", "2-HostedAssembly", "{CE194465-F09A-45CC-8D8A-5D17CCEC44C1}"
19+
EndProject
20+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "3-Server", "3-Server", "{0EAF3126-A656-48A1-9DA1-8AC2C1A8FD7D}"
21+
EndProject
22+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A33C2FB1-2A82-4411-9F1F-95E483B6A3F8}"
23+
ProjectSection(SolutionItems) = preProject
24+
..\README.md = ..\README.md
25+
EndProjectSection
26+
EndProject
27+
Global
28+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
29+
Debug|Any CPU = Debug|Any CPU
30+
Debug|x64 = Debug|x64
31+
Debug|x86 = Debug|x86
32+
Release|Any CPU = Release|Any CPU
33+
Release|x64 = Release|x64
34+
Release|x86 = Release|x86
35+
EndGlobalSection
36+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
37+
{FA7D165D-0A95-4ECE-8113-B7269706E9F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
38+
{FA7D165D-0A95-4ECE-8113-B7269706E9F1}.Debug|Any CPU.Build.0 = Debug|Any CPU
39+
{FA7D165D-0A95-4ECE-8113-B7269706E9F1}.Debug|x64.ActiveCfg = Debug|Any CPU
40+
{FA7D165D-0A95-4ECE-8113-B7269706E9F1}.Debug|x64.Build.0 = Debug|Any CPU
41+
{FA7D165D-0A95-4ECE-8113-B7269706E9F1}.Debug|x86.ActiveCfg = Debug|Any CPU
42+
{FA7D165D-0A95-4ECE-8113-B7269706E9F1}.Debug|x86.Build.0 = Debug|Any CPU
43+
{FA7D165D-0A95-4ECE-8113-B7269706E9F1}.Release|Any CPU.ActiveCfg = Release|Any CPU
44+
{FA7D165D-0A95-4ECE-8113-B7269706E9F1}.Release|Any CPU.Build.0 = Release|Any CPU
45+
{FA7D165D-0A95-4ECE-8113-B7269706E9F1}.Release|x64.ActiveCfg = Release|Any CPU
46+
{FA7D165D-0A95-4ECE-8113-B7269706E9F1}.Release|x64.Build.0 = Release|Any CPU
47+
{FA7D165D-0A95-4ECE-8113-B7269706E9F1}.Release|x86.ActiveCfg = Release|Any CPU
48+
{FA7D165D-0A95-4ECE-8113-B7269706E9F1}.Release|x86.Build.0 = Release|Any CPU
49+
{EE5F446D-3234-42AF-BCD5-C8FA5F867FF9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
50+
{EE5F446D-3234-42AF-BCD5-C8FA5F867FF9}.Debug|Any CPU.Build.0 = Debug|Any CPU
51+
{EE5F446D-3234-42AF-BCD5-C8FA5F867FF9}.Debug|x64.ActiveCfg = Debug|Any CPU
52+
{EE5F446D-3234-42AF-BCD5-C8FA5F867FF9}.Debug|x64.Build.0 = Debug|Any CPU
53+
{EE5F446D-3234-42AF-BCD5-C8FA5F867FF9}.Debug|x86.ActiveCfg = Debug|Any CPU
54+
{EE5F446D-3234-42AF-BCD5-C8FA5F867FF9}.Debug|x86.Build.0 = Debug|Any CPU
55+
{EE5F446D-3234-42AF-BCD5-C8FA5F867FF9}.Release|Any CPU.ActiveCfg = Release|Any CPU
56+
{EE5F446D-3234-42AF-BCD5-C8FA5F867FF9}.Release|Any CPU.Build.0 = Release|Any CPU
57+
{EE5F446D-3234-42AF-BCD5-C8FA5F867FF9}.Release|x64.ActiveCfg = Release|Any CPU
58+
{EE5F446D-3234-42AF-BCD5-C8FA5F867FF9}.Release|x64.Build.0 = Release|Any CPU
59+
{EE5F446D-3234-42AF-BCD5-C8FA5F867FF9}.Release|x86.ActiveCfg = Release|Any CPU
60+
{EE5F446D-3234-42AF-BCD5-C8FA5F867FF9}.Release|x86.Build.0 = Release|Any CPU
61+
{3D0C0BF4-6AD5-43DC-87C0-30C3C0A19911}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
62+
{3D0C0BF4-6AD5-43DC-87C0-30C3C0A19911}.Debug|Any CPU.Build.0 = Debug|Any CPU
63+
{3D0C0BF4-6AD5-43DC-87C0-30C3C0A19911}.Debug|x64.ActiveCfg = Debug|Any CPU
64+
{3D0C0BF4-6AD5-43DC-87C0-30C3C0A19911}.Debug|x64.Build.0 = Debug|Any CPU
65+
{3D0C0BF4-6AD5-43DC-87C0-30C3C0A19911}.Debug|x86.ActiveCfg = Debug|Any CPU
66+
{3D0C0BF4-6AD5-43DC-87C0-30C3C0A19911}.Debug|x86.Build.0 = Debug|Any CPU
67+
{3D0C0BF4-6AD5-43DC-87C0-30C3C0A19911}.Release|Any CPU.ActiveCfg = Release|Any CPU
68+
{3D0C0BF4-6AD5-43DC-87C0-30C3C0A19911}.Release|Any CPU.Build.0 = Release|Any CPU
69+
{3D0C0BF4-6AD5-43DC-87C0-30C3C0A19911}.Release|x64.ActiveCfg = Release|Any CPU
70+
{3D0C0BF4-6AD5-43DC-87C0-30C3C0A19911}.Release|x64.Build.0 = Release|Any CPU
71+
{3D0C0BF4-6AD5-43DC-87C0-30C3C0A19911}.Release|x86.ActiveCfg = Release|Any CPU
72+
{3D0C0BF4-6AD5-43DC-87C0-30C3C0A19911}.Release|x86.Build.0 = Release|Any CPU
73+
{FD9C4368-5E20-4ECD-A010-2AC111BFCB5F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
74+
{FD9C4368-5E20-4ECD-A010-2AC111BFCB5F}.Debug|Any CPU.Build.0 = Debug|Any CPU
75+
{FD9C4368-5E20-4ECD-A010-2AC111BFCB5F}.Debug|x64.ActiveCfg = Debug|Any CPU
76+
{FD9C4368-5E20-4ECD-A010-2AC111BFCB5F}.Debug|x64.Build.0 = Debug|Any CPU
77+
{FD9C4368-5E20-4ECD-A010-2AC111BFCB5F}.Debug|x86.ActiveCfg = Debug|Any CPU
78+
{FD9C4368-5E20-4ECD-A010-2AC111BFCB5F}.Debug|x86.Build.0 = Debug|Any CPU
79+
{FD9C4368-5E20-4ECD-A010-2AC111BFCB5F}.Release|Any CPU.ActiveCfg = Release|Any CPU
80+
{FD9C4368-5E20-4ECD-A010-2AC111BFCB5F}.Release|Any CPU.Build.0 = Release|Any CPU
81+
{FD9C4368-5E20-4ECD-A010-2AC111BFCB5F}.Release|x64.ActiveCfg = Release|Any CPU
82+
{FD9C4368-5E20-4ECD-A010-2AC111BFCB5F}.Release|x64.Build.0 = Release|Any CPU
83+
{FD9C4368-5E20-4ECD-A010-2AC111BFCB5F}.Release|x86.ActiveCfg = Release|Any CPU
84+
{FD9C4368-5E20-4ECD-A010-2AC111BFCB5F}.Release|x86.Build.0 = Release|Any CPU
85+
{3557A52A-96DD-4791-8D40-AE81D141B4D2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
86+
{3557A52A-96DD-4791-8D40-AE81D141B4D2}.Debug|Any CPU.Build.0 = Debug|Any CPU
87+
{3557A52A-96DD-4791-8D40-AE81D141B4D2}.Debug|x64.ActiveCfg = Debug|Any CPU
88+
{3557A52A-96DD-4791-8D40-AE81D141B4D2}.Debug|x64.Build.0 = Debug|Any CPU
89+
{3557A52A-96DD-4791-8D40-AE81D141B4D2}.Debug|x86.ActiveCfg = Debug|Any CPU
90+
{3557A52A-96DD-4791-8D40-AE81D141B4D2}.Debug|x86.Build.0 = Debug|Any CPU
91+
{3557A52A-96DD-4791-8D40-AE81D141B4D2}.Release|Any CPU.ActiveCfg = Release|Any CPU
92+
{3557A52A-96DD-4791-8D40-AE81D141B4D2}.Release|Any CPU.Build.0 = Release|Any CPU
93+
{3557A52A-96DD-4791-8D40-AE81D141B4D2}.Release|x64.ActiveCfg = Release|Any CPU
94+
{3557A52A-96DD-4791-8D40-AE81D141B4D2}.Release|x64.Build.0 = Release|Any CPU
95+
{3557A52A-96DD-4791-8D40-AE81D141B4D2}.Release|x86.ActiveCfg = Release|Any CPU
96+
{3557A52A-96DD-4791-8D40-AE81D141B4D2}.Release|x86.Build.0 = Release|Any CPU
97+
EndGlobalSection
98+
GlobalSection(SolutionProperties) = preSolution
99+
HideSolutionNode = FALSE
100+
EndGlobalSection
101+
GlobalSection(NestedProjects) = preSolution
102+
{FA7D165D-0A95-4ECE-8113-B7269706E9F1} = {ECF6AED3-BBB2-436D-A15F-3A37109DF26B}
103+
{EE5F446D-3234-42AF-BCD5-C8FA5F867FF9} = {0EAF3126-A656-48A1-9DA1-8AC2C1A8FD7D}
104+
{3D0C0BF4-6AD5-43DC-87C0-30C3C0A19911} = {CE194465-F09A-45CC-8D8A-5D17CCEC44C1}
105+
{FD9C4368-5E20-4ECD-A010-2AC111BFCB5F} = {CE194465-F09A-45CC-8D8A-5D17CCEC44C1}
106+
{3557A52A-96DD-4791-8D40-AE81D141B4D2} = {CE194465-F09A-45CC-8D8A-5D17CCEC44C1}
107+
EndGlobalSection
108+
GlobalSection(ExtensibilityGlobals) = postSolution
109+
SolutionGuid = {97132839-0BE6-47D1-A4C0-CB66F1AB6675}
110+
EndGlobalSection
111+
EndGlobal
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Router AppAssembly="@typeof(Program).Assembly" PreferExactMatches="@true">
2+
<Found Context="routeData">
3+
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
4+
</Found>
5+
<NotFound>
6+
<LayoutView Layout="@typeof(MainLayout)">
7+
<p>Sorry, there's nothing at this address.</p>
8+
</LayoutView>
9+
</NotFound>
10+
</Router>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net5.0</TargetFramework>
5+
6+
<!-- Globalization -->
7+
<BlazorWebAssemblyLoadAllGlobalizationData>true</BlazorWebAssemblyLoadAllGlobalizationData>
8+
9+
<!--
10+
<InvariantGlobalization>true</InvariantGlobalization>
11+
-->
12+
13+
</PropertyGroup>
14+
15+
16+
<ItemGroup>
17+
<PackageReference Include="Blazored.LocalStorage" Version="3.0.0" />
18+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.5" />
19+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.5" PrivateAssets="all" />
20+
<PackageReference Include="Microsoft.Extensions.Localization" Version="5.0.5" />
21+
<PackageReference Include="System.Net.Http.Json" Version="5.0.0" />
22+
<PackageReference Include="Toolbelt.Blazor.I18nText" Version="9.4.0" />
23+
</ItemGroup>
24+
25+
</Project>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel.DataAnnotations;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
7+
namespace FormComponents
8+
{
9+
10+
public class FritzHat
11+
{
12+
13+
[Required]
14+
public string Name { get; set; }
15+
16+
[MaxLength(100, ErrorMessage = "That's too much detail my friend. Get a little more direct in your description")]
17+
public string Description { get; set; }
18+
19+
public bool NeedsWashing { get; set; }
20+
21+
public string Genre { get; set; }
22+
23+
[Range(2000, 2021)]
24+
public int YearAcquired { get; set; }
25+
26+
27+
public DateTime DateLastWorn { get; set; }
28+
29+
}
30+
31+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
@page "/state"
2+
@inject Blazored.LocalStorage.ILocalStorageService localStorage
3+
@inject Toolbelt.Blazor.I18nText.I18nText I18nText
4+
5+
<h3>@MyText?.BrowserStateDemo</h3>
6+
7+
<EditForm Model="@TheHat" OnValidSubmit="@Submit">
8+
9+
<DataAnnotationsValidator />
10+
<ValidationSummary></ValidationSummary>
11+
12+
<p>
13+
<label>Name:
14+
<InputText @bind-Value="TheHat.Name" />
15+
</label>
16+
</p>
17+
18+
<p>
19+
<label>Description:
20+
<InputTextArea @bind-Value="TheHat.Description"></InputTextArea>
21+
</label>
22+
</p>
23+
24+
<p>
25+
<label>Needs Washing?
26+
<InputCheckbox @bind-Value="TheHat.NeedsWashing"></InputCheckbox>
27+
</label>
28+
</p>
29+
30+
<p>
31+
<label>Genre:
32+
<InputSelect @bind-Value="TheHat.Genre">
33+
<option value="">Select Genre...</option>
34+
<option value="TV">TV</option>
35+
<option value="Movie">Movie</option>
36+
<option value="Sport">Sport</option>
37+
<option value="Comics">Comics</option>
38+
<option value="Tech">Tech</option>
39+
</InputSelect>
40+
</label>
41+
</p>
42+
43+
<p>
44+
<label>Year Acquired:
45+
<InputNumber @bind-Value="TheHat.YearAcquired"></InputNumber>
46+
</label>
47+
</p>
48+
49+
<p>
50+
<label>Date Last Worn:
51+
<InputDate @bind-Value="TheHat.DateLastWorn"></InputDate>
52+
</label>
53+
<span>The date stored: @TheHat.DateLastWorn.ToShortDateString()</span>
54+
</p>
55+
56+
<button type="submit">Create Hat</button>
57+
58+
</EditForm>
59+
60+
@code {
61+
62+
public FritzHat TheHat { get; set; } = new FritzHat();
63+
64+
public I18nText.BlazorDemo MyText { get; set; }
65+
66+
protected override async Task OnInitializedAsync() {
67+
68+
MyText = await I18nText.GetTextTableAsync<I18nText.BlazorDemo>(this);
69+
70+
if (await localStorage.ContainKeyAsync("thehat")) {
71+
TheHat = await localStorage.GetItemAsync<FritzHat>("thehat");
72+
}
73+
74+
}
75+
76+
private async Task Submit()
77+
{
78+
79+
await localStorage.SetItemAsync("thehat", TheHat);
80+
81+
82+
}
83+
84+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
@page "/counter"
2+
3+
<h1>Counter</h1>
4+
5+
<p>Current count: @currentCount</p>
6+
7+
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
8+
9+
@code {
10+
private int currentCount = 0;
11+
12+
private void IncrementCount()
13+
{
14+
currentCount++;
15+
}
16+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
@page "/fetchdata"
2+
@inject HttpClient Http
3+
4+
<h1>Weather forecast</h1>
5+
6+
<p>This component demonstrates fetching data from the server.</p>
7+
8+
@if (forecasts == null)
9+
{
10+
<p><em>Loading...</em></p>
11+
}
12+
else
13+
{
14+
<table class="table">
15+
<thead>
16+
<tr>
17+
<th>Date</th>
18+
<th>Temp. (C)</th>
19+
<th>Temp. (F)</th>
20+
<th>Summary</th>
21+
</tr>
22+
</thead>
23+
<tbody>
24+
@foreach (var forecast in forecasts)
25+
{
26+
<tr>
27+
<td>@forecast.Date.ToShortDateString()</td>
28+
<td>@forecast.TemperatureC</td>
29+
<td>@forecast.TemperatureF</td>
30+
<td>@forecast.Summary</td>
31+
</tr>
32+
}
33+
</tbody>
34+
</table>
35+
}
36+
37+
@code {
38+
private WeatherForecast[] forecasts;
39+
40+
protected override async Task OnInitializedAsync()
41+
{
42+
forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("sample-data/weather.json");
43+
}
44+
45+
public class WeatherForecast
46+
{
47+
public DateTime Date { get; set; }
48+
49+
public int TemperatureC { get; set; }
50+
51+
public string Summary { get; set; }
52+
53+
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
54+
}
55+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
@page "/"
2+
3+
<h1>Hello, world!</h1>
4+
5+
Welcome to your new app.
6+
7+
<SurveyPrompt Title="How is Blazor working for you?" />
8+
9+
10+
<a href="/MyForm">Create a new hat for Fritz</a>
11+
12+
<br />
13+
14+
<a href="/state">Let's talk about state</a>

0 commit comments

Comments
 (0)