Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions scenarios/blazor.benchmarks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
imports:
- https://raw.githubusercontent.com/dotnet/crank/main/src/Microsoft.Crank.Jobs.Bombardier/bombardier.yml
- https://github.com/aspnet/Benchmarks/blob/main/scenarios/aspnet.profiles.yml?raw=true

jobs:
server:
source:
repository: https://github.com/aspnet/benchmarks.git
branchOrCommit: main
project: src/BenchmarksApps/BlazorBlazingPizza/BlazingPizza.Server.csproj

scenarios:
ssr:
application:
job: server
framework: net8.0
load:
job: bombardier
variables:
serverPort: 5000
path: /
6 changes: 6 additions & 0 deletions src/BenchmarksApps/BlazorBlazingPizza/App.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Router AppAssembly="typeof(Program).Assembly">
<NotFound>Page not found</NotFound>
<Found Context="routeData">
<RouteView RouteData="routeData" DefaultLayout="typeof(MainLayout)"></RouteView>
</Found>
</Router>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

</Project>
11 changes: 11 additions & 0 deletions src/BenchmarksApps/BlazorBlazingPizza/JSRuntimeExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Microsoft.JSInterop;

namespace BlazingPizza.Server;

public static class JSRuntimeExtensions
{
public static ValueTask<bool> Confirm(this IJSRuntime jsRuntime, string message)
{
return jsRuntime.InvokeAsync<bool>("confirm", message);
}
}
26 changes: 26 additions & 0 deletions src/BenchmarksApps/BlazorBlazingPizza/Model/Address.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.ComponentModel.DataAnnotations;

namespace BlazingPizza.Server.Model;

public class Address
{
public int Id { get; set; }

[Required, MaxLength(100)]
public string Name { get; set; }

[Required, MaxLength(100)]
public string Line1 { get; set; }

[MaxLength(100)]
public string Line2 { get; set; }

[Required, MaxLength(50)]
public string City { get; set; }

[Required, MaxLength(20)]
public string Region { get; set; }

[Required, MaxLength(20)]
public string PostalCode { get; set; }
}
26 changes: 26 additions & 0 deletions src/BenchmarksApps/BlazorBlazingPizza/Model/LatLong.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace BlazingPizza.Server.Model;

public class LatLong
{
public LatLong()
{
}

public LatLong(double latitude, double longitude) : this()
{
Latitude = latitude;
Longitude = longitude;
}

public double Latitude { get; set; }

public double Longitude { get; set; }

public static LatLong Interpolate(LatLong start, LatLong end, double proportion)
{
// The Earth is flat, right? So no need for spherical interpolation.
return new LatLong(
start.Latitude + (end.Latitude - start.Latitude) * proportion,
start.Longitude + (end.Longitude - start.Longitude) * proportion);
}
}
22 changes: 22 additions & 0 deletions src/BenchmarksApps/BlazorBlazingPizza/Model/Order.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Globalization;

namespace BlazingPizza.Server.Model;

public class Order
{
public int OrderId { get; set; }

public string UserId { get; set; }

public DateTime CreatedTime { get; set; }

public Address DeliveryAddress { get; set; } = new Address();

public LatLong DeliveryLocation { get; set; }

public List<Pizza> Pizzas { get; set; } = new List<Pizza>();

public decimal GetTotalPrice() => Pizzas.Sum(p => p.GetTotalPrice());

public string GetFormattedTotalPrice() => GetTotalPrice().ToString("0.00", CultureInfo.CurrentCulture);
}
64 changes: 64 additions & 0 deletions src/BenchmarksApps/BlazorBlazingPizza/Model/OrderState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
namespace BlazingPizza.Server.Model;

public class OrderState
{
private readonly ILogger<OrderState> logger;

public OrderState(ILogger<OrderState> logger)
{
this.logger = logger;
}

public bool ShowingConfigureDialog { get; private set; }

public Pizza ConfiguringPizza { get; private set; }

public Order Order { get; private set; } = new Order();

public void ShowConfigurePizzaDialog(PizzaSpecial special)
{
logger.LogInformation($"Configuring pizza {special.Id}");

ConfiguringPizza = new Pizza()
{
Special = special,
SpecialId = special.Id,
Size = Pizza.DefaultSize,
Toppings = new List<PizzaTopping>(),
};

ShowingConfigureDialog = true;
}

public void CancelConfigurePizzaDialog()
{
ConfiguringPizza = null;

ShowingConfigureDialog = false;
}

public void ConfirmConfigurePizzaDialog()
{
logger.LogInformation($"Adding pizza {ConfiguringPizza.SpecialId}");

Order.Pizzas.Add(ConfiguringPizza);
ConfiguringPizza = null;

ShowingConfigureDialog = false;
}

public void RemoveConfiguredPizza(Pizza pizza)
{
Order.Pizzas.Remove(pizza);
}

public void ResetOrder()
{
Order = new Order();
}

public void ReplaceOrder(Order order)
{
Order = order;
}
}
40 changes: 40 additions & 0 deletions src/BenchmarksApps/BlazorBlazingPizza/Model/Pizza.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.Globalization;

namespace BlazingPizza.Server.Model;

/// <summary>
/// Represents a customized pizza as part of an order
/// </summary>
public class Pizza
{
public const int DefaultSize = 12;
public const int MinimumSize = 9;
public const int MaximumSize = 17;

public int Id { get; set; }

public int OrderId { get; set; }

public PizzaSpecial Special { get; set; }

public int SpecialId { get; set; }

public int Size { get; set; }

public List<PizzaTopping> Toppings { get; set; }

public decimal GetBasePrice()
{
return Special.BasePrice * (decimal)Size / DefaultSize;
}

public decimal GetTotalPrice()
{
return GetBasePrice() + Toppings.Sum(t => t.Topping.Price);
}

public string GetFormattedTotalPrice()
{
return GetTotalPrice().ToString("0.00", CultureInfo.CurrentCulture);
}
}
21 changes: 21 additions & 0 deletions src/BenchmarksApps/BlazorBlazingPizza/Model/PizzaSpecial.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Globalization;

namespace BlazingPizza.Server.Model;

/// <summary>
/// Represents a pre-configured template for a pizza a user can order
/// </summary>
public class PizzaSpecial
{
public int Id { get; set; }

public string Name { get; set; }

public int BasePrice { get; set; }

public string Description { get; set; }

public string ImageUrl { get; set; }

public string GetFormattedBasePrice() => BasePrice.ToString("0.00", CultureInfo.CurrentCulture);
}
10 changes: 10 additions & 0 deletions src/BenchmarksApps/BlazorBlazingPizza/Model/PizzaTopping.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace BlazingPizza.Server.Model;

public class PizzaTopping
{
public Topping Topping { get; set; }

public int ToppingId { get; set; }

public int PizzaId { get; set; }
}
8 changes: 8 additions & 0 deletions src/BenchmarksApps/BlazorBlazingPizza/Model/Point.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace BlazingPizza.Server.Model;

public class Point
{
public double X { get; set; }

public double Y { get; set; }
}
74 changes: 74 additions & 0 deletions src/BenchmarksApps/BlazorBlazingPizza/Model/SpecialsService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
namespace BlazingPizza.Server.Model;

public class SpecialsService
{
public IList<PizzaSpecial> GetSpecials()
{
return new PizzaSpecial[]
{
new PizzaSpecial()
{
Name = "Basic Cheese Pizza",
Description = "It's cheesy and delicious. Why wouldn't you want one?",
BasePrice = 9,
ImageUrl = "img/pizzas/cheese.jpg",
},
new PizzaSpecial()
{
Id = 2,
Name = "The Baconatorizor",
Description = "It has EVERY kind of bacon",
BasePrice = 12,
ImageUrl = "img/pizzas/bacon.jpg",
},
new PizzaSpecial()
{
Id = 3,
Name = "Classic pepperoni",
Description = "It's the pizza you grew up with, but Blazing hot!",
BasePrice = 10,
ImageUrl = "img/pizzas/pepperoni.jpg",
},
new PizzaSpecial()
{
Id = 4,
Name = "Buffalo chicken",
Description = "Spicy chicken, hot sauce and bleu cheese, guaranteed to warm you up",
BasePrice = 12,
ImageUrl = "img/pizzas/meaty.jpg",
},
new PizzaSpecial()
{
Id = 5,
Name = "Mushroom Lovers",
Description = "It has mushrooms. Isn't that obvious?",
BasePrice = 11,
ImageUrl = "img/pizzas/mushroom.jpg",
},
new PizzaSpecial()
{
Id = 6,
Name = "The Brit",
Description = "When in London...",
BasePrice = 10,
ImageUrl = "img/pizzas/brit.jpg",
},
new PizzaSpecial()
{
Id = 7,
Name = "Veggie Delight",
Description = "It's like salad, but on a pizza",
BasePrice = 11,
ImageUrl = "img/pizzas/salad.jpg",
},
new PizzaSpecial()
{
Id = 8,
Name = "Margherita",
Description = "Traditional Italian pizza with tomatoes and basil",
BasePrice = 9,
ImageUrl = "img/pizzas/margherita.jpg",
},
};
}
}
14 changes: 14 additions & 0 deletions src/BenchmarksApps/BlazorBlazingPizza/Model/Topping.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Globalization;

namespace BlazingPizza.Server.Model;

public class Topping
{
public int Id { get; set; }

public string Name { get; set; }

public decimal Price { get; set; }

public string GetFormattedPrice() => Price.ToString("0.00", CultureInfo.CurrentCulture);
}
Loading