advanced userinterface design

This commit is contained in:
Nitload
2026-04-01 22:20:49 +08:00
parent 24498c2717
commit aa7ece4ed0
42 changed files with 2876 additions and 463 deletions
@@ -0,0 +1,63 @@
using System;
using System.Threading;
using System.Threading.Tasks;
namespace StgSharp.UserInterface
{
public abstract class StateHost
{
protected StateHost(
FrontCommandHost frontCommandHost,
AppState appState,
ServiceManager serviceManager
)
{
FrontCommandHost = frontCommandHost ??
throw new ArgumentNullException(nameof(frontCommandHost));
AppState = appState ?? throw new ArgumentNullException(nameof(appState));
ServiceManager = serviceManager ??
throw new ArgumentNullException(nameof(serviceManager));
FrontCommandHost.Attach(this);
ServiceManager.Attach(this);
}
public AppState AppState { get; }
public FrontCommandHost FrontCommandHost { get; }
public ServiceManager ServiceManager { get; }
public virtual async Task<CommandResult> PostAsync(
ViewHost source,
StateChangeCommand command,
CancellationToken cancellationToken = default
)
{
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(command);
CommandResult result = await FrontCommandHost.AcceptAsync(source, command, cancellationToken)
.ConfigureAwait(false);
await source.ReceiveCommandResultAsync(result, cancellationToken).ConfigureAwait(false);
return result;
}
public virtual async Task<CommandResult> PostAsync(
ViewHost source,
ExecuteCommand command,
CancellationToken cancellationToken = default
)
{
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(command);
CommandResult result = await FrontCommandHost.AcceptAsync(source, command, cancellationToken)
.ConfigureAwait(false);
await source.ReceiveCommandResultAsync(result, cancellationToken).ConfigureAwait(false);
return result;
}
}
}