public static BaseProtocol CreateProtocolChain(List<ulong> chain, Variant parameters)
{
BaseProtocol pResult = null;
//1. Check and see if all the protocols are handled by a factory
if (chain.Any(x => !_factoriesByProtocolId.ContainsKey(x)))
{
Logger.FATAL("protocol not handled by anynone");
return null;
}
//2. Spawn the protocols
foreach (var item in chain)
{
var pProtocol = _factoriesByProtocolId[item].SpawnProtocol(item, parameters);
if (pProtocol == null)
{
Logger.FATAL("Unable to spawn protocol {0} handled by factory {1}", item.TagToString(), _factoriesByProtocolId[item].Id);
pResult?.FarEndpoint.Dispose();
return null;
}
if (pResult != null)
pResult.NearProtocol = pProtocol;
pResult = pProtocol;
}
return pResult.NearEndpoint;
}