Files
ShrinkCommand.Integration.N…/ShrinkNetworkCommandBridgeExtensions.cs
cneicy f9b05b4178
Publish UPM package / publish (push) Failing after 1s
chore: initialize standalone UPM package
2026-08-26 02:49:49 +08:00

53 lines
1.9 KiB
C#

#nullable enable
using System;
using Cysharp.Threading.Tasks;
using ShrinkNetwork;
namespace ShrinkCommand.Integration
{
public static class ShrinkNetworkCommandBridgeExtensions
{
public static ShrinkNetworkService UseCommandBridge(
this ShrinkNetworkService networkService,
ShrinkCommandService commandService,
ShrinkNetworkCommandBridgeOptions? options = null)
{
if (networkService == null)
throw new ArgumentNullException(nameof(networkService));
if (commandService == null)
throw new ArgumentNullException(nameof(commandService));
ShrinkNetworkCommandBridge.RegisterService(networkService, commandService, options);
return networkService;
}
public static async UniTask<ShrinkNetworkCommandResponse> ExecuteCommandAsync(
this ShrinkNetworkSession session,
string commandLine,
string? serviceName = null,
string? clientLabel = null,
ShrinkRpcCallOptions? options = null)
{
if (session == null)
throw new ArgumentNullException(nameof(session));
ShrinkNetworkCommandBridge.EnsureMessagesRegistered(session.Service);
return await session.RpcAsync<ShrinkNetworkCommandRequest, ShrinkNetworkCommandResponse>(
new ShrinkNetworkCommandRequest
{
ServiceName = string.IsNullOrWhiteSpace(serviceName)
? ShrinkCommandConstants.DefaultServiceName
: serviceName.Trim(),
CommandLine = commandLine ?? string.Empty,
ClientLabel = clientLabel ?? string.Empty
},
options ?? new ShrinkRpcCallOptions
{
TimeoutMs = 5000,
DebugLabel = "RemoteCommand"
});
}
}
}