Skip to content

Commit

Permalink
Add workspace control buttons and align text style
Browse files Browse the repository at this point in the history
New Pause, Resume, and Step buttons have been added to the Wolder Interactive Web project for workspace control. The text in the 'main' selector of MainLayout.razor.css was aligned to the center. Workflow event handling improvements were also made in the Web and Core projects.
  • Loading branch information
rebelzach committed Mar 2, 2024
1 parent fb19c3c commit 2989afd
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public WorkspaceStateEventDispatcher()
WorkspaceInitializedAsync = async () =>
await Task.WhenAll(Delegates.Select(d =>
d.WorkspaceInitializedAsync())),
WorkspaceRunEndAsync = async () =>
await Task.WhenAll(Delegates.Select(d =>
d.WorkspaceRunEndAsync())),
InvocationBeginAsync = async (c) =>
await Task.WhenAll(Delegates.Select(d =>
d.InvocationBeginAsync(c))),
Expand Down
1 change: 1 addition & 0 deletions src/Wolder.Core/Workspace/Events/WorkspaceStateEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
public class WorkspaceStateEvents
{
public Func<Task> WorkspaceInitializedAsync { get; set; } = () => Task.CompletedTask;
public Func<Task> WorkspaceRunEndAsync { get; set; } = () => Task.CompletedTask;
public Func<InvocationBeginContext, Task> InvocationBeginAsync { get; set; } = (c) => Task.CompletedTask;
public Func<InvocationEndContext, Task> InvocationEndAsync { get; set; } = (c) => Task.CompletedTask;
}
1 change: 1 addition & 0 deletions src/Wolder.Core/Workspace/GeneratorWorkspaceBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ public async Task BuildWorkspaceAndRunAsync<TRootAction>(string rootPath)
await EventDispatcher.Events.WorkspaceInitializedAsync();
var invokeRootAction = serviceProvider.GetRequiredService<IInvoke>();
await invokeRootAction.InvokeVoidAsync<TRootAction>();
await EventDispatcher.Events.WorkspaceRunEndAsync();
}
}
12 changes: 12 additions & 0 deletions src/Wolder.Interactive.Web/Components/Index.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
@page "/"
@using Wolder.Interactive.Web.Services

@inject WorkspaceStateManager WorkspaceStateManager;

@rendermode InteractiveServer

<h3>Wolder Interactive</h3>

<div>
<button @onclick="WorkspaceStateManager.Pause">Pause</button>
<button @onclick="WorkspaceStateManager.Resume">Resume</button>
<button @onclick="WorkspaceStateManager.Step">Step</button>
</div>

@code {

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

main {
font-family: monospace;
text-align: center;
}
7 changes: 7 additions & 0 deletions src/Wolder.Interactive.Web/Services/WorkspaceStateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public WorkspaceStateManager()
Events = new()
{
WorkspaceInitializedAsync = WorkspaceInitializedAsync,
WorkspaceRunEndAsync = WorkspaceRunEndAsync,
InvocationBeginAsync = InvocationBeginAsync,
InvocationEndAsync = InvocationEndAsync,
};
Expand Down Expand Up @@ -50,6 +51,12 @@ private async Task InvocationBeginAsync(InvocationBeginContext c)
InvocationBegin?.Invoke(new InvocationDetail(c.Invokable.GetType().Name));
await _proceedWhenUnpaused.Task;
}

private async Task WorkspaceRunEndAsync()
{
Pause();
await _proceedWhenUnpaused.Task;
}

private Task InvocationEndAsync(InvocationEndContext c)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Wolder.Interactive.Web/SetupExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static GeneratorWorkspaceBuilder AddInteractiveWebServer(this GeneratorWo
{
var server = new WorkspaceInteractiveWebHost();
builder.Services.AddSingleton(server);
builder.EventDispatcher.Delegates.Add(server.WorkspaceStateNotifications.Events);
builder.EventDispatcher.Delegates.Add(server.WorkspaceStateManager.Events);
return builder;
}
}
6 changes: 4 additions & 2 deletions src/Wolder.Interactive.Web/WorkspaceInteractiveWebHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ public class WorkspaceInteractiveWebHost

public WorkspaceInteractiveWebHost()
{
WorkspaceStateNotifications.WorkspaceInitialized += () =>
WorkspaceStateManager.WorkspaceInitialized += () =>
{
_serverInitializeTask = StartAsync();
};
}

public WorkspaceStateManager WorkspaceStateNotifications { get; } = new();
public WorkspaceStateManager WorkspaceStateManager { get; } = new();

private async Task StartAsync()
{
Expand All @@ -32,6 +32,8 @@ private async Task StartAsync()
ApplicationName = "Wolder.Interactive.Web"
});

webBuilder.Services.AddSingleton(WorkspaceStateManager);

// Add services to the container.
webBuilder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
Expand Down

0 comments on commit 2989afd

Please sign in to comment.