2013-08-31 03:08:19 +00:00
|
|
|
|
using System;
|
|
|
|
|
using Microsoft.AspNet.SignalR;
|
|
|
|
|
using Microsoft.AspNet.SignalR.Infrastructure;
|
|
|
|
|
using NzbDrone.Api.SignalR;
|
|
|
|
|
using NzbDrone.Common.Messaging;
|
|
|
|
|
using NzbDrone.Common.Messaging.Events;
|
|
|
|
|
using NzbDrone.Common.Messaging.Tracking;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Api.Commands
|
|
|
|
|
{
|
|
|
|
|
public class CommandConnection : NzbDronePersistentConnection,
|
|
|
|
|
IHandleAsync<CommandStartedEvent>,
|
|
|
|
|
IHandleAsync<CommandCompletedEvent>,
|
2013-09-02 02:55:45 +00:00
|
|
|
|
IHandleAsync<CommandFailedEvent>
|
2013-08-31 03:08:19 +00:00
|
|
|
|
{
|
|
|
|
|
public override string Resource
|
|
|
|
|
{
|
|
|
|
|
get { return "/Command"; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void HandleAsync(CommandStartedEvent message)
|
|
|
|
|
{
|
2013-08-31 03:39:05 +00:00
|
|
|
|
BroadcastMessage(message.TrackedCommand);
|
2013-08-31 03:08:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void HandleAsync(CommandCompletedEvent message)
|
|
|
|
|
{
|
2013-08-31 03:39:05 +00:00
|
|
|
|
BroadcastMessage(message.TrackedCommand);
|
2013-08-31 03:08:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-02 02:55:45 +00:00
|
|
|
|
public void HandleAsync(CommandFailedEvent message)
|
2013-08-31 03:08:19 +00:00
|
|
|
|
{
|
2013-08-31 03:39:05 +00:00
|
|
|
|
BroadcastMessage(message.TrackedCommand);
|
2013-08-31 03:08:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void BroadcastMessage(TrackedCommand trackedCommand)
|
|
|
|
|
{
|
|
|
|
|
var context = ((ConnectionManager)GlobalHost.ConnectionManager).GetConnection(GetType());
|
|
|
|
|
context.Connection.Broadcast(trackedCommand);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|