2013-05-04 21:09:25 +00:00
|
|
|
using System.Collections.Generic;
|
2013-05-05 21:24:33 +00:00
|
|
|
using Microsoft.AspNet.SignalR;
|
|
|
|
using NzbDrone.Api.SignalR;
|
2013-05-04 21:09:25 +00:00
|
|
|
using Owin;
|
2013-05-05 21:24:33 +00:00
|
|
|
using TinyIoC;
|
2013-05-04 21:09:25 +00:00
|
|
|
|
|
|
|
namespace NzbDrone.Owin.MiddleWare
|
|
|
|
{
|
|
|
|
public class SignalRMiddleWare : IOwinMiddleWare
|
|
|
|
{
|
2013-05-05 21:24:33 +00:00
|
|
|
private readonly IEnumerable<NzbDronePersistentConnection> _persistentConnections;
|
2013-05-04 21:09:25 +00:00
|
|
|
|
2013-05-05 21:24:33 +00:00
|
|
|
public int Order { get { return 0; } }
|
|
|
|
|
|
|
|
public SignalRMiddleWare(IEnumerable<NzbDronePersistentConnection> persistentConnections, TinyIoCContainer container)
|
2013-05-04 21:09:25 +00:00
|
|
|
{
|
2013-05-05 21:24:33 +00:00
|
|
|
_persistentConnections = persistentConnections;
|
|
|
|
|
|
|
|
SignalrDependencyResolver.Register(container);
|
2013-05-04 21:09:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Attach(IAppBuilder appBuilder)
|
|
|
|
{
|
2013-05-05 21:24:33 +00:00
|
|
|
foreach (var nzbDronePersistentConnection in _persistentConnections)
|
|
|
|
{
|
2013-05-06 00:33:43 +00:00
|
|
|
var url = string.Format("signalr/{0}", nzbDronePersistentConnection.Resource.Trim('/'));
|
|
|
|
appBuilder.MapConnection(url, nzbDronePersistentConnection.GetType(), new ConnectionConfiguration { EnableCrossDomain = true });
|
2013-05-05 21:24:33 +00:00
|
|
|
}
|
|
|
|
|
2013-05-04 21:09:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|