将SignalR 2.0 Owin管道与SignalR库一起使用 - c#

我正在考虑将该库升级到SignalR 2.0

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

我希望它通过IAppBuilder接口支持2.0 Owin管道,而不是像SignalR 1.x那样使用RouteCollection

问题是,如何从IAppBuilder获取路由集合?我需要它来注册处理我的自定义js脚本的自定义IHttpHandler(就像SignalR注册其中心脚本)

我的lib的1.x设置如下所示

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

我对2.0配置的目标是这样的

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

我的依赖于RouteCollection的代码如下所示

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>()));
    }
}

编辑:看起来非常复杂,无法让Owin满足请求,我可以在SignalR 2.0中使用辅助方法来注册路由和该路由的处理程序吗?

更新:
看起来我在这段代码的正确轨道上

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

更新:难题的最后一部分,现在我只需要我的中间件就可以真正吐出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!!");
        }
    }
}

参考方案

最终版本如下所示,应用构建器扩展

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

Python 3运算符>>打印到文件 - python

我有以下Python代码编写项目的依赖文件。它可以在Python 2.x上正常工作,但是在使用Python 3进行测试时会报告错误。depend = None if not nmake: depend = open(".depend", "a") dependmak = open(".depend.mak&#…

无法解析Json响应 - php

我正在尝试解析一个包含产品类别的JSON文件,然后解析这些类别中的产品,并在div中显示它们。我的问题:虽然我可以获取类别,但我不知道如何索取产品(并将它们显示在类别下)。我的剧本:<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script> …

在xpath中选择多个条件 - php

我正在尝试使用来自高尔夫比赛的xml提要,以显示每个高尔夫球手在高尔夫球场上的位置。目前,我想展示符合两个条件的所有高尔夫球手(排在前25名,以及所有加拿大高尔夫球手)。这是xml提要的示例。<GolfDataFeed Type="Leaderboards" Timestamp="3/21/2012 9:18:09 PM&…

与哪些运算符>>兼容 - java

我这里没有什么代码int b=3; b=b >> 1; System.out.println(b); 它可以完美工作,但是当我将变量b更改为byte,short,float,double时,它包含错误,但是对于变量int和long来说,它可以完美工作,为什么它不能与其他变量一起工作? 参考方案 位移位运算符(例如>>)与任何整数类型兼…

使用javascript在客户端的列表视图中选择所有复选框 - javascript

我有一个列表视图,在标题中有一个复选框。如果标题复选框已选中/未选中,我想选择行中的所有复选框。如何在客户端实现此目标?这是ListView设计代码。<asp:ListView ID="lvTypes" runat="server" GroupPlaceholderID="groupPlaceHolde…