| | | 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 CoreWCF.Channels.Framing; |
| | | 6 | | |
| | | 7 | | namespace CoreWCF.Configuration |
| | | 8 | | { |
| | | 9 | | /// <summary> |
| | | 10 | | /// Extension methods for the <see cref="MapMiddleware"/>. |
| | | 11 | | /// </summary> |
| | | 12 | | public static class MapExtensions |
| | | 13 | | { |
| | | 14 | | /// <summary> |
| | | 15 | | /// Branches the handshake pipeline based on the result of a predicate. |
| | | 16 | | /// If the predicate returns true the branch is executed. |
| | | 17 | | /// </summary> |
| | | 18 | | /// <param name="handshakeBuilder">The <see cref="IFramingConnectionHandshakeBuilder"/> instance.</param> |
| | | 19 | | /// <param name="predicate">The request path to match.</param> |
| | | 20 | | /// <param name="configuration">The branch to take for positive path matches.</param> |
| | | 21 | | /// <returns>The <see cref="IFramingConnectionHandshakeBuilder"/> instance.</returns> |
| | | 22 | | public static IFramingConnectionHandshakeBuilder Map(this IFramingConnectionHandshakeBuilder handshakeBuilder, F |
| | | 23 | | { |
| | 166 | 24 | | if (handshakeBuilder == null) |
| | | 25 | | { |
| | 0 | 26 | | throw new ArgumentNullException(nameof(handshakeBuilder)); |
| | | 27 | | } |
| | | 28 | | |
| | 166 | 29 | | if (configuration == null) |
| | | 30 | | { |
| | 0 | 31 | | throw new ArgumentNullException(nameof(configuration)); |
| | | 32 | | } |
| | | 33 | | |
| | 166 | 34 | | if (predicate == null) |
| | | 35 | | { |
| | 0 | 36 | | throw new ArgumentNullException(nameof(predicate)); |
| | | 37 | | } |
| | | 38 | | |
| | | 39 | | // create branch |
| | 166 | 40 | | IFramingConnectionHandshakeBuilder branchBuilder = handshakeBuilder.New(); |
| | 166 | 41 | | configuration(branchBuilder); |
| | 166 | 42 | | HandshakeDelegate branch = branchBuilder.Build(); |
| | | 43 | | |
| | 166 | 44 | | var options = new MapOptions |
| | 166 | 45 | | { |
| | 166 | 46 | | Branch = branch, |
| | 166 | 47 | | Predicate = predicate, |
| | 166 | 48 | | }; |
| | 332 | 49 | | return handshakeBuilder.Use(next => new MapMiddleware(next, options).Invoke); |
| | | 50 | | } |
| | | 51 | | } |
| | | 52 | | } |