Use the SignalR 2.0 Owin pipeline with my SignalR lib

I am studying updating this library to SignalR 2.0

https://github.com/AndersMalmgren/SignalR.EventAggregatorProxy

I want it to support the Owin 2.0 pipeline with an interface IAppBuilderinstead of using RouteCollection, for example, SignalR 1.x.

The problem is, how can I get the route assembly from IAppBuilder? I need it to register a custom IHttpHandler that processes my custom js script (how SignalR registers its hub script)

1.x my library looks like this:

public static class SignalRConfig
{
    public static void Register(RouteCollection routes)
    {
        routes.MapHubs();
        routes.MapEventProxy<Contracts.Events.Event>();
    }
}

My goal for 2.0 config is something like this

public static class SignalRConfig
{
    public static void Configuration(IAppBuilder app)
    {
        app.MapSignalR();
        app.MapEventProxy<Contracts.Events.Event>();
    }
}

My code, which depends on the RouteCollection, is as follows:

public static class RouteCollectionExtensions
{
    public static void MapEventProxy<TEvent>(this RouteCollection routes)
    {
        Bootstrapper.Init<TEvent>();

        routes.Add(new Route(
                       "eventAggregation/events",
                       new RouteValueDictionary(),
                       new RouteValueDictionary() {{"controller", string.Empty}},
                       new EventScriptRouteHandler<TEvent>()));
    }
}

edit: , Owin , SignalR 2.0 ?

: im

using Owin;
using SignalR.EventAggregatorProxy.Boostrap;
namespace SignalR.EventAggregatorProxy.Owin
{
    public static class AppBuilderExtensions
    {
        public static void MapEventProxy<TEvent>(this IAppBuilder app)
        {
            Bootstrapper.Init<TEvent>();
            app.Map("/eventAggregation/events", subApp => subApp.Use<EventScriptMiddleware<TEvent>>());
        }
    }
}

EventScriptMiddleware

update: , , javacript,

namespace SignalR.EventAggregatorProxy.Owin
{
    public class EventScriptMiddleware<TEvent> : OwinMiddleware
    {
        public EventScriptMiddleware(OwinMiddleware next) : base(next)
        {
        }

        public override Task Invoke(IOwinContext context)
        {
            return context.Response.WriteAsync("Hello world!!");
        }
    }
}
+4
1

:

public static class AppBuilderExtensions
{
    public static void MapEventProxy<TEvent>(this IAppBuilder app)
    {
        Bootstrapper.Init<TEvent>();
        app.Map("/eventAggregation/events", subApp => subApp.Use<EventScriptMiddleware<TEvent>>());
    }
}

public override Task Invoke(IOwinContext context)
{
    var response = context.Response;
    response.ContentType = "application/javascript";
    response.StatusCode = 200;

    if (ClientCached(context.Request, scriptBuildDate))
    {
        response.StatusCode = 304;
        response.Headers["Content-Length"] = "0";
        response.Body.Close();
        response.Body = Stream.Null;

        return Task.FromResult<Object>(null);
    }

    response.Headers["Last-Modified"] = scriptBuildDate.ToUniversalTime().ToString("r");
    return response.WriteAsync(js);
}

https://github.com/AndersMalmgren/SignalR.EventAggregatorProxy/tree/master/SignalR.EventAggregatorProxy/Owin

+1

All Articles