2013-05-05 21:24:33 +00:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
using Microsoft.AspNet.SignalR;
|
2013-05-06 00:33:43 +00:00
|
|
|
using Microsoft.AspNet.SignalR.Infrastructure;
|
2013-05-05 21:24:33 +00:00
|
|
|
using NLog;
|
2013-08-31 01:42:30 +00:00
|
|
|
using NzbDrone.Common.Instrumentation;
|
2013-05-05 21:24:33 +00:00
|
|
|
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-06 00:33:43 +00:00
|
|
|
|
2013-05-05 21:24:33 +00:00
|
|
|
public BasicResourceConnection()
|
|
|
|
{
|
2013-08-31 01:42:30 +00:00
|
|
|
_logger = NzbDroneLogger.GetLogger(this);
|
2013-05-05 21:24:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override Task OnConnected(IRequest request, string connectionId)
|
|
|
|
{
|
2013-05-11 05:59:42 +00:00
|
|
|
_logger.Trace("SignalR client connected. ID:{0}", connectionId);
|
2013-05-05 21:24:33 +00:00
|
|
|
return base.OnConnected(request, connectionId);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void HandleAsync(ModelEvent<T> message)
|
|
|
|
{
|
2013-05-11 05:59:42 +00:00
|
|
|
var context = ((ConnectionManager)GlobalHost.ConnectionManager).GetConnection(GetType());
|
2013-05-06 00:33:43 +00:00
|
|
|
context.Connection.Broadcast(message);
|
2013-05-05 21:24:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|