| | | 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.Collections.Generic; |
| | | 5 | | |
| | | 6 | | namespace CoreWCF.Channels |
| | | 7 | | { |
| | | 8 | | public class CustomBinding : Binding |
| | | 9 | | { |
| | 1799 | 10 | | public CustomBinding() |
| | | 11 | | { |
| | 1799 | 12 | | } |
| | | 13 | | |
| | 20 | 14 | | public CustomBinding(params BindingElement[] bindingElementsInTopDownChannelStackOrder) |
| | | 15 | | { |
| | 20 | 16 | | if (bindingElementsInTopDownChannelStackOrder == null) |
| | | 17 | | { |
| | 0 | 18 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(bindingElementsInTopDownChannelS |
| | | 19 | | } |
| | | 20 | | |
| | 104 | 21 | | foreach (BindingElement element in bindingElementsInTopDownChannelStackOrder) |
| | | 22 | | { |
| | 32 | 23 | | Elements.Add(element); |
| | | 24 | | } |
| | 20 | 25 | | } |
| | | 26 | | |
| | | 27 | | public CustomBinding(string name, string ns, params BindingElement[] bindingElementsInTopDownChannelStackOrder) |
| | 56 | 28 | | : base(name, ns) |
| | | 29 | | { |
| | 56 | 30 | | if (bindingElementsInTopDownChannelStackOrder == null) |
| | | 31 | | { |
| | 0 | 32 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(bindingElementsInTopDownChannelS |
| | | 33 | | } |
| | | 34 | | |
| | 112 | 35 | | foreach (BindingElement element in bindingElementsInTopDownChannelStackOrder) |
| | | 36 | | { |
| | 0 | 37 | | Elements.Add(element); |
| | | 38 | | } |
| | 56 | 39 | | } |
| | | 40 | | |
| | 1 | 41 | | public CustomBinding(IEnumerable<BindingElement> bindingElementsInTopDownChannelStackOrder) |
| | | 42 | | { |
| | 1 | 43 | | if (bindingElementsInTopDownChannelStackOrder == null) |
| | | 44 | | { |
| | 0 | 45 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(bindingElementsInTopDownChannelS |
| | | 46 | | } |
| | | 47 | | |
| | 4 | 48 | | foreach (BindingElement element in bindingElementsInTopDownChannelStackOrder) |
| | | 49 | | { |
| | 1 | 50 | | Elements.Add(element); |
| | | 51 | | } |
| | 1 | 52 | | } |
| | | 53 | | |
| | | 54 | | public CustomBinding(Binding binding) |
| | 9109 | 55 | | : this(binding, SafeCreateBindingElements(binding)) |
| | | 56 | | { |
| | 9109 | 57 | | } |
| | | 58 | | |
| | | 59 | | private static BindingElementCollection SafeCreateBindingElements(Binding binding) |
| | | 60 | | { |
| | 9109 | 61 | | if (binding == null) |
| | | 62 | | { |
| | 0 | 63 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(binding)); |
| | | 64 | | } |
| | 9109 | 65 | | return binding.CreateBindingElements(); |
| | | 66 | | } |
| | | 67 | | |
| | 9142 | 68 | | internal CustomBinding(Binding binding, BindingElementCollection elements) |
| | | 69 | | { |
| | 9142 | 70 | | if (binding == null) |
| | | 71 | | { |
| | 0 | 72 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(binding)); |
| | | 73 | | } |
| | 9142 | 74 | | if (elements == null) |
| | | 75 | | { |
| | 0 | 76 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(elements)); |
| | | 77 | | } |
| | | 78 | | |
| | 9142 | 79 | | Name = binding.Name; |
| | 9142 | 80 | | Namespace = binding.Namespace; |
| | 9142 | 81 | | CloseTimeout = binding.CloseTimeout; |
| | 9142 | 82 | | OpenTimeout = binding.OpenTimeout; |
| | 9142 | 83 | | ReceiveTimeout = binding.ReceiveTimeout; |
| | 9142 | 84 | | SendTimeout = binding.SendTimeout; |
| | | 85 | | |
| | 55562 | 86 | | for (int i = 0; i < elements.Count; i++) |
| | | 87 | | { |
| | 18639 | 88 | | Elements.Add(elements[i]); |
| | | 89 | | } |
| | 9142 | 90 | | } |
| | | 91 | | |
| | 47164 | 92 | | public BindingElementCollection Elements { get; } = new BindingElementCollection(); |
| | | 93 | | |
| | | 94 | | public override BindingElementCollection CreateBindingElements() |
| | | 95 | | { |
| | 5385 | 96 | | return Elements.Clone(); |
| | | 97 | | } |
| | | 98 | | |
| | | 99 | | public override string Scheme |
| | | 100 | | { |
| | | 101 | | get |
| | | 102 | | { |
| | 888 | 103 | | TransportBindingElement transport = Elements.Find<TransportBindingElement>(); |
| | 888 | 104 | | if (transport == null) |
| | | 105 | | { |
| | 0 | 106 | | return string.Empty; |
| | | 107 | | } |
| | | 108 | | |
| | 888 | 109 | | return transport.Scheme; |
| | | 110 | | } |
| | | 111 | | } |
| | | 112 | | } |
| | | 113 | | } |