Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed and simplified hub cache.

  • Loading branch information...
commit cd18cf92798d17fc967f062984c234c2e541d14f 1 parent b535408
@pszmyd authored
View
45 SignalR/Hubs/Lookup/ReflectedHubDescriptorProvider.cs
@@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
-using SignalR.Infrastructure;
namespace SignalR.Hubs
{
@@ -38,22 +37,17 @@ public bool TryGetHub(string hubName, out HubDescriptor descriptor)
.SelectMany(GetTypesSafe)
.Where(IsHubType);
- // Building a list of descriptors for each type
- var descriptors = types.Select(type =>
- new HubDescriptor
- {
- Name = GetHubName(type),
- Type = type
- });
-
// Building cache entries for each descriptor
- // Each descriptor is stored in dictionary under several keys for allowing quick lookup:
- // full type name, short type name and optionally a name given by attribute
- var cacheEntries = descriptors
- .SelectMany(desc => CacheKeysFor(desc.Type)
- .Select(key => new { Descriptor = desc, Key = key }))
- .ToDictionary(anon => anon.Key,
- anon => anon.Descriptor,
+ // Each descriptor is stored in dictionary under a key
+ // that is it's name or the name provided by an attribute
+ var cacheEntries = types
+ .Select(type => new HubDescriptor
+ {
+ Name = type.GetHubName(),
+ Type = type
+ })
+ .ToDictionary(hub => hub.Name,
+ hub => hub,
StringComparer.OrdinalIgnoreCase);
return cacheEntries;
@@ -74,19 +68,6 @@ private static bool IsHubType(Type type)
}
}
- private static IEnumerable<string> CacheKeysFor(Type type)
- {
- yield return type.FullName;
- yield return type.Name;
-
- var attributeName = GetHubName(type);
-
- if (!String.Equals(attributeName, type.Name, StringComparison.OrdinalIgnoreCase))
- {
- yield return attributeName;
- }
- }
-
private static IEnumerable<Type> GetTypesSafe(Assembly a)
{
try
@@ -98,11 +79,5 @@ private static IEnumerable<Type> GetTypesSafe(Assembly a)
return Enumerable.Empty<Type>();
}
}
-
- private static string GetHubName(Type type)
- {
- return ReflectionHelper.GetAttributeValue<HubNameAttribute, string>(type, attr => attr.HubName)
- ?? type.Name;
- }
}
}
View
3  SignalR/SignalR.csproj
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -54,6 +54,7 @@
<Compile Include="Hosting\IResponse.cs" />
<Compile Include="CommandType.cs" />
<Compile Include="ConnectionExtensions.cs" />
+ <Compile Include="Hubs\Extensions\HubTypeExtensions.cs" />
<Compile Include="Hubs\Extensions\HubManagerExtensions.cs" />
<Compile Include="Hubs\Lookup\DefaultParameterResolver.cs" />
<Compile Include="Hubs\Lookup\IParameterResolver.cs" />
Please sign in to comment.
Something went wrong with that request. Please try again.