public static bool RegisterProtocolFactory(this BaseProtocolFactory pFactory) {//1. Test to see if this factory is already registered if (_factoriesById.ContainsKey(pFactory.Id)) { Logger.FATAL("Factory id {0} already registered", pFactory.Id); return(false); } //2. Test to see if the protocol chains exported by this factory are already in use if (pFactory.HandledProtocolChains.Any(x => _factoriesByChainName.ContainsKey(x))) { Logger.FATAL("protocol chain already handled by factory "); return(false); } //3. Test to see if the protocols exported by this factory are already in use if (pFactory.HandledProtocols.Any(x => _factoriesByProtocolId.ContainsKey(x))) { Logger.FATAL("protocol already handled by factory "); return(false); } //4. Register everything #if PARALLEL pFactory.HandledProtocolChains().AsParallel().ForAll(x => _factoriesByChainName[x] = pFactory); pFactory.HandledProtocols().AsParallel().ForAll(x => _factoriesByProtocolId[x] = pFactory); #else foreach (var handledProtocolChain in pFactory.HandledProtocolChains) { _factoriesByChainName[handledProtocolChain] = pFactory; } foreach (var handledProtocol in pFactory.HandledProtocols) { _factoriesByProtocolId[handledProtocol] = pFactory; } #endif _factoriesById[pFactory.Id] = pFactory; return(true); }