| | | 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 CoreWCF.Channels; |
| | | 7 | | |
| | | 8 | | namespace CoreWCF.Configuration |
| | | 9 | | { |
| | | 10 | | public class WebSocketTransportSettingsElement : ServiceModelConfigurationElement |
| | | 11 | | { |
| | | 12 | | [ConfigurationProperty(ConfigurationStrings.TransportUsage, DefaultValue = WebSocketDefaults.TransportUsage)] |
| | | 13 | | public virtual WebSocketTransportUsage TransportUsage |
| | | 14 | | { |
| | 4 | 15 | | get { return (WebSocketTransportUsage)base[ConfigurationStrings.TransportUsage]; } |
| | 0 | 16 | | set { base[ConfigurationStrings.TransportUsage] = value; } |
| | | 17 | | } |
| | | 18 | | |
| | | 19 | | [ConfigurationProperty(ConfigurationStrings.CreateNotificationOnConnection, DefaultValue = WebSocketDefaults.Cre |
| | | 20 | | public bool CreateNotificationOnConnection |
| | | 21 | | { |
| | 4 | 22 | | get { return (bool)base[ConfigurationStrings.CreateNotificationOnConnection]; } |
| | 0 | 23 | | set { base[ConfigurationStrings.CreateNotificationOnConnection] = value; } |
| | | 24 | | } |
| | | 25 | | |
| | | 26 | | [ConfigurationProperty(ConfigurationStrings.KeepAliveInterval, DefaultValue = WebSocketDefaults.DefaultKeepAlive |
| | | 27 | | public TimeSpan KeepAliveInterval |
| | | 28 | | { |
| | 4 | 29 | | get { return (TimeSpan)base[ConfigurationStrings.KeepAliveInterval]; } |
| | 0 | 30 | | set { base[ConfigurationStrings.KeepAliveInterval] = value; } |
| | | 31 | | } |
| | | 32 | | |
| | | 33 | | [ConfigurationProperty(ConfigurationStrings.SubProtocol, DefaultValue = null)] |
| | | 34 | | [StringValidator(MinLength = 0)] |
| | | 35 | | public virtual string SubProtocol |
| | | 36 | | { |
| | 4 | 37 | | get { return (string)base[ConfigurationStrings.SubProtocol]; } |
| | 0 | 38 | | set { base[ConfigurationStrings.SubProtocol] = value; } |
| | | 39 | | } |
| | | 40 | | |
| | | 41 | | [ConfigurationProperty(ConfigurationStrings.DisablePayloadMasking, DefaultValue = WebSocketDefaults.DisablePaylo |
| | | 42 | | public bool DisablePayloadMasking |
| | | 43 | | { |
| | 4 | 44 | | get { return (bool)base[ConfigurationStrings.DisablePayloadMasking]; } |
| | 0 | 45 | | set { base[ConfigurationStrings.DisablePayloadMasking] = value; } |
| | | 46 | | } |
| | | 47 | | |
| | | 48 | | [ConfigurationProperty(ConfigurationStrings.MaxPendingConnections, DefaultValue = WebSocketDefaults.DefaultMaxPe |
| | | 49 | | [IntegerValidator(MinValue = 0)] |
| | | 50 | | public int MaxPendingConnections |
| | | 51 | | { |
| | 4 | 52 | | get { return (int)base[ConfigurationStrings.MaxPendingConnections]; } |
| | 0 | 53 | | set { base[ConfigurationStrings.MaxPendingConnections] = value; } |
| | | 54 | | } |
| | | 55 | | |
| | | 56 | | public void InitializeFrom(WebSocketTransportSettings settings) |
| | | 57 | | { |
| | 0 | 58 | | if (settings == null) |
| | | 59 | | { |
| | 0 | 60 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(settings)); |
| | | 61 | | } |
| | | 62 | | |
| | 0 | 63 | | SetPropertyValueIfNotDefaultValue(ConfigurationStrings.TransportUsage, settings.TransportUsage); |
| | 0 | 64 | | SetPropertyValueIfNotDefaultValue(ConfigurationStrings.CreateNotificationOnConnection, settings.CreateNotifi |
| | 0 | 65 | | SetPropertyValueIfNotDefaultValue(ConfigurationStrings.KeepAliveInterval, settings.KeepAliveInterval); |
| | 0 | 66 | | SetPropertyValueIfNotDefaultValue(ConfigurationStrings.SubProtocol, settings.SubProtocol); |
| | 0 | 67 | | SetPropertyValueIfNotDefaultValue(ConfigurationStrings.DisablePayloadMasking, settings.DisablePayloadMasking |
| | 0 | 68 | | SetPropertyValueIfNotDefaultValue(ConfigurationStrings.MaxPendingConnections, settings.MaxPendingConnections |
| | 0 | 69 | | } |
| | | 70 | | |
| | | 71 | | public void ApplyConfiguration(WebSocketTransportSettings settings) |
| | | 72 | | { |
| | 4 | 73 | | if (settings == null) |
| | | 74 | | { |
| | 0 | 75 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(settings)); |
| | | 76 | | } |
| | | 77 | | |
| | 4 | 78 | | settings.TransportUsage = TransportUsage; |
| | 4 | 79 | | settings.CreateNotificationOnConnection = CreateNotificationOnConnection; |
| | 4 | 80 | | settings.KeepAliveInterval = KeepAliveInterval; |
| | 4 | 81 | | settings.SubProtocol = string.IsNullOrEmpty(SubProtocol) ? null : SubProtocol; |
| | 4 | 82 | | settings.DisablePayloadMasking = DisablePayloadMasking; |
| | 4 | 83 | | settings.MaxPendingConnections = MaxPendingConnections; |
| | 4 | 84 | | } |
| | | 85 | | } |
| | | 86 | | } |