Skip to content

Commit 3684c96

Browse files
author
Rafał Maciąg
committed
string identifiers
1 parent 1438a82 commit 3684c96

30 files changed

+343
-172
lines changed

src/MicroPlumberd.CommandBus.Abstractions/ICommandBus.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public interface ICommandBus
1010
/// </summary>
1111
/// <param name="recipientId">The ID of the recipient.</param>
1212
/// <param name="command">The command to send.</param>
13+
/// <param name="token"></param>
1314
/// <returns>A task representing the asynchronous operation.</returns>
14-
Task SendAsync(object recipientId, object command);
15+
Task SendAsync(object recipientId, object command, CancellationToken token = default);
1516
}

src/MicroPlumberd.Examples.Cinema/Components/App.razor

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
<meta charset="utf-8" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
77
<base href="/" />
8-
<link rel="stylesheet" href="bootstrap/bootstrap.min.css" />
8+
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" rel="stylesheet" />
9+
<link href="_content/MudBlazor/MudBlazor.min.css" rel="stylesheet" />
910
<link rel="stylesheet" href="app.css" />
1011
<link rel="stylesheet" href="MicroPlumberd.Examples.Cinema.styles.css" />
1112
<link rel="icon" type="image/png" href="favicon.png" />
@@ -15,6 +16,7 @@
1516
<body>
1617
<Routes @rendermode="InteractiveServer" />
1718
<script src="_framework/blazor.web.js"></script>
19+
<script src="_content/MudBlazor/MudBlazor.min.js"></script>
1820
</body>
1921

2022
</html>
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
@inherits LayoutComponentBase
2+
<MudThemeProvider IsDarkMode="true"/>
3+
<MudDialogProvider/>
4+
<MudSnackbarProvider/>
25

3-
<div class="page">
4-
<div class="sidebar">
5-
<NavMenu />
6-
</div>
6+
<MudLayout>
7+
<MudAppBar>
8+
<MudIconButton Icon="@Icons.Material.Filled.Menu" Color="Color.Inherit" Edge="Edge.Start" OnClick="@((e) => DrawerToggle())" />
9+
My Application
10+
</MudAppBar>
11+
<MudDrawer @bind-Open="@_drawerOpen">
12+
<NavMenu/>
13+
</MudDrawer>
14+
<MudMainContent>
15+
@Body
16+
</MudMainContent>
17+
</MudLayout>
18+
@code {
19+
bool _drawerOpen = true;
720

8-
<main>
9-
<div class="top-row px-4">
10-
<a href="https://learn.microsoft.com/aspnet/core/" target="_blank">About</a>
11-
</div>
12-
13-
<article class="content px-4">
14-
@Body
15-
</article>
16-
</main>
17-
</div>
18-
19-
<div id="blazor-error-ui">
20-
An unhandled error has occurred.
21-
<a href="" class="reload">Reload</a>
22-
<a class="dismiss">🗙</a>
23-
</div>
21+
void DrawerToggle()
22+
{
23+
_drawerOpen = !_drawerOpen;
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,5 @@
1-
<div class="top-row ps-3 navbar navbar-dark">
2-
<div class="container-fluid">
3-
<a class="navbar-brand" href="">Micro-Cinema</a>
4-
</div>
5-
</div>
6-
7-
<input type="checkbox" title="Navigation menu" class="navbar-toggler" />
8-
9-
<div class="nav-scrollable" onclick="document.querySelector('.navbar-toggler').click()">
10-
<nav class="flex-column">
11-
<div class="nav-item px-3">
12-
<NavLink class="nav-link" href="" Match="NavLinkMatch.All">
13-
<span class="bi bi-house-door-fill-nav-menu" aria-hidden="true"></span> Home
14-
</NavLink>
15-
</div>
16-
17-
<div class="nav-item px-3">
18-
<NavLink class="nav-link" href="scheduler">
19-
<span class="bi bi-plus-square-fill-nav-menu" aria-hidden="true"></span> Schedule Manager
20-
</NavLink>
21-
</div>
22-
23-
24-
</nav>
25-
</div>
26-
1+
<MudNavMenu>
2+
<MudNavLink Href="/" Match="NavLinkMatch.All">Dashboard</MudNavLink>
3+
<MudNavLink Href="/scheduler" Match="NavLinkMatch.Prefix">Scheduler</MudNavLink>
4+
5+
</MudNavMenu>

src/MicroPlumberd.Examples.Cinema/Components/_Imports.razor

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
@using Microsoft.JSInterop
99
@using MicroPlumberd.Examples.Cinema
1010
@using MicroPlumberd.Examples.Cinema.Components
11+
@using MudBlazor
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Web">
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
44
<TargetFramework>net8.0</TargetFramework>
@@ -7,9 +7,10 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="MicroPlumberd" Version="1.0.51.109" />
11-
<PackageReference Include="MicroPlumberd.Services" Version="1.0.51.109" />
12-
<PackageReference Include="MicroPlumberd.SourceGenerators" Version="1.0.51.109" />
10+
<ProjectReference Include="..\MicroPlumberd.Services\MicroPlumberd.Services.csproj" />
11+
<ProjectReference Include="..\MicroPlumberd.SourceGenerators\MicroPlumberd.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
12+
<ProjectReference Include="..\MicroPlumberd\MicroPlumberd.csproj" />
13+
<PackageReference Include="MudBlazor" Version="6.19.1" />
1314
</ItemGroup>
1415

1516
</Project>

src/MicroPlumberd.Examples.Cinema/Program.cs

+3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
using MicroPlumberd.Examples.Cinema.Components;
22
using MicroPlumberd.Services;
3+
using MudBlazor.Services;
34

45
namespace MicroPlumberd.Examples.Cinema
56
{
67
public class Program
78
{
89
public static void Main(string[] args)
910
{
11+
1012
var builder = WebApplication.CreateBuilder(args);
1113

1214
// Add services to the container.
1315
builder.Services.AddRazorComponents()
1416
.AddInteractiveServerComponents();
1517
builder.Services.AddPlumberd();
18+
builder.Services.AddMudServices();
1619

1720
var app = builder.Build();
1821

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
@using MicroPlumberd.Examples.Cinema.Utils
2+
@using MudBlazor
3+
<MudDialog>
4+
<DialogContent>
5+
6+
<MudForm>
7+
@* <MudTextField Label="Movie" @bind-Value="_cmd.Movie" Converter="OptionConverters.String"/> *@
8+
</MudForm>
9+
10+
</DialogContent>
11+
<DialogActions>
12+
<MudButton Color="Color.Primary" OnClick="Close">Ok</MudButton>
13+
</DialogActions>
14+
</MudDialog>
15+
16+
@code
17+
{
18+
private CreateScreening _cmd = new CreateScreening();
19+
20+
public void Close()
21+
{
22+
23+
}
24+
}

src/MicroPlumberd.Examples.Cinema/Scheduler/ScheduleCommandHandler.cs

+26-21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
using System.ComponentModel.DataAnnotations;
22
using System.Drawing;
3+
using System.Reflection;
4+
using System.Text.Json;
5+
using System.Text.Json.Serialization;
36
using MicroPlumberd.Services;
47

58
namespace MicroPlumberd.Examples.Cinema.Scheduler
@@ -8,14 +11,15 @@ namespace MicroPlumberd.Examples.Cinema.Scheduler
811
public partial class ScheduleCommandHandler(IPlumber plumber)
912
{
1013
[ThrowsFaultException<ScreeningTimeCannotBeInPast>]
11-
public async Task Handle(Guid id, DefineScreening cmd)
14+
public async Task Handle(Guid id, PathScreening cmd)
1215
{
1316
if (cmd.Date.IsDefined && cmd.Time.IsDefined)
14-
if (cmd.Date.Value.ToDateTime(cmd.Time.Value) < DateTime.Now)
15-
throw new FaultException<ScreeningTimeCannotBeInPast>(new ScreeningTimeCannotBeInPast());
17+
if (cmd.Date.Value.ToDateTime(cmd.Time.Value) < DateTime.Now)
18+
throw new FaultException<ScreeningTimeCannotBeInPast>(new ScreeningTimeCannotBeInPast());
1619

17-
18-
ScreeningStateDefined state = await plumber.GetState<ScreeningStateDefined>(id);
20+
21+
ScreeningStateDefined state = await plumber.GetState<ScreeningStateDefined>(id) ?? throw new Exception();
22+
1923
if (cmd.SeatConfiguration.IsDefined)
2024
{
2125
SeatRoomConfiguration conf = cmd.SeatConfiguration;
@@ -36,7 +40,7 @@ public async Task Handle(Guid id, DefineScreening cmd)
3640
if (cmd.Date.IsDefined)
3741
state.When = cmd.Date.Value.ToDateTime(TimeOnly.MinValue).Add(state.When.TimeOfDay);
3842

39-
//await plumber.AppendState(state);
43+
await plumber.AppendState(state);
4044
}
4145
}
4246

@@ -47,28 +51,29 @@ public class ScreeningTimeCannotBeInPast
4751
}
4852

4953
public readonly record struct SeatLocation(ushort Row, ushort Seat);
50-
51-
public readonly record struct Property<T>
52-
{
53-
public T Value { get; init; }
54-
public static implicit operator T(Property<T> value) => value.Value;
55-
public static implicit operator Property<T>(T value) => new Property<T>() { Value = value, IsDefined = true};
56-
57-
public bool IsDefined { get; init; }
58-
}
54+
5955
public record SeatRoomConfiguration
6056
{
6157
public int SeatCount { get; init; }
6258
public int RowCount { get; init; }
6359
public SeatLocation[] EmptySpaces { get; init; }
6460
}
65-
public record DefineScreening
61+
62+
public record PathScreening
63+
{
64+
public Option<SeatRoomConfiguration> SeatConfiguration { get; set; }
65+
public Option<string> Movie { get; set; }
66+
public Option<string> Room { get; set; }
67+
public Option<TimeOnly> Time { get; set; }
68+
public Option<DateOnly> Date { get; set; }
69+
}
70+
public record CreateScreening
6671
{
67-
public Property<SeatRoomConfiguration> SeatConfiguration { get; init; }
68-
public Property<string> Movie { get; init; }
69-
public Property<string> Room { get; init; }
70-
public Property<TimeOnly> Time { get; init; }
71-
public Property<DateOnly> Date { get; init; }
72+
public SeatRoomConfiguration SeatConfiguration { get; set; }
73+
public string Movie { get; set; }
74+
public string Room { get; set; }
75+
public TimeOnly Time { get; set; }
76+
public DateOnly Date { get; set; }
7277

7378
}
7479

Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
@page "/scheduler"
2+
@using MudBlazor
3+
@inject IDialogService DialogService
24

3-
<PageTitle>Counter</PageTitle>
5+
<PageTitle>Scheduler</PageTitle>
46

5-
<h1>Counter</h1>
67

7-
<p role="status">Current count: @currentCount</p>
8-
9-
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
8+
<MudButton OnClick="OpenDialog" Variant="Variant.Filled" Color="Color.Primary">
9+
Add screening
10+
</MudButton>
1011

1112
@code {
12-
private int currentCount = 0;
13-
14-
private void IncrementCount()
13+
private void OpenDialog()
1514
{
16-
currentCount++;
15+
DialogService.Show<AddScreeningDialog>("Add Screening");
1716
}
1817
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using MudBlazor;
2+
3+
namespace MicroPlumberd.Examples.Cinema.Utils
4+
{
5+
public class OptionConverters
6+
{
7+
public static MudBlazor.Converter<Option<string>, string> String =
8+
new MudBlazor.Converter<Option<string>, string>() { GetFunc = x => x, SetFunc = x => x.Value };
9+
}
10+
}

src/MicroPlumberd.Examples.Cinema/wwwroot/app.css

-51
This file was deleted.

src/MicroPlumberd.Examples.Cinema/wwwroot/bootstrap/bootstrap.min.css

-7
This file was deleted.

src/MicroPlumberd.Examples.Cinema/wwwroot/bootstrap/bootstrap.min.css.map

-1
This file was deleted.

0 commit comments

Comments
 (0)