Skip to content

Commit 2c1b9ed

Browse files
Blazor SSR scenario (#1804)
1 parent c4d1a24 commit 2c1b9ed

Some content is hidden

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

48 files changed

+2136
-0
lines changed

scenarios/blazor.benchmarks.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
imports:
2+
- https://raw.githubusercontent.com/dotnet/crank/main/src/Microsoft.Crank.Jobs.Bombardier/bombardier.yml
3+
- https://github.com/aspnet/Benchmarks/blob/main/scenarios/aspnet.profiles.yml?raw=true
4+
5+
jobs:
6+
server:
7+
source:
8+
repository: https://github.com/aspnet/benchmarks.git
9+
branchOrCommit: main
10+
project: src/BenchmarksApps/BlazorBlazingPizza/BlazingPizza.Server.csproj
11+
12+
scenarios:
13+
ssr:
14+
application:
15+
job: server
16+
framework: net8.0
17+
load:
18+
job: bombardier
19+
variables:
20+
serverPort: 5000
21+
path: /
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<Router AppAssembly="typeof(Program).Assembly">
2+
<NotFound>Page not found</NotFound>
3+
<Found Context="routeData">
4+
<RouteView RouteData="routeData" DefaultLayout="typeof(MainLayout)"></RouteView>
5+
</Found>
6+
</Router>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
</PropertyGroup>
7+
8+
</Project>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using Microsoft.JSInterop;
2+
3+
namespace BlazingPizza.Server;
4+
5+
public static class JSRuntimeExtensions
6+
{
7+
public static ValueTask<bool> Confirm(this IJSRuntime jsRuntime, string message)
8+
{
9+
return jsRuntime.InvokeAsync<bool>("confirm", message);
10+
}
11+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System.ComponentModel.DataAnnotations;
2+
3+
namespace BlazingPizza.Server.Model;
4+
5+
public class Address
6+
{
7+
public int Id { get; set; }
8+
9+
[Required, MaxLength(100)]
10+
public string Name { get; set; }
11+
12+
[Required, MaxLength(100)]
13+
public string Line1 { get; set; }
14+
15+
[MaxLength(100)]
16+
public string Line2 { get; set; }
17+
18+
[Required, MaxLength(50)]
19+
public string City { get; set; }
20+
21+
[Required, MaxLength(20)]
22+
public string Region { get; set; }
23+
24+
[Required, MaxLength(20)]
25+
public string PostalCode { get; set; }
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
namespace BlazingPizza.Server.Model;
2+
3+
public class LatLong
4+
{
5+
public LatLong()
6+
{
7+
}
8+
9+
public LatLong(double latitude, double longitude) : this()
10+
{
11+
Latitude = latitude;
12+
Longitude = longitude;
13+
}
14+
15+
public double Latitude { get; set; }
16+
17+
public double Longitude { get; set; }
18+
19+
public static LatLong Interpolate(LatLong start, LatLong end, double proportion)
20+
{
21+
// The Earth is flat, right? So no need for spherical interpolation.
22+
return new LatLong(
23+
start.Latitude + (end.Latitude - start.Latitude) * proportion,
24+
start.Longitude + (end.Longitude - start.Longitude) * proportion);
25+
}
26+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System.Globalization;
2+
3+
namespace BlazingPizza.Server.Model;
4+
5+
public class Order
6+
{
7+
public int OrderId { get; set; }
8+
9+
public string UserId { get; set; }
10+
11+
public DateTime CreatedTime { get; set; }
12+
13+
public Address DeliveryAddress { get; set; } = new Address();
14+
15+
public LatLong DeliveryLocation { get; set; }
16+
17+
public List<Pizza> Pizzas { get; set; } = new List<Pizza>();
18+
19+
public decimal GetTotalPrice() => Pizzas.Sum(p => p.GetTotalPrice());
20+
21+
public string GetFormattedTotalPrice() => GetTotalPrice().ToString("0.00", CultureInfo.CurrentCulture);
22+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
namespace BlazingPizza.Server.Model;
2+
3+
public class OrderState
4+
{
5+
private readonly ILogger<OrderState> logger;
6+
7+
public OrderState(ILogger<OrderState> logger)
8+
{
9+
this.logger = logger;
10+
}
11+
12+
public bool ShowingConfigureDialog { get; private set; }
13+
14+
public Pizza ConfiguringPizza { get; private set; }
15+
16+
public Order Order { get; private set; } = new Order();
17+
18+
public void ShowConfigurePizzaDialog(PizzaSpecial special)
19+
{
20+
logger.LogInformation($"Configuring pizza {special.Id}");
21+
22+
ConfiguringPizza = new Pizza()
23+
{
24+
Special = special,
25+
SpecialId = special.Id,
26+
Size = Pizza.DefaultSize,
27+
Toppings = new List<PizzaTopping>(),
28+
};
29+
30+
ShowingConfigureDialog = true;
31+
}
32+
33+
public void CancelConfigurePizzaDialog()
34+
{
35+
ConfiguringPizza = null;
36+
37+
ShowingConfigureDialog = false;
38+
}
39+
40+
public void ConfirmConfigurePizzaDialog()
41+
{
42+
logger.LogInformation($"Adding pizza {ConfiguringPizza.SpecialId}");
43+
44+
Order.Pizzas.Add(ConfiguringPizza);
45+
ConfiguringPizza = null;
46+
47+
ShowingConfigureDialog = false;
48+
}
49+
50+
public void RemoveConfiguredPizza(Pizza pizza)
51+
{
52+
Order.Pizzas.Remove(pizza);
53+
}
54+
55+
public void ResetOrder()
56+
{
57+
Order = new Order();
58+
}
59+
60+
public void ReplaceOrder(Order order)
61+
{
62+
Order = order;
63+
}
64+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System.Globalization;
2+
3+
namespace BlazingPizza.Server.Model;
4+
5+
/// <summary>
6+
/// Represents a customized pizza as part of an order
7+
/// </summary>
8+
public class Pizza
9+
{
10+
public const int DefaultSize = 12;
11+
public const int MinimumSize = 9;
12+
public const int MaximumSize = 17;
13+
14+
public int Id { get; set; }
15+
16+
public int OrderId { get; set; }
17+
18+
public PizzaSpecial Special { get; set; }
19+
20+
public int SpecialId { get; set; }
21+
22+
public int Size { get; set; }
23+
24+
public List<PizzaTopping> Toppings { get; set; }
25+
26+
public decimal GetBasePrice()
27+
{
28+
return Special.BasePrice * (decimal)Size / DefaultSize;
29+
}
30+
31+
public decimal GetTotalPrice()
32+
{
33+
return GetBasePrice() + Toppings.Sum(t => t.Topping.Price);
34+
}
35+
36+
public string GetFormattedTotalPrice()
37+
{
38+
return GetTotalPrice().ToString("0.00", CultureInfo.CurrentCulture);
39+
}
40+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.Globalization;
2+
3+
namespace BlazingPizza.Server.Model;
4+
5+
/// <summary>
6+
/// Represents a pre-configured template for a pizza a user can order
7+
/// </summary>
8+
public class PizzaSpecial
9+
{
10+
public int Id { get; set; }
11+
12+
public string Name { get; set; }
13+
14+
public int BasePrice { get; set; }
15+
16+
public string Description { get; set; }
17+
18+
public string ImageUrl { get; set; }
19+
20+
public string GetFormattedBasePrice() => BasePrice.ToString("0.00", CultureInfo.CurrentCulture);
21+
}

0 commit comments

Comments
 (0)