Example #1
0
        /// <summary>
        /// Branches the handshake pipeline based on the result of a predicate.
        /// If the predicate returns true the branch is executed.
        /// </summary>
        /// <param name="handshakeBuilder">The <see cref="IFramingConnectionHandshakeBuilder"/> instance.</param>
        /// <param name="predicate">The request path to match.</param>
        /// <param name="configuration">The branch to take for positive path matches.</param>
        /// <returns>The <see cref="IFramingConnectionHandshakeBuilder"/> instance.</returns>
        public static IFramingConnectionHandshakeBuilder Map(this IFramingConnectionHandshakeBuilder handshakeBuilder, Func <FramingConnection, bool> predicate, Action <IFramingConnectionHandshakeBuilder> configuration)
        {
            if (handshakeBuilder == null)
            {
                throw new ArgumentNullException(nameof(handshakeBuilder));
            }

            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            if (predicate == null)
            {
                throw new ArgumentNullException(nameof(predicate));
            }

            // create branch
            IFramingConnectionHandshakeBuilder branchBuilder = handshakeBuilder.New();

            configuration(branchBuilder);
            HandshakeDelegate branch = branchBuilder.Build();

            var options = new MapOptions
            {
                Branch    = branch,
                Predicate = predicate,
            };

            return(handshakeBuilder.Use(next => new MapMiddleware(next, options).Invoke));
        }
Example #2
0
 /// <summary>
 /// Creates a new instance of <see cref="MapMiddleware"/>.
 /// </summary>
 /// <param name="next">The delegate representing the next middleware in the request pipeline.</param>
 /// <param name="options">The middleware options.</param>
 public MapMiddleware(HandshakeDelegate next, MapOptions options)
 {
     _next    = next ?? throw new ArgumentNullException(nameof(next));
     _options = options ?? throw new ArgumentNullException(nameof(options));
 }