Sonarr/NzbDrone/Owin/MiddleWare/SignalRMiddleWare.cs

32 lines
1.1 KiB
C#
Raw Normal View History

using System.Collections.Generic;
2013-05-05 21:24:33 +00:00
using Microsoft.AspNet.SignalR;
using NzbDrone.Api.SignalR;
2013-05-10 23:53:50 +00:00
using NzbDrone.Common.Composition;
using Owin;
namespace NzbDrone.Owin.MiddleWare
{
public class SignalRMiddleWare : IOwinMiddleWare
{
2013-05-05 21:24:33 +00:00
private readonly IEnumerable<NzbDronePersistentConnection> _persistentConnections;
2013-05-05 21:24:33 +00:00
public int Order { get { return 0; } }
2013-05-10 23:53:50 +00:00
public SignalRMiddleWare(IEnumerable<NzbDronePersistentConnection> persistentConnections, IContainer container)
{
2013-05-05 21:24:33 +00:00
_persistentConnections = persistentConnections;
SignalrDependencyResolver.Register(container);
}
public void Attach(IAppBuilder appBuilder)
{
2013-05-05 21:24:33 +00:00
foreach (var nzbDronePersistentConnection in _persistentConnections)
{
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
}
}
}
}