1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-11-01 00:12:30 +01:00
Sonarr/NzbDrone.Api/SignalR/BasicResourceConnection.cs

36 lines
1.0 KiB
C#
Raw Normal View History

2013-05-05 23:24:33 +02:00
using System.Threading.Tasks;
using Microsoft.AspNet.SignalR;
using Microsoft.AspNet.SignalR.Infrastructure;
2013-05-05 23:24:33 +02:00
using NLog;
using NzbDrone.Common.Messaging;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Datastore.Events;
namespace NzbDrone.Api.SignalR
{
public abstract class BasicResourceConnection<T> :
NzbDronePersistentConnection,
IHandleAsync<ModelEvent<T>>
where T : ModelBase
{
private readonly Logger _logger;
2013-05-05 23:24:33 +02:00
public BasicResourceConnection()
{
_logger = LogManager.GetCurrentClassLogger();
}
protected override Task OnConnected(IRequest request, string connectionId)
{
2013-05-11 07:59:42 +02:00
_logger.Trace("SignalR client connected. ID:{0}", connectionId);
2013-05-05 23:24:33 +02:00
return base.OnConnected(request, connectionId);
}
public void HandleAsync(ModelEvent<T> message)
{
2013-05-11 07:59:42 +02:00
var context = ((ConnectionManager)GlobalHost.ConnectionManager).GetConnection(GetType());
context.Connection.Broadcast(message);
2013-05-05 23:24:33 +02:00
}
}
}