protected IDictionary<string, HubDescriptor> BuildHubsCache()
{
// Getting all IHub-implementing types that apply
var types = _locator.GetAssemblies()
.SelectMany(GetTypesSafe)
.Where(IsHubType);
// Building cache entries for each descriptor
// Each descriptor is stored in dictionary under a key
// that is it's name or the name provided by an attribute
var hubDescriptors = types
.Select(type => new HubDescriptor
{
NameSpecified = (type.GetHubAttributeName() != null),
Name = type.GetHubName(),
HubType = type
});
var cacheEntries = new Dictionary<string, HubDescriptor>(StringComparer.OrdinalIgnoreCase);
foreach (var descriptor in hubDescriptors)
{
HubDescriptor oldDescriptor = null;
if (!cacheEntries.TryGetValue(descriptor.Name, out oldDescriptor))
{
cacheEntries[descriptor.Name] = descriptor;
}
else
{
throw new InvalidOperationException(
String.Format(CultureInfo.CurrentCulture,
Resources.Error_DuplicateHubNames,
oldDescriptor.HubType.AssemblyQualifiedName,
descriptor.HubType.AssemblyQualifiedName,
descriptor.Name));
}
}
return cacheEntries;
}