using MxGateway.Client; using MxGateway.Contracts.Proto; using MxGateway.Contracts.Proto.Galaxy; namespace MxGateway.Client.Cli; internal sealed class MxGatewayCliClientAdapter : IMxGatewayCliClient { private readonly MxGatewayClient _client; private readonly Lazy _galaxyClient; /// /// Initializes a new instance of the that bridges the CLI to the gateway client. /// /// The gateway client to adapt. public MxGatewayCliClientAdapter(MxGatewayClient client) { _client = client; _galaxyClient = new Lazy( () => GalaxyRepositoryClient.Create(_client.Options)); } /// public Task OpenSessionAsync( OpenSessionRequest request, CancellationToken cancellationToken) { return _client.OpenSessionRawAsync(request, cancellationToken); } /// public Task CloseSessionAsync( CloseSessionRequest request, CancellationToken cancellationToken) { return _client.CloseSessionRawAsync(request, cancellationToken); } /// public Task InvokeAsync( MxCommandRequest request, CancellationToken cancellationToken) { return _client.InvokeAsync(request, cancellationToken); } /// public IAsyncEnumerable StreamEventsAsync( StreamEventsRequest request, CancellationToken cancellationToken) { return _client.StreamEventsAsync(request, cancellationToken); } /// public Task AcknowledgeAlarmAsync( AcknowledgeAlarmRequest request, CancellationToken cancellationToken) { return _client.AcknowledgeAlarmAsync(request, cancellationToken); } /// public IAsyncEnumerable StreamAlarmsAsync( StreamAlarmsRequest request, CancellationToken cancellationToken) { return _client.StreamAlarmsAsync(request, cancellationToken); } /// public Task GalaxyTestConnectionAsync( TestConnectionRequest request, CancellationToken cancellationToken) { return _galaxyClient.Value.TestConnectionRawAsync(request, cancellationToken); } /// public Task GalaxyGetLastDeployTimeAsync( GetLastDeployTimeRequest request, CancellationToken cancellationToken) { return _galaxyClient.Value.GetLastDeployTimeRawAsync(request, cancellationToken); } /// public Task GalaxyDiscoverHierarchyAsync( DiscoverHierarchyRequest request, CancellationToken cancellationToken) { return _galaxyClient.Value.DiscoverHierarchyRawAsync(request, cancellationToken); } /// public IAsyncEnumerable GalaxyWatchDeployEventsAsync( WatchDeployEventsRequest request, CancellationToken cancellationToken) { return _galaxyClient.Value.WatchDeployEventsRawAsync(request, cancellationToken); } /// public async ValueTask DisposeAsync() { if (_galaxyClient.IsValueCreated) { await _galaxyClient.Value.DisposeAsync().ConfigureAwait(false); } await _client.DisposeAsync().ConfigureAwait(false); } }