Commands return immediately and signalr is used to control the UI

This commit is contained in:
Mark McDowall 2013-08-30 20:08:19 -07:00
commit c96ba5efd3
55 changed files with 439 additions and 238 deletions

View file

@ -0,0 +1,42 @@
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>,
IHandle<CommandFailedEvent>
{
public override string Resource
{
get { return "/Command"; }
}
public void HandleAsync(CommandStartedEvent message)
{
BroadcastMessage(message.Command);
}
public void HandleAsync(CommandCompletedEvent message)
{
BroadcastMessage(message.Command);
}
public void Handle(CommandFailedEvent message)
{
BroadcastMessage(message.Command);
}
private void BroadcastMessage(TrackedCommand trackedCommand)
{
var context = ((ConnectionManager)GlobalHost.ConnectionManager).GetConnection(GetType());
context.Connection.Broadcast(trackedCommand);
}
}
}