private void BuildCache(IHubLocator hubLocator)
        {
            foreach (var hubType in hubLocator.GetHubs())
            {
                // Always cache by full name
                AddCacheKey(hubType.FullName, hubType);

                // If there's a hub name attribute then use it as an alternative name
                var hubName = ReflectionHelper.GetAttributeValue<HubNameAttribute, string>(hubType, a => a.HubName);

                // Don't add it if it's the same as the short name
                if (!String.Equals(hubName, hubType.Name, StringComparison.OrdinalIgnoreCase))
                {
                    AddCacheKey(hubName, hubType);
                }

                // Add an entry for the type's short name
                AddCacheKey(hubType.Name, hubType);
            }
        }
示例#2
0
        private void BuildCache(IHubLocator hubLocator)
        {
            foreach (var hubType in hubLocator.GetHubs())
            {
                // Always cache by full name
                AddCacheKey(hubType.FullName, hubType);

                // If there's a hub name attribute then use it as an alternative name
                var hubName = ReflectionHelper.GetAttributeValue <HubNameAttribute, string>(hubType, a => a.HubName);

                // Don't add it if it's the same as the short name
                if (!String.Equals(hubName, hubType.Name, StringComparison.OrdinalIgnoreCase))
                {
                    AddCacheKey(hubName, hubType);
                }

                // Add an entry for the type's short name
                AddCacheKey(hubType.Name, hubType);
            }
        }
示例#3
0
        public string GenerateProxy(HttpContextBase context, string serviceUrl)
        {
            string script;

            if (_scriptCache.TryGetValue(serviceUrl, out script))
            {
                return(script);
            }

            var template = _template.Value;

            script = template.Replace("{serviceUrl}", serviceUrl);

            var hubs  = new StringBuilder();
            var first = true;

            foreach (var type in _hubLocator.GetHubs())
            {
                if (!first)
                {
                    hubs.AppendLine(",");
                    hubs.Append("        ");
                }
                GenerateType(serviceUrl, hubs, type);
                first = false;
            }

            script = script.Replace("/*hubs*/", hubs.ToString());

            if (!context.IsDebuggingEnabled)
            {
                script = _javascriptMinifier.Minify(script);
            }

            _scriptCache.TryAdd(serviceUrl, script);

            return(script);
        }