Пример #1
0
        /// <summary>
        /// 获取路由信息。
        /// </summary>
        /// <param name="routes">路由集合。</param>
        public void GetRoutes(ICollection <RouteDescriptor> routes)
        {
            #region Hub

            var owinRoute = new RouteCollection().MapOwinPath("signalr.hubs", "/signalr"
                                                              , app => app.MapSignalR(string.Empty, _rabbitHubConfiguration.ConnectionConfiguration));

            routes.Add(new RouteDescriptor
            {
                Name         = "Rabbit.Components.Web.SignalR",
                Route        = owinRoute,
                SessionState = SessionStateBehavior.Disabled,
                Priority     = 5000
            });

            #endregion Hub

            #region PersistentConnection

            foreach (var tuple in _typeHarvester.Get <PersistentConnection>())
            {
                var attrs = tuple.Item1.GetCustomAttributes(typeof(ConnectionAttribute), false);

                var typeName       = tuple.Item1.Name.ToLowerInvariant();
                var connectionName = typeName.Contains("connection")
                                            ? typeName.Substring(0, typeName.IndexOf("connection", StringComparison.Ordinal))
                                            : typeName;
                var connectionUrl = connectionName;

                if (attrs.Any())
                {
                    var attrName = ((ConnectionAttribute)attrs[0]).Name;
                    var attrUrl  = ((ConnectionAttribute)attrs[0]).Url;

                    connectionName = !string.IsNullOrWhiteSpace(attrName) ? attrName : connectionName;
                    connectionUrl  = connectionName;

                    connectionUrl = !string.IsNullOrWhiteSpace(attrUrl) ? attrUrl : connectionUrl;
                }

                var tuple1 = tuple;
                routes.Add(new RouteDescriptor
                {
                    Route        = new RouteCollection().MapOwinPath(connectionName, "/" + connectionUrl.TrimStart('/'), map => map.MapSignalR(string.Empty, tuple1.Item1, _rabbitHubConfiguration.ConnectionConfiguration)),
                    SessionState = SessionStateBehavior.Disabled,
                    Priority     = int.MaxValue - 1
                });
            }

            #endregion PersistentConnection
        }
        private IDictionary <string, HubDescriptor> BuildHubsCache()
        {
            var types = _typeHarvester.Get(IsHubType).Select(tt => tt.Item1);

            var cacheEntries = types
                               .Select(type => new HubDescriptor
            {
                NameSpecified = (GetHubAttributeName(type) != null),
                Name          = GetHubName(type),
                HubType       = type
            })
                               .ToDictionary(hub => hub.Name,
                                             hub => hub,
                                             StringComparer.OrdinalIgnoreCase);

            return(cacheEntries);
        }