53 lines
1.9 KiB
C#
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"
|
|
});
|
|
}
|
|
}
|
|
}
|