|
|
|
@ -1,7 +1,6 @@
|
|
|
|
|
using NzbDrone.Api.REST;
|
|
|
|
|
using NzbDrone.Core.Datastore;
|
|
|
|
|
using NzbDrone.Core.Datastore.Events;
|
|
|
|
|
using NzbDrone.Core.Messaging.Commands;
|
|
|
|
|
using NzbDrone.Core.Messaging.Events;
|
|
|
|
|
using NzbDrone.SignalR;
|
|
|
|
|
|
|
|
|
@ -11,17 +10,17 @@ namespace NzbDrone.Api
|
|
|
|
|
where TResource : RestResource, new()
|
|
|
|
|
where TModel : ModelBase
|
|
|
|
|
{
|
|
|
|
|
private readonly ICommandExecutor _commandExecutor;
|
|
|
|
|
private readonly IBroadcastSignalRMessage _signalRBroadcaster;
|
|
|
|
|
|
|
|
|
|
protected NzbDroneRestModuleWithSignalR(ICommandExecutor commandExecutor)
|
|
|
|
|
protected NzbDroneRestModuleWithSignalR(IBroadcastSignalRMessage signalRBroadcaster)
|
|
|
|
|
{
|
|
|
|
|
_commandExecutor = commandExecutor;
|
|
|
|
|
_signalRBroadcaster = signalRBroadcaster;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected NzbDroneRestModuleWithSignalR(ICommandExecutor commandExecutor, string resource)
|
|
|
|
|
protected NzbDroneRestModuleWithSignalR(IBroadcastSignalRMessage signalRBroadcaster, string resource)
|
|
|
|
|
: base(resource)
|
|
|
|
|
{
|
|
|
|
|
_commandExecutor = commandExecutor;
|
|
|
|
|
_signalRBroadcaster = signalRBroadcaster;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Handle(ModelEvent<TModel> message)
|
|
|
|
@ -34,30 +33,25 @@ namespace NzbDrone.Api
|
|
|
|
|
BroadcastResourceChange(message.Action, message.Model.Id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void BroadcastResourceChange(ModelAction action, TResource resource)
|
|
|
|
|
{
|
|
|
|
|
var signalRMessage = new SignalRMessage
|
|
|
|
|
{
|
|
|
|
|
Name = Resource,
|
|
|
|
|
Body = new ResourceChangeMessage<TResource>(resource, action)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
_commandExecutor.PublishCommand(new BroadcastSignalRMessage(signalRMessage));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void BroadcastResourceChange(ModelAction action, int id)
|
|
|
|
|
{
|
|
|
|
|
var resource = GetResourceById(id);
|
|
|
|
|
BroadcastResourceChange(action, resource);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void BroadcastResourceChange(ModelAction action, TResource resource)
|
|
|
|
|
{
|
|
|
|
|
var signalRMessage = new SignalRMessage
|
|
|
|
|
{
|
|
|
|
|
Name = Resource,
|
|
|
|
|
Body = new ResourceChangeMessage<TResource>(resource, action)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
_commandExecutor.PublishCommand(new BroadcastSignalRMessage(signalRMessage));
|
|
|
|
|
_signalRBroadcaster.BroadcastMessage(signalRMessage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void BroadcastResourceChange(ModelAction action)
|
|
|
|
|
{
|
|
|
|
|
var signalRMessage = new SignalRMessage
|
|
|
|
@ -66,7 +60,7 @@ namespace NzbDrone.Api
|
|
|
|
|
Body = new ResourceChangeMessage<TResource>(action)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
_commandExecutor.PublishCommand(new BroadcastSignalRMessage(signalRMessage));
|
|
|
|
|
_signalRBroadcaster.BroadcastMessage(signalRMessage);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|