You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Connected.Framework/Connected.Notifications/Events/Server/EventServerConnection.cs

37 lines
944 B

using Connected.Net.Hubs;
using Connected.Net.Messaging;
using Connected.Net.Server;
using Microsoft.AspNetCore.SignalR.Client;
using Microsoft.Extensions.Logging;
namespace Connected.Notifications.Events.Server;
internal class EventServerConnection : ServerConnection
{
public event EventHandler<EventNotificationArgs>? Received;
public EventServerConnection(IEndpointServer server, ILogger<EventServerConnection> logger) : base(server)
{
Logger = logger;
}
private ILogger<EventServerConnection> Logger { get; }
public override async Task Initialize(string hubUrl)
{
await base.Initialize(hubUrl);
Connection.On<MessageAcknowledgeArgs, EventNotificationArgs>("Notify", (a, e) =>
{
Connection.InvokeAsync(nameof(EventHub.Acknowledge), a);
Received?.Invoke(this, e);
});
Connection.On<ServerExceptionArgs>("Exception", (e) =>
{
Logger.LogError("Caching hub exception: {message}", e.Message);
});
}
}