| | | 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 | | using System; |
| | | 6 | | |
| | | 7 | | namespace CoreWCF.Channels |
| | | 8 | | { |
| | | 9 | | public class NetTcpOptions |
| | | 10 | | { |
| | 240 | 11 | | internal List<TcpListenOptions> CodeBackedListenOptions { get; } = new List<TcpListenOptions>(); |
| | 80 | 12 | | public IServiceProvider ApplicationServices { get; internal set; } |
| | | 13 | | |
| | | 14 | | public void Listen(string baseAddress) |
| | | 15 | | { |
| | | 16 | | try |
| | | 17 | | { |
| | 0 | 18 | | var baseAddressUri = new Uri(baseAddress); |
| | 0 | 19 | | Listen(new Uri(baseAddress)); |
| | 0 | 20 | | } |
| | 0 | 21 | | catch(UriFormatException ufe) |
| | | 22 | | { |
| | 0 | 23 | | throw new CommunicationException($"Unable to parse base address {baseAddress}", ufe); |
| | | 24 | | } |
| | 0 | 25 | | } |
| | | 26 | | |
| | 150 | 27 | | public void Listen(Uri baseAddress) => Listen(baseAddress, _ => { }); |
| | | 28 | | |
| | 5 | 29 | | public void Listen(string baseAddress, Action<TcpListenOptions> configure) => Listen(new Uri(baseAddress), confi |
| | | 30 | | |
| | | 31 | | public void Listen(Uri baseAddress, Action<TcpListenOptions> configure) |
| | | 32 | | { |
| | 80 | 33 | | if (baseAddress == null) throw new ArgumentNullException(nameof(baseAddress)); |
| | 80 | 34 | | if (configure == null) throw new ArgumentNullException(nameof(configure)); |
| | | 35 | | |
| | 80 | 36 | | var listenOptions = new TcpListenOptions(baseAddress); |
| | 80 | 37 | | ApplyEndpointDefaults(listenOptions); |
| | 80 | 38 | | configure(listenOptions); |
| | 80 | 39 | | CodeBackedListenOptions.Add(listenOptions); |
| | 80 | 40 | | } |
| | | 41 | | |
| | | 42 | | private void ApplyEndpointDefaults(TcpListenOptions listenOptions) |
| | | 43 | | { |
| | 80 | 44 | | listenOptions.NetTcpServerOptions = this; |
| | 80 | 45 | | } |
| | | 46 | | } |
| | | 47 | | } |