| | | 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.Configuration; |
| | | 6 | | using System.Globalization; |
| | | 7 | | using System.Threading; |
| | | 8 | | using CoreWCF.Runtime; |
| | | 9 | | |
| | | 10 | | namespace CoreWCF.Configuration |
| | | 11 | | { |
| | | 12 | | internal sealed class ExtensionsSection : ConfigurationSection |
| | | 13 | | { |
| | 1 | 14 | | private static readonly Lazy<ExtensionsSection> s_extensionsSection = new Lazy<ExtensionsSection>(LazyThreadSafe |
| | | 15 | | |
| | 17 | 16 | | private static ExtensionsSection ExtensionSection => s_extensionsSection.Value; |
| | | 17 | | |
| | | 18 | | [ConfigurationProperty(ConfigurationStrings.BindingElementExtensions)] |
| | | 19 | | public ExtensionElementCollection BindingElementExtensions |
| | | 20 | | { |
| | 26 | 21 | | get { return (ExtensionElementCollection)base[ConfigurationStrings.BindingElementExtensions]; } |
| | | 22 | | } |
| | | 23 | | |
| | | 24 | | [ConfigurationProperty(ConfigurationStrings.BindingExtensions)] |
| | | 25 | | public ExtensionElementCollection BindingExtensions |
| | | 26 | | { |
| | 7 | 27 | | get { return (ExtensionElementCollection)base[ConfigurationStrings.BindingExtensions]; } |
| | | 28 | | } |
| | | 29 | | |
| | | 30 | | private void InitializeBindingElementExtensions() |
| | | 31 | | { |
| | 1 | 32 | | BindingElementExtensions.Add(new ExtensionElement(ConfigurationStrings.BinaryMessageEncodingSectionName, typ |
| | 1 | 33 | | BindingElementExtensions.Add(new ExtensionElement(ConfigurationStrings.HttpsTransportSectionName, typeof(Htt |
| | 1 | 34 | | BindingElementExtensions.Add(new ExtensionElement(ConfigurationStrings.HttpTransportSectionName, typeof(Http |
| | 1 | 35 | | BindingElementExtensions.Add(new ExtensionElement(ConfigurationStrings.MtomMessageEncodingSectionName, typeo |
| | 1 | 36 | | BindingElementExtensions.Add(new ExtensionElement(ConfigurationStrings.SecuritySectionName, typeof(SecurityE |
| | 1 | 37 | | BindingElementExtensions.Add(new ExtensionElement(ConfigurationStrings.SslStreamSecuritySectionName, typeof( |
| | 1 | 38 | | BindingElementExtensions.Add(new ExtensionElement(ConfigurationStrings.TcpTransportSectionName, typeof(TcpTr |
| | 1 | 39 | | BindingElementExtensions.Add(new ExtensionElement(ConfigurationStrings.TextMessageEncodingSectionName, typeo |
| | 1 | 40 | | BindingElementExtensions.Add(new ExtensionElement(ConfigurationStrings.WindowsStreamSecuritySectionName, typ |
| | 1 | 41 | | } |
| | | 42 | | |
| | | 43 | | private void InitializeBindingExtensions() |
| | | 44 | | { |
| | 1 | 45 | | BindingExtensions.Add(new ExtensionElement(ConfigurationStrings.BasicHttpBindingCollectionElementName, typeo |
| | 1 | 46 | | BindingExtensions.Add(new ExtensionElement(ConfigurationStrings.CustomBindingCollectionElementName, typeof(C |
| | 1 | 47 | | BindingExtensions.Add(new ExtensionElement(ConfigurationStrings.NetTcpBindingCollectionElementName, typeof(N |
| | 1 | 48 | | BindingExtensions.Add(new ExtensionElement(ConfigurationStrings.WSHttpBindingCollectionElementName, typeof(W |
| | 1 | 49 | | BindingExtensions.Add(new ExtensionElement(ConfigurationStrings.UdpBindingCollectionElementName, Configurati |
| | 1 | 50 | | BindingExtensions.Add(new ExtensionElement(ConfigurationStrings.NetHttpBindingCollectionElementName, typeof( |
| | 1 | 51 | | BindingExtensions.Add(new ExtensionElement(ConfigurationStrings.WebHttpBindingCollectionElementName, typeof( |
| | 1 | 52 | | } |
| | | 53 | | |
| | 1 | 54 | | public ExtensionsSection() |
| | | 55 | | { |
| | 1 | 56 | | InitializeDefault(); |
| | 1 | 57 | | } |
| | | 58 | | |
| | | 59 | | protected override void InitializeDefault() |
| | | 60 | | { |
| | 1 | 61 | | InitializeBindingElementExtensions(); |
| | 1 | 62 | | InitializeBindingExtensions(); |
| | 1 | 63 | | } |
| | | 64 | | |
| | | 65 | | |
| | | 66 | | internal static ExtensionElementCollection LookupAssociatedCollection(Type extensionType, ContextInformation eva |
| | | 67 | | { |
| | 0 | 68 | | collectionName = GetExtensionType(extensionType); |
| | 0 | 69 | | return ExtensionsSection.LookupCollection(collectionName, evaluationContext); |
| | | 70 | | } |
| | | 71 | | |
| | | 72 | | private static string GetExtensionType(Type extensionType) |
| | | 73 | | { |
| | 0 | 74 | | string collectionName = string.Empty; |
| | | 75 | | |
| | 0 | 76 | | if (extensionType.IsSubclassOf(typeof(BindingElementExtensionElement))) |
| | | 77 | | { |
| | 0 | 78 | | collectionName = ConfigurationStrings.BindingElementExtensions; |
| | | 79 | | } |
| | 0 | 80 | | else if (extensionType.IsSubclassOf(typeof(BindingCollectionElement))) |
| | | 81 | | { |
| | 0 | 82 | | collectionName = ConfigurationStrings.BindingExtensions; |
| | | 83 | | } |
| | | 84 | | else |
| | | 85 | | { |
| | | 86 | | // LookupAssociatedCollection built on assumption that extensionType is valid. |
| | | 87 | | // This should be protected at the callers site. If assumption is invalid, then |
| | | 88 | | // configuration system is in an indeterminate state. Need to stop in a manner that |
| | | 89 | | // user code can not capture. |
| | | 90 | | Fx.Assert(string.Format(CultureInfo.InvariantCulture, "{0} is not a type supported by the ServiceModelEx |
| | 0 | 91 | | DiagnosticUtility.FailFast(string.Format(CultureInfo.InvariantCulture, "{0} is not a type supported by t |
| | | 92 | | } |
| | | 93 | | |
| | 0 | 94 | | return collectionName; |
| | | 95 | | } |
| | | 96 | | |
| | | 97 | | |
| | | 98 | | internal static ExtensionElementCollection LookupCollection(string collectionName, ContextInformation evaluation |
| | | 99 | | { |
| | 17 | 100 | | ExtensionElementCollection collection = null; |
| | 17 | 101 | | ExtensionsSection extensionsSection = ExtensionSection; |
| | | 102 | | |
| | | 103 | | switch (collectionName) |
| | | 104 | | { |
| | | 105 | | case (ConfigurationStrings.BindingElementExtensions): |
| | 17 | 106 | | collection = extensionsSection.BindingElementExtensions; |
| | 17 | 107 | | break; |
| | | 108 | | case (ConfigurationStrings.BindingExtensions): |
| | 0 | 109 | | collection = extensionsSection.BindingExtensions; |
| | 0 | 110 | | break; |
| | | 111 | | default: |
| | | 112 | | // LookupCollection built on assumption that collectionName is valid. |
| | | 113 | | // This should be protected at the callers site. If assumption is invalid, then |
| | | 114 | | // configuration system is in an indeterminate state. Need to stop in a manner that |
| | | 115 | | // user code can not capture. |
| | | 116 | | Fx.Assert(string.Format(CultureInfo.InvariantCulture, "{0} is not a valid ServiceModelExtensionsSect |
| | 0 | 117 | | DiagnosticUtility.FailFast(string.Format(CultureInfo.InvariantCulture, "{0} is not a valid ServiceMo |
| | | 118 | | break; |
| | | 119 | | } |
| | | 120 | | |
| | 17 | 121 | | return collection; |
| | | 122 | | } |
| | | 123 | | } |
| | | 124 | | } |