コード例 #1
0
        public static IServiceProvider UseProxyWebSocket(this IServiceProvider serviceProvider, CancellationToken cancellationToken = default(CancellationToken))
        {
            IList <IWebSocketConnector> connectors = InvocatorFactory.GetConnectors(serviceProvider);

            foreach (var connector in connectors)
            {
                Task.Run(async() => await connector.ConnectAsync(cancellationToken));
            }

            return(serviceProvider);
        }
コード例 #2
0
        public static IApplicationBuilder UseProxyWebSockets(this IApplicationBuilder app, CancellationTokenSource cancellationTokenSource = null)
        {
            ThrowIfServiceNotRegistered(app.ApplicationServices);
            var appLifeTime = app.ApplicationServices.GetService <IApplicationLifetime>();
            IList <IWebSocketConnector> connectors = InvocatorFactory.GetConnectors(app.ApplicationServices);

            foreach (var connector in connectors)
            {
                appLifeTime.ApplicationStopping.Register(OnShutdown, connector);
                Task.Run(async() => await connector.ConnectAsync(cancellationTokenSource));
            }

            return(app);
        }
コード例 #3
0
        public static IApplicationBuilder UseProxyWebSockets(this IApplicationBuilder app, CancellationToken cancellationToken = default(CancellationToken))
        {
            ThrowIfServiceNotRegistered(app.ApplicationServices);
            var appLifeTime = app.ApplicationServices.GetService <IApplicationLifetime>();
            IList <IWebSocketConnector> connectors = InvocatorFactory.GetConnectors(app.ApplicationServices);

            foreach (var connector in connectors)
            {
                InvocatorsHelper.EnsureHostPair(connector.InvocatorContext);
                appLifeTime.ApplicationStopping.Register(OnShutdown, connector);
                Task.Factory.StartNew(async() => await connector.ConnectAsync(cancellationToken), TaskCreationOptions.LongRunning);
            }

            return(app);
        }
コード例 #4
0
 public static ProxyWebSocketsBuilder AddProxyWebSockets(this IServiceCollection services)
 {
     services.AddSingleton <IWebSocketConnector>(_ => InvocatorFactory.GetConnectors(_).First());
     AddProxyWebSocketsInternal(services);
     return(new ProxyWebSocketsBuilder(services));
 }