Skip to content

Commit f9ac2ef

Browse files
committed
added some changes
1 parent 4dfccff commit f9ac2ef

22 files changed

+1322
-1023
lines changed

App.razor

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
<Router AppAssembly="@typeof(Program).Assembly">
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>
1+
<Router AppAssembly="@typeof(Program).Assembly">
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>

BlazorDemo.csproj

-15
This file was deleted.

BlazorWasmDemo.csproj

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.1</TargetFramework>
5+
<RazorLangVersion>3.0</RazorLangVersion>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="3.2.1" />
10+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Build" Version="3.2.1" PrivateAssets="all" />
11+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="3.2.1" PrivateAssets="all" />
12+
<PackageReference Include="microsoft.extensions.logging.configuration" Version="3.1.9" />
13+
<PackageReference Include="System.Net.Http.Json" Version="3.2.0" />
14+
</ItemGroup>
15+
16+
</Project>

Pages/Counter.razor

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,16 +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-
}
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+
}

Pages/FetchData.razor

+55-55
Original file line numberDiff line numberDiff line change
@@ -1,55 +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.GetJsonAsync<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-
}
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+
}

Pages/Index.razor

+50-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,50 @@
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?" />
1+
@page "/"
2+
@inject IJSRuntime JS;
3+
4+
@using Microsoft.Extensions.Logging;
5+
@inject ILogger<Index> Logger;
6+
7+
8+
<h1>Hello, world!</h1>
9+
10+
Welcome to your new app.
11+
12+
<SurveyPrompt Title="How is Blazor working for you?" />
13+
14+
<br/><br/>
15+
<button class='btn btn-primary' @onclick='OnCreateLogs'>Create Logs!</button>
16+
<br/><br/>
17+
<button class='btn btn-primary' @onclick='OnListDevices'>List Devices!</button>
18+
<br/><br/>
19+
<p id='device-list'></p>
20+
21+
@functions {
22+
protected void OnCreateLogs()
23+
{
24+
var logLevels = Enum.GetValues(typeof(LogLevel)).Cast<LogLevel>();
25+
foreach (var logLevel in logLevels.Where(l => l != LogLevel.None))
26+
{
27+
Logger.Log(logLevel, logLevel.ToString());
28+
}
29+
}
30+
protected async Task OnListDevices()
31+
{
32+
try
33+
{
34+
var device = await this.JS.InvokeAsync<string>("getUSBDevices", new object[] { "ok" });
35+
//var device = "21234,234234";
36+
Console.WriteLine(device);
37+
var tokens = device.Split(",", StringSplitOptions.RemoveEmptyEntries);
38+
Console.WriteLine(tokens.Length);
39+
if (tokens.Length > 0)
40+
{
41+
string p_name = tokens[0];
42+
string s_num = tokens.Length > 1 ? tokens[1] : "";
43+
await this.JS.InvokeAsync<bool>("showDevice", new object[] { p_name, s_num });
44+
}
45+
}
46+
catch
47+
{}
48+
49+
}
50+
}

Program.cs

+35-20
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,35 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Threading.Tasks;
4-
using System.Text;
5-
using Microsoft.AspNetCore.Blazor.Hosting;
6-
using Microsoft.Extensions.DependencyInjection;
7-
8-
namespace BlazorDemo
9-
{
10-
public class Program
11-
{
12-
public static async Task Main(string[] args)
13-
{
14-
var builder = WebAssemblyHostBuilder.CreateDefault(args);
15-
builder.RootComponents.Add<App>("app");
16-
17-
await builder.Build().RunAsync();
18-
}
19-
}
20-
}
1+
using System;
2+
using System.Net.Http;
3+
using System.Collections.Generic;
4+
using System.Threading.Tasks;
5+
using System.Text;
6+
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
7+
using Microsoft.Extensions.Configuration;
8+
using Microsoft.Extensions.DependencyInjection;
9+
using Microsoft.Extensions.Logging;
10+
using Microsoft.Extensions.Logging.Configuration;
11+
12+
namespace BlazorWasmDemo
13+
{
14+
public class Program
15+
{
16+
public static async Task Main(string[] args)
17+
{
18+
var builder = WebAssemblyHostBuilder.CreateDefault(args);
19+
builder.RootComponents.Add<App>("app");
20+
21+
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
22+
23+
ConfigureLogging(builder);
24+
25+
await builder.Build().RunAsync();
26+
}
27+
28+
private static void ConfigureLogging(WebAssemblyHostBuilder builder, string section = "Logging")
29+
{
30+
builder.Logging.AddConfiguration(builder.Configuration.GetSection(section));
31+
}
32+
}
33+
34+
35+
}

Properties/launchSettings.json

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"iisSettings": {
3+
"windowsAuthentication": false,
4+
"anonymousAuthentication": true,
5+
"iisExpress": {
6+
"applicationUrl": "http://localhost:50680",
7+
"sslPort": 44395
8+
}
9+
},
10+
"profiles": {
11+
"IIS Express": {
12+
"commandName": "IISExpress",
13+
"launchBrowser": true,
14+
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
15+
"environmentVariables": {
16+
"ASPNETCORE_ENVIRONMENT": "Development"
17+
}
18+
},
19+
"BlazorWasmDemo": {
20+
"commandName": "Project",
21+
"launchBrowser": true,
22+
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
23+
"applicationUrl": "https://localhost:5001;http://localhost:5000",
24+
"environmentVariables": {
25+
"ASPNETCORE_ENVIRONMENT": "Development"
26+
}
27+
}
28+
}
29+
}

Shared/MainLayout.razor

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
@inherits LayoutComponentBase
2-
3-
<div class="sidebar">
4-
<NavMenu />
5-
</div>
6-
7-
<div class="main">
8-
<div class="top-row px-4">
9-
<a href="http://blazor.net" target="_blank" class="ml-md-auto">About</a>
10-
</div>
11-
12-
<div class="content px-4">
13-
@Body
14-
</div>
15-
</div>
1+
@inherits LayoutComponentBase
2+
3+
<div class="sidebar">
4+
<NavMenu />
5+
</div>
6+
7+
<div class="main">
8+
<div class="top-row px-4">
9+
<a href="http://blazor.net" target="_blank" class="ml-md-auto">About</a>
10+
</div>
11+
12+
<div class="content px-4">
13+
@Body
14+
</div>
15+
</div>

0 commit comments

Comments
 (0)