コード例 #1
0
        internal static UriPrefixTable <HandshakeDelegate> BuildAddressTable(IServiceProvider services)
        {
            ILogger <NetMessageFramingConnectionHandler> logger = services.GetRequiredService <ILogger <NetMessageFramingConnectionHandler> >();
            IServiceBuilder    serviceBuilder    = services.GetRequiredService <IServiceBuilder>();
            IDispatcherBuilder dispatcherBuilder = services.GetRequiredService <IDispatcherBuilder>();
            var addressTable = new UriPrefixTable <HandshakeDelegate>();

            foreach (Type serviceType in serviceBuilder.Services)
            {
                List <IServiceDispatcher> dispatchers = dispatcherBuilder.BuildDispatchers(serviceType);
                foreach (IServiceDispatcher dispatcher in dispatchers)
                {
                    if (dispatcher.BaseAddress == null)
                    {
                        // TODO: Should we throw? Ignore?
                        continue;
                    }

                    // TODO: Limit to specifically TcpTransportBindingElement if net.tcp etc
                    BindingElementCollection be = dispatcher.Binding.CreateBindingElements();
                    ConnectionOrientedTransportBindingElement cotbe = be.Find <ConnectionOrientedTransportBindingElement>();
                    if (cotbe == null)
                    {
                        // TODO: Should we throw? Ignore?
                        continue;
                    }

                    HandshakeDelegate handshake = BuildHandshakeDelegateForDispatcher(dispatcher);
                    logger.LogDebug($"Registering URI {dispatcher.BaseAddress} with NetMessageFramingConnectionHandler");
                    addressTable.RegisterUri(dispatcher.BaseAddress, cotbe.HostNameComparisonMode, handshake);
                }
            }

            return(addressTable);
        }
コード例 #2
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));
        }
コード例 #3
0
 private HandshakeDelegate BuildHandshake(IFramingConnectionHandshakeBuilder handshakeBuilder)
 {
     handshakeBuilder.UseMiddleware <FramingModeHandshakeMiddleware>();
     handshakeBuilder.Map(connection => connection.FramingMode == FramingMode.Duplex,
                          configuration =>
     {
         configuration.UseMiddleware <DuplexFramingMiddleware>();
         configuration.Use(next => async(connection) =>
         {
             UriPrefixTable <HandshakeDelegate> addressTable = configuration.HandshakeServices.GetRequiredService <UriPrefixTable <HandshakeDelegate> >();
             HandshakeDelegate serviceHandshake = GetServiceHandshakeDelegate(addressTable, connection.Via);
             await serviceHandshake(connection);
             await next(connection);
         });
         configuration.UseMiddleware <ServerFramingDuplexSessionMiddleware>();
         configuration.UseMiddleware <ServerSessionConnectionReaderMiddleware>();
     });
     handshakeBuilder.Map(connection => connection.FramingMode == FramingMode.Singleton,
                          configuration =>
     {
         configuration.UseMiddleware <SingletonFramingMiddleware>();
         configuration.Use(next => async(connection) =>
         {
             UriPrefixTable <HandshakeDelegate> addressTable = configuration.HandshakeServices.GetRequiredService <UriPrefixTable <HandshakeDelegate> >();
             HandshakeDelegate serviceHandshake = GetServiceHandshakeDelegate(addressTable, connection.Via);
             await serviceHandshake(connection);
             await next(connection);
         });
         configuration.UseMiddleware <ServerFramingSingletonMiddleware>();
         configuration.UseMiddleware <ServerSingletonConnectionReaderMiddleware>();
     });
     return(handshakeBuilder.Build());
 }
コード例 #4
0
 public NetMessageFramingConnectionHandler(IServiceBuilder serviceBuilder, IDispatcherBuilder dispatcherBuilder, IFramingConnectionHandshakeBuilder handshakeBuilder)
 {
     _serviceBuilder        = serviceBuilder;
     _dispatcherBuilder     = dispatcherBuilder;
     _handshake             = BuildHandshake(handshakeBuilder);
     _services              = handshakeBuilder.HandshakeServices;
     serviceBuilder.Opened += OnServiceBuilderOpened;
 }
コード例 #5
0
        public void addHandshakeCompleteListener(HandshakeDelegate handshakeDelegate)
        {
            if (_handshakeComplete)
            {
                handshakeDelegate(_handshake);
                return;
            }

            _handshakeListeners.Add(handshakeDelegate);
        }
コード例 #6
0
        public HandshakeDelegate Build()
        {
            HandshakeDelegate app = context =>
            {
                return(Task.CompletedTask);
            };

            foreach (var component in _components.Reverse())
            {
                app = component(app);
            }

            return(app);
        }
コード例 #7
0
        internal static HandshakeDelegate GetServiceHandshakeDelegate(UriPrefixTable <HandshakeDelegate> addressTable, Uri via)
        {
            HandshakeDelegate handshake = null;

            if (addressTable.TryLookupUri(via, HostNameComparisonMode.StrongWildcard, out handshake))
            {
                return(handshake);
            }

            if (addressTable.TryLookupUri(via, HostNameComparisonMode.Exact, out handshake))
            {
                return(handshake);
            }

            addressTable.TryLookupUri(via, HostNameComparisonMode.WeakWildcard, out handshake);
            return(handshake);
        }
コード例 #8
0
 public DuplexFramingMiddleware(HandshakeDelegate next)
 {
     _next = next;
 }
コード例 #9
0
 public ServerFramingSingletonMiddleware(HandshakeDelegate next)
 {
     _next = next;
 }
コード例 #10
0
ファイル: MapMiddleware.cs プロジェクト: wpenbert/CoreWCF
 /// <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));
 }
コード例 #11
0
 public ServerFramingDuplexSessionMiddleware(HandshakeDelegate next)
 {
     _next = next;
 }
コード例 #12
0
 public FramingModeHandshakeMiddleware(HandshakeDelegate next)
 {
     _next = next;
 }
コード例 #13
0
 public FramingModeHandshakeMiddleware(HandshakeDelegate next, IApplicationLifetime appLifetime)
 {
     _next        = next;
     _appLifetime = appLifetime;
 }
コード例 #14
0
 public NetMessageFramingConnectionHandler(IServiceBuilder serviceBuilder, IDispatcherBuilder dispatcherBuilder, IFramingConnectionHandshakeBuilder handshakeBuilder)
 {
     _serviceBuilder    = serviceBuilder;
     _dispatcherBuilder = dispatcherBuilder;
     _handshake         = BuildHandshake(handshakeBuilder);
 }
コード例 #15
0
 public ServerSingletonConnectionReaderMiddleware(HandshakeDelegate next, IServiceScopeFactory servicesScopeFactory)
 {
     _next = next;
     _servicesScopeFactory = servicesScopeFactory;
 }
コード例 #16
0
 public SingletonFramingMiddleware(HandshakeDelegate next)
 {
     _next = next;
 }
コード例 #17
0
 public ServerSessionConnectionReaderMiddleware(HandshakeDelegate next, IServiceScopeFactory servicesScopeFactory, IApplicationLifetime appLifetime)
 {
     _next = next;
     _servicesScopeFactory = servicesScopeFactory;
     _appLifetime          = appLifetime;
 }