| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using CoreWCF.Configuration; |
| | | 6 | | using CoreWCF.Dispatcher; |
| | | 7 | | |
| | | 8 | | namespace CoreWCF.Channels |
| | | 9 | | { |
| | | 10 | | internal class ChannelBuilder |
| | | 11 | | { |
| | | 12 | | private readonly bool _isChannelDemuxerRequired = false; |
| | | 13 | | |
| | 33 | 14 | | public ChannelBuilder(BindingContext context, bool addChannelDemuxerIfRequired) |
| | | 15 | | { |
| | 33 | 16 | | _isChannelDemuxerRequired = addChannelDemuxerIfRequired; |
| | 33 | 17 | | if (_isChannelDemuxerRequired) |
| | | 18 | | { |
| | 22 | 19 | | ChannelDemuxer = new ChannelDemuxer(); |
| | | 20 | | } |
| | | 21 | | |
| | 33 | 22 | | Binding = new CustomBinding(context.Binding, context.RemainingBindingElements); |
| | 33 | 23 | | BindingParameters = context.BindingParameters; |
| | 33 | 24 | | } |
| | | 25 | | |
| | 0 | 26 | | public ChannelBuilder(Binding binding, BindingParameterCollection bindingParameters, bool addChannelDemuxerIfReq |
| | | 27 | | { |
| | 0 | 28 | | Binding = new CustomBinding(binding); |
| | 0 | 29 | | BindingParameters = bindingParameters; |
| | 0 | 30 | | _isChannelDemuxerRequired = addChannelDemuxerIfRequired; |
| | 0 | 31 | | } |
| | | 32 | | |
| | 55 | 33 | | public CustomBinding Binding { get; set; } |
| | | 34 | | |
| | 100 | 35 | | public BindingParameterCollection BindingParameters { get; set; } |
| | | 36 | | |
| | 77 | 37 | | public ChannelDemuxer ChannelDemuxer { get; } |
| | | 38 | | |
| | | 39 | | public TypedChannelDemuxer GetTypedChannelDemuxer<TChannel>() where TChannel : class, IChannel |
| | | 40 | | { |
| | 0 | 41 | | return ChannelDemuxer.GetTypedServiceDispatcher<TChannel>(BindingParameters); |
| | | 42 | | } |
| | | 43 | | |
| | | 44 | | public TypedChannelDemuxer GetTypedChannelDemuxer(Type channelType) |
| | | 45 | | { |
| | 24 | 46 | | return ChannelDemuxer.GetTypedServiceDispatcher(channelType, BindingParameters); |
| | | 47 | | } |
| | | 48 | | |
| | | 49 | | public IServiceDispatcher AddServiceDispatcher<TChannel>(IServiceDispatcher innerDispatcher) where TChannel : c |
| | | 50 | | { |
| | 0 | 51 | | if (!_isChannelDemuxerRequired) |
| | 0 | 52 | | throw new Exception("ChannelDemuxerRequired is set to false"); |
| | 0 | 53 | | return ChannelDemuxer.CreateServiceDispatcher<TChannel>(innerDispatcher, BindingParameters); |
| | | 54 | | } |
| | | 55 | | |
| | | 56 | | public IServiceDispatcher AddServiceDispatcher<TChannel>(IServiceDispatcher innerDispatcher, ChannelDemuxerFilte |
| | | 57 | | { |
| | 33 | 58 | | if (!_isChannelDemuxerRequired) |
| | 0 | 59 | | throw new Exception("ChannelDemuxerRequired is set to false"); |
| | 33 | 60 | | return ChannelDemuxer.CreateServiceDispatcher<TChannel>(innerDispatcher, filter, BindingParameters); |
| | | 61 | | } |
| | | 62 | | |
| | | 63 | | public void RemoveServiceDispatcher<TChannel>(MessageFilter filter) where TChannel : class, IChannel |
| | | 64 | | { |
| | 10 | 65 | | if (ChannelDemuxer == null) |
| | | 66 | | { |
| | 0 | 67 | | throw new Exception("Demuxer can't be null"); |
| | | 68 | | } |
| | 10 | 69 | | ChannelDemuxer.RemoveServiceDispatcher<TChannel>(filter, BindingParameters); |
| | 10 | 70 | | } |
| | | 71 | | |
| | | 72 | | public IServiceDispatcher BuildServiceDispatcher<TChannel>(BindingContext context, IServiceDispatcher innerDispa |
| | | 73 | | { |
| | 33 | 74 | | return context.BuildNextServiceDispatcher<TChannel>(innerDispatcher); |
| | | 75 | | } |
| | | 76 | | } |
| | | 77 | | } |