-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
72 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using MadWorldNL.MantaRayPlan.Events; | ||
using MadWorldNL.MantaRayPlan.Web.Configurations; | ||
using Microsoft.AspNetCore.SignalR.Client; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace MadWorldNL.MantaRayPlan.Web.Services.Events; | ||
|
||
public class EventsService : IAsyncDisposable | ||
{ | ||
private bool _isStarted; | ||
private readonly HubConnection _hubConnection; | ||
|
||
public event Action<MessageBusStatusEvent>? EventReceived; | ||
|
||
public EventsService(IOptions<ApiSettings> settings) | ||
{ | ||
_hubConnection = new HubConnectionBuilder() | ||
.WithUrl($"{settings.Value.Address}Events") | ||
.Build(); | ||
|
||
_hubConnection.On<MessageBusStatusEvent>("NewEvent", (@event) => | ||
{ | ||
EventReceived?.Invoke(@event); | ||
}); | ||
} | ||
|
||
public Task StartAsync() | ||
{ | ||
if (_isStarted) | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
|
||
_isStarted = true; | ||
return _hubConnection.StartAsync(); | ||
} | ||
|
||
public async ValueTask DisposeAsync() | ||
{ | ||
await _hubConnection.StopAsync(); | ||
await _hubConnection.DisposeAsync(); | ||
|
||
GC.SuppressFinalize(this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters