-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add server sample app, fix watch position bug, and fix publish nuget …
…bug.
- Loading branch information
1 parent
b22026a
commit fd7bb93
Showing
39 changed files
with
1,466 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
@page "/track" | ||
|
||
@inject IGeolocationService Geolocation | ||
|
||
<PageTitle>Geolocation</PageTitle> | ||
<h1> | ||
Geolocation | ||
@if (_isLoading) | ||
{ | ||
<span class="spinner-border text-primary" style="border-width: .12em;" role="status"> | ||
<span class="visually-hidden">Loading...</span> | ||
</span> | ||
} | ||
@if (_position is not null) | ||
{ | ||
<span class="pe-1">: | ||
<code> | ||
@(_position.TimestampAsUtcDateTime.ToLocalTime().ToString()) | ||
</code> | ||
</span> | ||
<a href="https://www.nuget.org/packages/Blazor.LocalStorage.WebAssembly" target="_blank" | ||
rel="noopener noreferrer nofollow"> | ||
<span class="oi oi-external-link"></span> | ||
</a> | ||
} | ||
</h1> | ||
|
||
@if (_isLoading) | ||
{ | ||
<p>This page demonstrates the source generated <code>Blazor.Geolocation.WebAssembly</code> package.</p> | ||
} | ||
|
||
@{ | ||
<Code Value=@_position T=GeolocationPosition IsError=false /> | ||
<Code Value=@_positionError T=GeolocationPositionError IsError=true /> | ||
|
||
<BingMap Position=@_position /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) David Pine. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
namespace Blazor.ExampleConsumer.Pages; | ||
|
||
public partial class Track : IDisposable | ||
{ | ||
readonly JsonSerializerOptions _opts = new() | ||
{ | ||
WriteIndented = true, | ||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase, | ||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull | ||
}; | ||
readonly PositionOptions _options = new() | ||
{ | ||
EnableHighAccuracy = true, | ||
MaximumAge = null, | ||
Timeout = 15_000 | ||
}; | ||
|
||
GeolocationPosition? _position; | ||
GeolocationPositionError? _positionError; | ||
double _watchId; | ||
bool _isLoading = true; | ||
|
||
protected override void OnInitialized() => | ||
_watchId = Geolocation.WatchPosition( | ||
component: this, | ||
onSuccessCallbackMethodName: nameof(OnPositionRecieved), | ||
onErrorCallbackMethodName: nameof(OnPositionError), | ||
options: _options); | ||
|
||
[JSInvokable] | ||
public void OnPositionRecieved(GeolocationPosition position) | ||
{ | ||
_isLoading = false; | ||
_position = position; | ||
StateHasChanged(); | ||
} | ||
|
||
[JSInvokable] | ||
public void OnPositionError(GeolocationPositionError positionError) | ||
{ | ||
_isLoading = false; | ||
_positionError = positionError; | ||
StateHasChanged(); | ||
} | ||
|
||
public void Dispose() => Geolocation.ClearWatch(_watchId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Router AppAssembly="@typeof(App).Assembly"> | ||
<Found Context="routeData"> | ||
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" /> | ||
<FocusOnNavigate RouteData="@routeData" Selector="h1" /> | ||
</Found> | ||
<NotFound> | ||
<PageTitle>Not found</PageTitle> | ||
<LayoutView Layout="@typeof(MainLayout)"> | ||
<p role="alert">Sorry, there's nothing at this address.</p> | ||
</LayoutView> | ||
</NotFound> | ||
</Router> |
18 changes: 18 additions & 0 deletions
18
samples/BlazorServer.ExampleConsumer/BlazorServer.ExampleConsumer.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Blazor.Geolocation\Blazor.Geolocation.csproj" /> | ||
<ProjectReference Include="..\..\src\Blazor.LocalStorage\Blazor.LocalStorage.csproj" /> | ||
<ProjectReference Include="..\..\src\Blazor.Serialization\Blazor.Serialization.csproj" /> | ||
<ProjectReference Include="..\..\src\Blazor.SessionStorage\Blazor.SessionStorage.csproj" /> | ||
<ProjectReference Include="..\..\src\Blazor.SpeechRecognition\Blazor.SpeechRecognition.csproj" /> | ||
<ProjectReference Include="..\..\src\Blazor.SpeechSynthesis\Blazor.SpeechSynthesis.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
15 changes: 15 additions & 0 deletions
15
samples/BlazorServer.ExampleConsumer/Data/WeatherForecast.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (c) David Pine. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
namespace BlazorServer.ExampleConsumer.Data; | ||
|
||
public class WeatherForecast | ||
{ | ||
public DateOnly Date { get; set; } | ||
|
||
public int TemperatureC { get; set; } | ||
|
||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); | ||
|
||
public string? Summary { get; set; } | ||
} |
22 changes: 22 additions & 0 deletions
22
samples/BlazorServer.ExampleConsumer/Data/WeatherForecastService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (c) David Pine. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
namespace BlazorServer.ExampleConsumer.Data; | ||
|
||
public class WeatherForecastService | ||
{ | ||
private static readonly string[] Summaries = new[] | ||
{ | ||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" | ||
}; | ||
|
||
public Task<WeatherForecast[]> GetForecastAsync(DateOnly startDate) | ||
{ | ||
return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast | ||
{ | ||
Date = startDate.AddDays(index), | ||
TemperatureC = Random.Shared.Next(-20, 55), | ||
Summary = Summaries[Random.Shared.Next(Summaries.Length)] | ||
}).ToArray()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
@page "/counter" | ||
|
||
<PageTitle>Counter</PageTitle> | ||
|
||
<h1>Counter</h1> | ||
|
||
<p role="status">Current count: @currentCount</p> | ||
|
||
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button> | ||
|
||
@code { | ||
private int currentCount = 0; | ||
|
||
private void IncrementCount() | ||
{ | ||
currentCount++; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
@page | ||
@model BlazorServer.ExampleConsumer.Pages.ErrorModel | ||
|
||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /> | ||
<title>Error</title> | ||
<link href="~/css/bootstrap/bootstrap.min.css" rel="stylesheet" /> | ||
<link href="~/css/site.css" rel="stylesheet" asp-append-version="true" /> | ||
</head> | ||
|
||
<body> | ||
<div class="main"> | ||
<div class="content px-4"> | ||
<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> | ||
</div> | ||
</div> | ||
</body> | ||
|
||
</html> |
28 changes: 28 additions & 0 deletions
28
samples/BlazorServer.ExampleConsumer/Pages/Error.cshtml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) David Pine. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System.Diagnostics; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
|
||
namespace BlazorServer.ExampleConsumer.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; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
samples/BlazorServer.ExampleConsumer/Pages/FetchData.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
@page "/fetchdata" | ||
@using BlazorServer.ExampleConsumer.Data | ||
@inject WeatherForecastService ForecastService | ||
|
||
<PageTitle>Weather forecast</PageTitle> | ||
|
||
<h1>Weather forecast</h1> | ||
|
||
<p>This component demonstrates fetching data from a service.</p> | ||
|
||
@if (forecasts == null) | ||
{ | ||
<p><em>Loading...</em></p> | ||
} | ||
else | ||
{ | ||
<table class="table"> | ||
<thead> | ||
<tr> | ||
<th>Date</th> | ||
<th>Temp. (C)</th> | ||
<th>Temp. (F)</th> | ||
<th>Summary</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
@foreach (var forecast in forecasts) | ||
{ | ||
<tr> | ||
<td>@forecast.Date.ToShortDateString()</td> | ||
<td>@forecast.TemperatureC</td> | ||
<td>@forecast.TemperatureF</td> | ||
<td>@forecast.Summary</td> | ||
</tr> | ||
} | ||
</tbody> | ||
</table> | ||
} | ||
|
||
@code { | ||
private WeatherForecast[]? forecasts; | ||
|
||
protected override async Task OnInitializedAsync() | ||
{ | ||
forecasts = await ForecastService.GetForecastAsync(DateOnly.FromDateTime(DateTime.Now)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
@page "/" | ||
|
||
<PageTitle>Index</PageTitle> | ||
|
||
<h1>Hello, world!</h1> | ||
|
||
Welcome to your new app. | ||
|
||
<SurveyPrompt Title="How is Blazor working for you?" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
@page "/" | ||
@using Microsoft.AspNetCore.Components.Web | ||
@namespace BlazorServer.ExampleConsumer.Pages | ||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers | ||
|
||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<base href="~/" /> | ||
<link rel="stylesheet" href="css/bootstrap/bootstrap.min.css" /> | ||
<link href="css/site.css" rel="stylesheet" /> | ||
<link href="BlazorServer.ExampleConsumer.styles.css" rel="stylesheet" /> | ||
<link rel="icon" type="image/png" href="favicon.png"/> | ||
<component type="typeof(HeadOutlet)" render-mode="ServerPrerendered" /> | ||
</head> | ||
<body> | ||
<component type="typeof(App)" render-mode="ServerPrerendered" /> | ||
|
||
<div id="blazor-error-ui"> | ||
<environment include="Staging,Production"> | ||
An error has occurred. This application may no longer respond until reloaded. | ||
</environment> | ||
<environment include="Development"> | ||
An unhandled exception has occurred. See browser dev tools for details. | ||
</environment> | ||
<a href="" class="reload">Reload</a> | ||
<a class="dismiss">🗙</a> | ||
</div> | ||
|
||
<script src="_framework/blazor.server.js"></script> | ||
</body> | ||
</html> |
Oops, something went wrong.