/// <summary> /// This helper resolves a channel from the direction specified. /// </summary> /// <param name="cpipe">The pipeline.</param> /// <param name="direction"></param> /// <param name="throwIfChannelIsNull"></param> /// <returns>The resolved channel or null if not resolved and throwIfChannelIsNull is false. Otherwise an exception will be raised.</returns> public static Channel ToChannel(this IPipelineChannel cpipe, ChannelDirection direction, bool throwIfChannelIsNull = true) { Channel channel = null; if (cpipe is IPipelineChannelBroadcast) { switch (direction) { case ChannelDirection.Incoming: channel = ((IPipelineChannelBroadcast)cpipe).ChannelListener; break; case ChannelDirection.Outgoing: channel = ((IPipelineChannelBroadcast)cpipe).ChannelSender; break; default: throw new NotSupportedException($"ChannelDirection {direction} not supported in {nameof(CorePipelineExtensions)}/{nameof(ToChannel)}"); } } else { channel = cpipe.Channel; } if (channel == null && throwIfChannelIsNull) { throw new ArgumentNullException($"The pipe channel is null -> {direction}"); } return(channel); }
private static void AttachPriorityPartition <P>(IPipelineChannel pipeline, P config) where P : PartitionConfig { if (pipeline is IPipelineChannelBroadcast) { throw new NotSupportedException("AttachPriorityPartition is not supported for broadcast channels."); } var channel = pipeline.Channel; if (channel.Partitions == null) { channel.Partitions = new List <P>(new[] { config }); return; } var partitions = channel.Partitions as List <P>; if (partitions == null) { throw new ChannelPartitionConfigCastException(pipeline.Channel.Id); } if (partitions.Select((p) => p.Priority).Contains(config.Priority)) { throw new ChannelPartitionConfigExistsException(pipeline.Channel.Id, config.Priority); } partitions.Add(config); }