| | | 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 System.Globalization; |
| | | 6 | | using System.Text; |
| | | 7 | | using CoreWCF.Configuration; |
| | | 8 | | |
| | | 9 | | namespace CoreWCF.Channels |
| | | 10 | | { |
| | | 11 | | public class BindingContext |
| | | 12 | | { |
| | | 13 | | public BindingContext(CustomBinding binding, BindingParameterCollection parameters) |
| | 9697 | 14 | | : this(binding, parameters, null, string.Empty) |
| | | 15 | | { |
| | 9697 | 16 | | } |
| | | 17 | | |
| | 10310 | 18 | | public BindingContext(CustomBinding binding, BindingParameterCollection parameters, Uri listenUriBaseAddress, st |
| | | 19 | | { |
| | 10310 | 20 | | if (binding == null) |
| | | 21 | | { |
| | 0 | 22 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(binding)); |
| | | 23 | | } |
| | 10310 | 24 | | if (listenUriRelativeAddress == null) |
| | | 25 | | { |
| | 0 | 26 | | listenUriRelativeAddress = string.Empty; |
| | | 27 | | } |
| | | 28 | | |
| | 10310 | 29 | | Initialize(binding, binding.Elements, parameters, listenUriBaseAddress, listenUriRelativeAddress); |
| | 10310 | 30 | | } |
| | | 31 | | |
| | 11735 | 32 | | private BindingContext(CustomBinding binding, |
| | 11735 | 33 | | BindingElementCollection remainingBindingElements, |
| | 11735 | 34 | | BindingParameterCollection parameters, |
| | 11735 | 35 | | Uri listenUriBaseAddress, |
| | 11735 | 36 | | string listenUriRelativeAddress) |
| | | 37 | | { |
| | 11735 | 38 | | Initialize(binding, remainingBindingElements, parameters, listenUriBaseAddress, listenUriRelativeAddress); |
| | 11735 | 39 | | } |
| | | 40 | | |
| | | 41 | | private void Initialize(CustomBinding binding, |
| | | 42 | | BindingElementCollection remainingBindingElements, |
| | | 43 | | BindingParameterCollection parameters, |
| | | 44 | | Uri listenUriBaseAddress, |
| | | 45 | | string listenUriRelativeAddress) |
| | | 46 | | { |
| | 22045 | 47 | | Binding = binding; |
| | 22045 | 48 | | RemainingBindingElements = new BindingElementCollection(remainingBindingElements); |
| | 22045 | 49 | | BindingParameters = new BindingParameterCollection(parameters); |
| | 22045 | 50 | | ListenUriBaseAddress = listenUriBaseAddress; |
| | 22045 | 51 | | ListenUriRelativeAddress = listenUriRelativeAddress; |
| | 22045 | 52 | | } |
| | | 53 | | |
| | 34313 | 54 | | public CustomBinding Binding { get; private set; } |
| | | 55 | | |
| | 37324 | 56 | | public BindingParameterCollection BindingParameters { get; private set; } |
| | | 57 | | |
| | 33800 | 58 | | public Uri ListenUriBaseAddress { get; set; } |
| | | 59 | | |
| | 33798 | 60 | | public string ListenUriRelativeAddress { get; set; } |
| | | 61 | | |
| | 56042 | 62 | | public BindingElementCollection RemainingBindingElements { get; private set; } |
| | | 63 | | |
| | | 64 | | public IServiceDispatcher BuildNextServiceDispatcher<TChannel>(IServiceDispatcher innerDispatcher) where TChanne |
| | | 65 | | { |
| | 1241 | 66 | | return RemoveNextElement().BuildServiceDispatcher<TChannel>(this, innerDispatcher); |
| | | 67 | | } |
| | | 68 | | |
| | | 69 | | public bool CanBuildNextServiceDispatcher<TChannel>() where TChannel : class, IChannel |
| | | 70 | | { |
| | 3932 | 71 | | BindingContext clone = Clone(); |
| | 3932 | 72 | | return clone.RemoveNextElement().CanBuildServiceDispatcher<TChannel>(clone); |
| | | 73 | | } |
| | | 74 | | |
| | | 75 | | public T GetInnerProperty<T>() where T : class |
| | | 76 | | { |
| | 8761 | 77 | | if (RemainingBindingElements.Count == 0) |
| | | 78 | | { |
| | 1149 | 79 | | return null; |
| | | 80 | | } |
| | | 81 | | else |
| | | 82 | | { |
| | 7612 | 83 | | BindingContext clone = Clone(); |
| | 7612 | 84 | | return clone.RemoveNextElement().GetProperty<T>(clone); |
| | | 85 | | } |
| | | 86 | | } |
| | | 87 | | public BindingContext Clone() |
| | | 88 | | { |
| | 11735 | 89 | | return new BindingContext(Binding, RemainingBindingElements, BindingParameters, |
| | 11735 | 90 | | ListenUriBaseAddress, ListenUriRelativeAddress); |
| | | 91 | | } |
| | | 92 | | |
| | | 93 | | private BindingElement RemoveNextElement() |
| | | 94 | | { |
| | 12785 | 95 | | BindingElement element = RemainingBindingElements.Remove<BindingElement>(); |
| | 12785 | 96 | | if (element != null) |
| | | 97 | | { |
| | 12785 | 98 | | return element; |
| | | 99 | | } |
| | | 100 | | |
| | 0 | 101 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format( |
| | 0 | 102 | | SR.NoChannelBuilderAvailable, Binding.Name, Binding.Namespace))); |
| | | 103 | | } |
| | | 104 | | |
| | | 105 | | internal void ValidateBindingElementsConsumed() |
| | | 106 | | { |
| | 593 | 107 | | if (RemainingBindingElements.Count != 0) |
| | | 108 | | { |
| | 0 | 109 | | StringBuilder builder = new StringBuilder(); |
| | 0 | 110 | | foreach (BindingElement bindingElement in RemainingBindingElements) |
| | | 111 | | { |
| | 0 | 112 | | if (builder.Length > 0) |
| | | 113 | | { |
| | 0 | 114 | | builder.Append(CultureInfo.CurrentCulture.TextInfo.ListSeparator); |
| | 0 | 115 | | builder.Append(" "); |
| | | 116 | | } |
| | 0 | 117 | | string typeString = bindingElement.GetType().ToString(); |
| | 0 | 118 | | builder.Append(typeString.Substring(typeString.LastIndexOf('.') + 1)); |
| | | 119 | | } |
| | 0 | 120 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.Not |
| | | 121 | | } |
| | 593 | 122 | | } |
| | | 123 | | } |
| | | 124 | | } |