Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions src/paradigm-ehb.CommandCenter.Core/Models/AgentClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace paradigm_ehb.CommandCenter.Core.Models
{
public sealed class AgentClient : IDisposable
public sealed class AgentClient : IDisposable, IAsyncDisposable
{
private bool disposedValue;
private AgentHealthWatcher? _healthWatcher;
Expand All @@ -16,19 +16,19 @@
/// <summary>
/// Gets or sets the network endpoint information for the agent connection.
/// </summary>
public AgentEndpoint Endpoint { get; set; }

Check warning on line 19 in src/paradigm-ehb.CommandCenter.Core/Models/AgentClient.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Endpoint' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

public GrpcChannel Channel { get; init; }

Check warning on line 21 in src/paradigm-ehb.CommandCenter.Core/Models/AgentClient.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Channel' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

public Health.HealthClient Health { get; init; }

Check warning on line 23 in src/paradigm-ehb.CommandCenter.Core/Models/AgentClient.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Health' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

public Greeter.GreeterClient Greeter { get; init; }

Check warning on line 25 in src/paradigm-ehb.CommandCenter.Core/Models/AgentClient.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Greeter' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

public JournalService.JournalServiceClient Journal { get; init; }

Check warning on line 27 in src/paradigm-ehb.CommandCenter.Core/Models/AgentClient.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Journal' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

public HandlerService.HandlerServiceClient Service { get; init; }

Check warning on line 29 in src/paradigm-ehb.CommandCenter.Core/Models/AgentClient.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Service' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

public ResourcesService.ResourcesServiceClient Resources { get; init; }

Check warning on line 31 in src/paradigm-ehb.CommandCenter.Core/Models/AgentClient.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Resources' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

public bool HealthWatchEnabled { get; set; } = true;

Expand Down Expand Up @@ -63,6 +63,7 @@
{
StopHealthWatch();
_healthWatcher?.Dispose();
Channel.ShutdownAsync().Wait();
Channel?.Dispose();
}
catch
Expand All @@ -77,7 +78,33 @@
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}

private async Task DisposeAsync(bool disposing)
{
if (!disposedValue)
{
if (disposing)
{
try
{
StopHealthWatch();
_healthWatcher?.Dispose();
await Channel.ShutdownAsync().ConfigureAwait(false);
Channel?.Dispose();
}
catch
{
// ignore
}
}
disposedValue = true;
}
}

public async ValueTask DisposeAsync()
{
await DisposeAsync(true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
_ = InitializeForNavigationAsync(e);
}

protected override async void OnNavigatedFrom(NavigationEventArgs e)
{
base.OnNavigatedFrom(e);

AgentClient? agentClient = await _agentClientRegistry.GetAsync(serverObj.Id);
if (agentClient is not null) await agentClient.DisposeAsync();
await _agentClientRegistry.DeregisterAsync(serverObj.Id);
}

private async Task InitializeForNavigationAsync(NavigationEventArgs e)
{
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,8 @@ private async Task LoadAllServices(CancellationToken cancellationToken = default
GetUnitsReply? response = await client.Service.GetAllUnitsAsync(request: new GetUnitsRequest(), cancellationToken: cancellationToken);
if (response is null)
{
throw new InvalidOperationException("Received null response from ActionAsync.");
await ShowErrorInfoBarAsync("Failed to retrieve services: received null response from agent.");
return;
}

foreach (LoadedUnit? unit in response.Units)
Expand Down
Loading