Skip to content

Commit

Permalink
Merge branch 'main' into 12Release
Browse files Browse the repository at this point in the history
  • Loading branch information
twsouthwick committed Jun 29, 2023
2 parents 58ff44e + 1f4826a commit ada67fc
Show file tree
Hide file tree
Showing 146 changed files with 87,093 additions and 28 deletions.
16 changes: 16 additions & 0 deletions Microsoft.AspNetCore.SystemWebAdapters.sln
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MvcCoreApp", "samples\Remot
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CoreApp", "samples\CoreApp\CoreApp.csproj", "{431651D7-D40A-403E-813C-496A1414AA22}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "WebFormsToBlazor", "WebFormsToBlazor", "{3A71E8B4-7E40-4326-B5FC-0CFA30A388D1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebFormsFramework", "samples\WebFormsToBlazor\WebFormsFramework\WebFormsFramework.csproj", "{0993BA4C-218B-43DD-A8A0-997B05808A08}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlazorCore", "samples\WebFormsToBlazor\BlazorCore\BlazorCore.csproj", "{23094126-C05C-4172-A01F-998780976709}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Modules", "Modules", "{4ED7A31C-8DBE-4A32-A17A-D72794F9FE2C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ModulesLibrary", "samples\Modules\ModulesLibrary\ModulesLibrary.csproj", "{5597A485-4D9B-4CE6-A489-DEBE9338450F}"
Expand Down Expand Up @@ -155,6 +160,14 @@ Global
{431651D7-D40A-403E-813C-496A1414AA22}.Debug|Any CPU.Build.0 = Debug|Any CPU
{431651D7-D40A-403E-813C-496A1414AA22}.Release|Any CPU.ActiveCfg = Release|Any CPU
{431651D7-D40A-403E-813C-496A1414AA22}.Release|Any CPU.Build.0 = Release|Any CPU
{0993BA4C-218B-43DD-A8A0-997B05808A08}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0993BA4C-218B-43DD-A8A0-997B05808A08}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0993BA4C-218B-43DD-A8A0-997B05808A08}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0993BA4C-218B-43DD-A8A0-997B05808A08}.Release|Any CPU.Build.0 = Release|Any CPU
{23094126-C05C-4172-A01F-998780976709}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{23094126-C05C-4172-A01F-998780976709}.Debug|Any CPU.Build.0 = Debug|Any CPU
{23094126-C05C-4172-A01F-998780976709}.Release|Any CPU.ActiveCfg = Release|Any CPU
{23094126-C05C-4172-A01F-998780976709}.Release|Any CPU.Build.0 = Release|Any CPU
{5597A485-4D9B-4CE6-A489-DEBE9338450F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5597A485-4D9B-4CE6-A489-DEBE9338450F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5597A485-4D9B-4CE6-A489-DEBE9338450F}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -196,6 +209,9 @@ Global
{174A36F1-27ED-43FC-A3A1-00DA58C4E30C} = {9C8EBDB5-FA17-4C9C-8946-04692AC752CE}
{2BF8EE74-1AB3-4DB8-ADDE-27A35981CA04} = {9C8EBDB5-FA17-4C9C-8946-04692AC752CE}
{431651D7-D40A-403E-813C-496A1414AA22} = {95915611-30BF-4AFF-AE41-5CDC6F57DCF7}
{3A71E8B4-7E40-4326-B5FC-0CFA30A388D1} = {95915611-30BF-4AFF-AE41-5CDC6F57DCF7}
{0993BA4C-218B-43DD-A8A0-997B05808A08} = {3A71E8B4-7E40-4326-B5FC-0CFA30A388D1}
{23094126-C05C-4172-A01F-998780976709} = {3A71E8B4-7E40-4326-B5FC-0CFA30A388D1}
{4ED7A31C-8DBE-4A32-A17A-D72794F9FE2C} = {95915611-30BF-4AFF-AE41-5CDC6F57DCF7}
{5597A485-4D9B-4CE6-A489-DEBE9338450F} = {4ED7A31C-8DBE-4A32-A17A-D72794F9FE2C}
{B262AD69-11F0-4AE0-949A-AEAA2300C061} = {4ED7A31C-8DBE-4A32-A17A-D72794F9FE2C}
Expand Down
12 changes: 12 additions & 0 deletions samples/WebFormsToBlazor/BlazorCore/App.razor
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 samples/WebFormsToBlazor/BlazorCore/BlazorCore.csproj
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>
<PackageReference Include="Microsoft.AspNetCore.Components.CustomElements" Version="7.0.3" />
<PackageReference Include="Yarp.ReverseProxy" Version="1.1.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\Microsoft.AspNetCore.SystemWebAdapters.CoreServices\Microsoft.AspNetCore.SystemWebAdapters.CoreServices.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using System.Reflection;
using Microsoft.AspNetCore.Components;

namespace BlazorCore;

public static class BlazorEndpointRouteBuilderExtensions
{
public static IEndpointConventionBuilder MapBlazorPages(this IEndpointRouteBuilder endpoints, string page)
{
var assembly = Assembly.GetEntryAssembly();
if (assembly is null)
{
throw new InvalidOperationException("No entry assembly available.");
}
return endpoints.MapBlazorPages(page, assembly);
}

public static IEndpointConventionBuilder MapBlazorPages(this IEndpointRouteBuilder endpoints, string page, params Assembly[] assemblies)
{
ArgumentNullException.ThrowIfNull(assemblies);
var builder = new BlazorEndpointConventionBuilder();
foreach (var route in GetRoutes(assemblies))
{
var conventionBuilder = endpoints.MapFallbackToPage(route, page);
conventionBuilder.Add(b =>
{
// By default this will be 'Fallback {route}', but this will help identify it is explicitly registered
b.DisplayName = $"Blazor {route}";
// {page} will, by default, have Order = 0; this will ensure the order is not the same
((RouteEndpointBuilder)b).Order = -1;
});
builder.Add(conventionBuilder);
}
return builder;
}

private static IEnumerable<string> GetRoutes(Assembly[] assemblies)
{
foreach (var assembly in assemblies)
{
foreach (var type in assembly.GetTypes())
{
if (typeof(IComponent).IsAssignableFrom(type))
{
foreach (var attribute in type.GetCustomAttributes(typeof(RouteAttribute)))
{
if (attribute is RouteAttribute { Template: { } route })
{
yield return route;
}
}
}
}
}
}

private sealed class BlazorEndpointConventionBuilder : IEndpointConventionBuilder
{
private readonly List<IEndpointConventionBuilder> _builders = new();
public void Add(IEndpointConventionBuilder builder)
{
_builders.Add(builder);
}
void IEndpointConventionBuilder.Add(Action<EndpointBuilder> convention)
{
foreach (var builder in _builders)
{
builder.Add(convention);
}
}
#if NET7_0_OR_GREATER
void IEndpointConventionBuilder.Finally(Action<EndpointBuilder> finalConvention)
{
foreach (var builder in _builders)
{
builder.Finally(finalConvention);
}
}
#endif
}
}
13 changes: 13 additions & 0 deletions samples/WebFormsToBlazor/BlazorCore/Data/WeatherForecast.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace BlazorCore.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; }
}
}
20 changes: 20 additions & 0 deletions samples/WebFormsToBlazor/BlazorCore/Data/WeatherForecastService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace BlazorCore.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());
}
}
}
8 changes: 8 additions & 0 deletions samples/WebFormsToBlazor/BlazorCore/HelloWorld.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<h3>HelloWorld from ASP.NET Core</h3>

Current path: @Path

@code {
[Parameter]
public string Path { get; set; } = "no-route";
}
18 changes: 18 additions & 0 deletions samples/WebFormsToBlazor/BlazorCore/Pages/Counter.razor
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++;
}
}
42 changes: 42 additions & 0 deletions samples/WebFormsToBlazor/BlazorCore/Pages/Error.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
@page
@model BlazorCore.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>
27 changes: 27 additions & 0 deletions samples/WebFormsToBlazor/BlazorCore/Pages/Error.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace BlazorCore.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 samples/WebFormsToBlazor/BlazorCore/Pages/FetchData.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
@page "/fetchdata"
@using BlazorCore.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));
}
}
9 changes: 9 additions & 0 deletions samples/WebFormsToBlazor/BlazorCore/Pages/Index.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@page "/i"

<PageTitle>Index</PageTitle>

<h1>Hello, world!</h1>

Welcome to your new app.

<SurveyPrompt Title="How is Blazor working for you?" />
36 changes: 36 additions & 0 deletions samples/WebFormsToBlazor/BlazorCore/Pages/_Host.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
@page "/blazor-host"
@* // This is to prevent '/' from being used if the root goes to the backend *@

@using Microsoft.AspNetCore.Components.Web
@namespace BlazorCore.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="BlazorCore.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>
Loading

0 comments on commit ada67fc

Please sign in to comment.