Skip to content

Commit

Permalink
Update Orleans App Service sample to work on App Service Linux (#10)
Browse files Browse the repository at this point in the history
* Update Orleans App Service sample to work on App Service Linux

* Update Silo/Components/PurchasableProductTable.razor

---------

Co-authored-by: David Pine <[email protected]>
  • Loading branch information
ReubenBond and IEvangelist authored Oct 2, 2024
1 parent af1bfdf commit 59c19c3
Show file tree
Hide file tree
Showing 29 changed files with 163 additions and 169 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Setup .NET 7.0
- name: Setup .NET 8.0
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
dotnet-version: 8.0.x

- name: .NET publish shopping cart app
run: dotnet publish ./Silo/Orleans.ShoppingCart.Silo.csproj --configuration Release
Expand Down
1 change: 1 addition & 0 deletions Abstractions/CartItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Orleans.ShoppingCart.Abstractions;

[GenerateSerializer, Immutable]
[Alias("Orleans.ShoppingCart.Abstractions.CartItem")]
public sealed record class CartItem(
string UserId,
int Quantity,
Expand Down
6 changes: 3 additions & 3 deletions Abstractions/Orleans.ShoppingCart.Abstractions.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

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

<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.11.3" />
<PackageReference Include="Azure.Identity" Version="1.12.1" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.22.0" />
<PackageReference Include="Microsoft.Orleans.Sdk" Version="7.0.0" />
<PackageReference Include="Microsoft.Orleans.Sdk" Version="8.2.0" />
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions Abstractions/ProductCategory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace Orleans.ShoppingCart.Abstractions;

[GenerateSerializer]
public enum ProductCategory
{
Accessories,
Expand Down
20 changes: 14 additions & 6 deletions Abstractions/ProductDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,25 @@

namespace Orleans.ShoppingCart.Abstractions;

[GenerateSerializer, Immutable]
[GenerateSerializer]
public sealed record class ProductDetails
{
public string Id { get; set; } = null!;
public string Name { get; set; } = null!;
public string Description { get; set; } = null!;
[Id(0)]
public string? Id { get; set; }
[Id(1)]
public string? Name { get; set; }
[Id(2)]
public string? Description { get; set; }
[Id(3)]
public ProductCategory Category { get; set; }
[Id(4)]
public int Quantity { get; set; }
[Id(5)]
public decimal UnitPrice { get; set; }
public string DetailsUrl { get; set; } = null!;
public string ImageUrl { get; set; } = null!;
[Id(6)]
public string? DetailsUrl { get; set; }
[Id(7)]
public string? ImageUrl { get; set; }

[JsonIgnore]
public decimal TotalPrice =>
Expand Down
1 change: 1 addition & 0 deletions Grains/InventoryGrain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Task<HashSet<ProductDetails>> IInventoryGrain.GetAllProductsAsync() =>

async Task IInventoryGrain.AddOrUpdateProductAsync(ProductDetails product)
{
ArgumentNullException.ThrowIfNull(product.Id);
_productIds.State.Add(product.Id);
_productCache[product.Id] = product;

Expand Down
8 changes: 4 additions & 4 deletions Grains/Orleans.ShoppingCart.Grains.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

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

<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.11.3" />
<PackageReference Include="Azure.Identity" Version="1.12.1" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.22.0" />
<PackageReference Include="Microsoft.Orleans.Runtime" Version="7.0.0" />
<PackageReference Include="Microsoft.Orleans.Sdk" Version="7.0.0" />
<PackageReference Include="Microsoft.Orleans.Runtime" Version="8.2.0" />
<PackageReference Include="Microsoft.Orleans.Sdk" Version="8.2.0" />
</ItemGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions Grains/ProductGrain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Task IProductGrain.CreateOrUpdateProductAsync(ProductDetails productDetails) =>

private async Task UpdateStateAsync(ProductDetails product)
{
ArgumentNullException.ThrowIfNull(product.Id);
var oldCategory = _product.State.Category;

_product.State = product;
Expand Down
7 changes: 6 additions & 1 deletion Grains/ShoppingCartGrain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public ShoppingCartGrain(

async Task<bool> IShoppingCartGrain.AddOrUpdateItemAsync(int quantity, ProductDetails product)
{
ArgumentNullException.ThrowIfNull(product.Id);
var products = GrainFactory.GetGrain<IProductGrain>(product.Id);

int? adjustedQuantity = null;
Expand All @@ -29,7 +30,10 @@ async Task<bool> IShoppingCartGrain.AddOrUpdateItemAsync(int quantity, ProductDe
if (isAvailable && claimedProduct is not null)
{
var item = ToCartItem(quantity, claimedProduct);
_cart.State[claimedProduct.Id] = item;
if (!string.IsNullOrEmpty(claimedProduct.Id))
{
_cart.State[claimedProduct.Id] = item;
}

await _cart.WriteStateAsync();
return true;
Expand All @@ -52,6 +56,7 @@ Task<int> IShoppingCartGrain.GetTotalItemsInCartAsync() =>

async Task IShoppingCartGrain.RemoveItemAsync(ProductDetails product)
{
ArgumentNullException.ThrowIfNull(product.Id);
var products = GrainFactory.GetGrain<IProductGrain>(product.Id);
await products.ReturnProductAsync(product.Quantity);

Expand Down
2 changes: 1 addition & 1 deletion Silo/App.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Router AppAssembly="@typeof(Startup).Assembly">
<Router AppAssembly="@typeof(Program).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
</Found>
Expand Down
2 changes: 1 addition & 1 deletion Silo/Components/ManageProductModal.razor
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

public void Close() => MudDialog?.Cancel();

private void Bogus() => Product = Product.GetBogusFaker().Generate();
private void Bogus() => Product = ProductDetailsExtensions.ProductDetailsFaker.Generate();

private Task Save()
{
Expand Down
14 changes: 7 additions & 7 deletions Silo/Components/ProductTable.razor
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
@using Blazor.Serialization.Extensions

<MudStack>
<MudToolBar DisableGutters="true">
<MudToolBar Gutters="false">
<MudText Typo="Typo.h4">@Title</MudText>
<MudSpacer />
@ChildContent
<MudPaper Outlined="true" Class="flex-grow-1 pb-2 pl-3">
<MudPaper Outlined="true" Class="flex-grow-1 pa-2 ma-3">
<MudTextField @bind-Value="_filter" Placeholder="Search products" Adornment="Adornment.Start"
AdornmentIcon="@Icons.Material.Filled.Search" IconSize="Size.Medium" Class="mt-n2" DisableUnderLine="true">
AdornmentIcon="@Icons.Material.Filled.Search" IconSize="Size.Medium" Class="d-flex justify-center" Underline=false>
</MudTextField>
</MudPaper>
</MudToolBar>
Expand All @@ -18,22 +18,22 @@
IsEditRowSwitchingBlocked=true>
<HeaderContent>
<MudTh>
<MudTableSortLabel SortBy=@(new Func<ProductDetails, object>(p => p.Name))>
<MudTableSortLabel SortBy=@(new Func<ProductDetails, object>(p => p.Name!))>
Name
</MudTableSortLabel>
</MudTh>
<MudTh>
<MudTableSortLabel SortBy=@(new Func<ProductDetails, object>(p => p.Description))>
<MudTableSortLabel SortBy=@(new Func<ProductDetails, object>(p => p.Description!))>
Description
</MudTableSortLabel>
</MudTh>
<MudTh>
<MudTableSortLabel SortBy=@(new Func<ProductDetails, object>(p => p.Quantity))>
<MudTableSortLabel SortBy=@(new Func<ProductDetails, object>(p => p.Quantity!))>
Quantity
</MudTableSortLabel>
</MudTh>
<MudTh>
<MudTableSortLabel SortBy=@(new Func<ProductDetails, object>(p => p.UnitPrice))>
<MudTableSortLabel SortBy=@(new Func<ProductDetails, object>(p => p.UnitPrice!))>
Price
</MudTableSortLabel>
</MudTh>
Expand Down
27 changes: 15 additions & 12 deletions Silo/Components/PurchasableProductTable.razor
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<MudStack>
<MudToolBar DisableGutters="true">
<MudToolBar Gutters="false">
<MudText Typo="Typo.h4">@Title</MudText>
<MudSpacer />
<MudPaper Outlined="true" Class="flex-grow-1 pb-2 pl-3">
<MudPaper Outlined="true" Class="flex-grow-1 pa-2 ma-3">
<MudTextField @bind-Value="_filter" Placeholder="Search products" Adornment="Adornment.Start"
AdornmentIcon="@Icons.Material.Filled.Search" IconSize="Size.Medium" Class="mt-n2" DisableUnderLine="true">
AdornmentIcon="@Icons.Material.Filled.Search" IconSize="Size.Medium" Class="d-flex justify-center" Underline="false">
</MudTextField>
</MudPaper>
</MudToolBar>
Expand All @@ -13,22 +13,22 @@
<HeaderContent>
<MudTh>Products</MudTh>
<MudTh>
<MudTableSortLabel SortBy=@(new Func<ProductDetails, object>(p => p.Name))>
<MudTableSortLabel SortBy=@(new Func<ProductDetails, object>(p => p.Name!))>
Name
</MudTableSortLabel>
</MudTh>
<MudTh>
<MudTableSortLabel SortBy=@(new Func<ProductDetails, object>(p => p.Description))>
<MudTableSortLabel SortBy=@(new Func<ProductDetails, object>(p => p.Description!))>
Description
</MudTableSortLabel>
</MudTh>
<MudTh>
<MudTableSortLabel SortBy=@(new Func<ProductDetails, object>(p => p.Quantity))>
<MudTableSortLabel SortBy=@(new Func<ProductDetails, object>(p => p.Quantity!))>
Quantity
</MudTableSortLabel>
</MudTh>
<MudTh>
<MudTableSortLabel SortBy=@(new Func<ProductDetails, object>(p => p.UnitPrice))>
<MudTableSortLabel SortBy=@(new Func<ProductDetails, object>(p => p.UnitPrice!))>
Price
</MudTableSortLabel>
</MudTh>
Expand All @@ -37,7 +37,7 @@
<MudTd>
<MudFab Disabled=@(IsInCart?.Invoke(product) ?? false) Size=Size.Small
Color=Color.Primary StartIcon=@Icons.Material.Filled.AddShoppingCart
OnClick=@(async _ => await AddToCartAsync(product.Id))/>
OnClick="@(() => AddToCartAsync(product.Id!))"/>
</MudTd>
<MudTd DataLabel="Name">@product.Name</MudTd>
<MudTd DataLabel="Description">@product.Description</MudTd>
Expand Down Expand Up @@ -65,10 +65,13 @@
[Parameter, EditorRequired]
public Func<ProductDetails, bool> IsInCart { get; set; } = null!;

Task AddToCartAsync(string productId) =>
OnAddedToCart.HasDelegate
? OnAddedToCart.InvokeAsync(productId)
: Task.CompletedTask;
async Task AddToCartAsync(string productId)
{
if (OnAddedToCart is { HasDelegate: true } onAddedToCart)
{
await onAddedToCart.InvokeAsync(productId);
}
}

bool OnFilter(ProductDetails product) => product.MatchesFilter(_filter);
}
2 changes: 1 addition & 1 deletion Silo/Components/ShoppingCartSummary.razor
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<MudText Typo=Typo.subtitle1><b>@_totalCost</b></MudText>
</MudStack>
<MudButton Variant="Variant.Filled" Color="Color.Primary"
Disabled="@(Items?.Count() == 0 ? true : false)" DisableElevation
Disabled="@(Items?.Count() == 0 ? true : false)" DropShadow="false"
Size=@Size.Large>
Checkout
</MudButton>
Expand Down
6 changes: 3 additions & 3 deletions Silo/Extensions/ProductDetailsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Orleans.ShoppingCart.Silo.Extensions;

internal static class ProductDetailsExtensions
{
internal static Faker<ProductDetails> GetBogusFaker(this ProductDetails productDetails) =>
internal static readonly Faker<ProductDetails> ProductDetailsFaker =
new Faker<ProductDetails>()
.StrictMode(true)
.RuleFor(p => p.Id, (f, p) => f.Random.Number(1, 100_000).ToString())
Expand All @@ -26,8 +26,8 @@ internal static bool MatchesFilter(this ProductDetails product, string? filter)

if (product is not null)
{
return product.Name.Contains(filter, StringComparison.OrdinalIgnoreCase)
|| product.Description.Contains(filter, StringComparison.OrdinalIgnoreCase);
return (product.Name is { } name && name.Contains(filter, StringComparison.OrdinalIgnoreCase))
|| (product.Description is { } description && description.Contains(filter, StringComparison.OrdinalIgnoreCase));
}

return false;
Expand Down
3 changes: 0 additions & 3 deletions Silo/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
global using MudBlazor;
global using MudBlazor.Services;
global using Orleans.Configuration;
global using Orleans.Hosting;
global using Orleans.Runtime;
global using Orleans.ShoppingCart.Abstractions;
global using Orleans.ShoppingCart.Silo;
global using Orleans.ShoppingCart.Silo.Extensions;
global using Orleans.ShoppingCart.Silo.Services;
global using Orleans.ShoppingCart.Silo.StartupTasks;
Expand Down
16 changes: 8 additions & 8 deletions Silo/Orleans.ShoppingCart.Silo.csproj
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<IsTransformWebConfigDisabled>false</IsTransformWebConfigDisabled>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.11.3" />
<PackageReference Include="Blazor.Serialization" Version="2.0.11" />
<PackageReference Include="Blazor.LocalStorage" Version="2.0.11" />
<PackageReference Include="Azure.Identity" Version="1.12.1" />
<PackageReference Include="Blazor.Serialization" Version="8.0.0" />
<PackageReference Include="Blazor.LocalStorage" Version="8.0.0" />
<PackageReference Include="Bogus" Version="34.0.2" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.22.0" />
<PackageReference Include="Microsoft.Orleans.Clustering.AzureStorage" Version="7.0.0" />
<PackageReference Include="Microsoft.Orleans.Persistence.AzureStorage" Version="7.0.0" />
<PackageReference Include="Microsoft.Orleans.Server" Version="7.0.0" />
<PackageReference Include="Microsoft.Orleans.Clustering.AzureStorage" Version="8.2.0" />
<PackageReference Include="Microsoft.Orleans.Persistence.AzureStorage" Version="8.2.0" />
<PackageReference Include="Microsoft.Orleans.Server" Version="8.2.0" />

<PackageReference Include="MudBlazor" Version="6.2.0" />
<PackageReference Include="MudBlazor" Version="7.8.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Silo/Pages/Cart.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@page "/cart"

<MudToolBar DisableGutters="true">
<MudToolBar Gutters="false">
<MudText Typo="Typo.h4">Shopping Cart</MudText>
<MudSpacer />
<MudButton Variant="Variant.Outlined" StartIcon=@Icons.Material.Filled.RemoveShoppingCart
Expand Down
2 changes: 1 addition & 1 deletion Silo/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<MudContainer MaxWidth="MaxWidth.Medium" Class="mt-16">
<MudText Typo=Typo.h4 Class="pb-4">Welcome to the Orleans Shopping Cart</MudText>
<MudList>
<MudList T="string">
<MudListItem>
Use the <strong>Shop Inventory</strong> link to add items to your cart.
</MudListItem>
Expand Down
2 changes: 1 addition & 1 deletion Silo/Pages/Products.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<ProductTable Title="Product Management" Products=@_products EditProduct=@OnEditProduct>
<MudButton Variant="Variant.Filled" StartIcon="@Icons.Material.Filled.Add"
Color="Color.Primary" Size="Size.Large" DisableElevation="true" OnClick=@CreateNewProduct>
Color="Color.Primary" Size="Size.Large" DropShadow="false" OnClick=@CreateNewProduct>
Create New Product
</MudButton>
<MudDivider Vertical="true" FlexItem="true" Class="my-3 mx-4"/>
Expand Down
2 changes: 1 addition & 1 deletion Silo/Pages/Products.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private void CreateNewProduct()

private async Task OnProductUpdated(ProductDetails product)
{
var fake = faker.Generate();
var fake = ProductDetailsExtensions.ProductDetailsFaker.Generate();
product = product with
{
Id = fake.Id,
Expand Down
1 change: 1 addition & 0 deletions Silo/Pages/_Host.cshtml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@page "/"
@namespace Orleans.ShoppingCart.Pages
@using Orleans.ShoppingCart.Silo
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@{
Layout = null;
Expand Down
Loading

0 comments on commit 59c19c3

Please sign in to comment.