Пример #1
0
        public void Configure(
            IApplicationBuilder app,
            IHostingEnvironment env,
            LifetimeManager lifetimeManager,
            InterpreterManager interpreterManager,
            SecurityManager securityManager
            )
        {
            lifetimeManager.Initialize();
            interpreterManager.Initialize();

            app.UseWebSockets(new WebSocketOptions {
                ReplaceFeature    = true,
                KeepAliveInterval = TimeSpan.FromMilliseconds(1000000000),
                ReceiveBufferSize = 0x10000
            });

            var routeBuilder = new RouteBuilder(app, new RouteHandler(RemoteUriHelper.HandlerAsync));

            routeBuilder.MapRoute("help_and_shiny", "remoteuri");
            app.UseRouter(routeBuilder.Build());

            app.UseBasicAuthentication(options => {
                options.Events = new BasicEvents {
                    OnSignIn = securityManager.SignInAsync
                };
            });

            app.Use((context, next) => {
                if (!context.User.Identity.IsAuthenticated)
                {
                    return(context.Authentication.ChallengeAsync());
                }
                else
                {
                    return(next());
                }
            });

            app.UseMvc();
        }
Пример #2
0
        public virtual void Configure(IApplicationBuilder app
                                      , IApplicationLifetime applicationLifetime
                                      , IHostingEnvironment env
                                      , IOptions <StartupOptions> startupOptions
                                      , ILogger <Startup> logger
                                      , LifetimeManager lifetimeManager
                                      , InterpreterManager interpreterManager
                                      , SecurityManager securityManager)
        {
            _logger = logger;
            var    serverAddresses = app.ServerFeatures.Get <IServerAddressesFeature>();
            string pipeName        = startupOptions.Value.WriteServerUrlsToPipe;

            if (pipeName != null)
            {
                NamedPipeClientStream pipe;
                try {
                    pipe = new NamedPipeClientStream(".", pipeName, PipeDirection.Out);
                    pipe.Connect(10000);
                } catch (IOException ex) {
                    logger.LogCritical(0, ex, Resources.Critical_InvalidPipeHandle, pipeName);
                    throw;
                } catch (TimeoutException ex) {
                    logger.LogCritical(0, ex, Resources.Critical_PipeConnectTimeOut, pipeName);
                    throw;
                }

                applicationLifetime.ApplicationStarted.Register(() => Task.Run(() => {
                    using (pipe) {
                        string serverUriStr = JsonConvert.SerializeObject(serverAddresses.Addresses);
                        logger.LogTrace(Resources.Trace_ServerUrlsToPipeBegin, pipeName, Environment.NewLine, serverUriStr);

                        var serverUriData = Encoding.UTF8.GetBytes(serverUriStr);
                        pipe.Write(serverUriData, 0, serverUriData.Length);
                        pipe.Flush();
                    }

                    logger.LogTrace(Resources.Trace_ServerUrlsToPipeDone, pipeName);
                }));
            }

            lifetimeManager.Initialize();
            interpreterManager.Initialize();

            app.UseWebSockets(new WebSocketOptions {
                ReplaceFeature    = true,
                KeepAliveInterval = TimeSpan.FromMilliseconds(1000000000),
                ReceiveBufferSize = 0x10000
            });

            var routeBuilder = new RouteBuilder(app, new RouteHandler(RemoteUriHelper.HandlerAsync));

            routeBuilder.MapRoute("help_and_shiny", "remoteuri");
            app.UseRouter(routeBuilder.Build());

            app.UseBasicAuthentication(options => options.Events = new BasicEvents {
                OnSignIn = securityManager.SignInAsync
            });

            app.Use((context, next) => context.User.Identity.IsAuthenticated
                ? next()
                : context.Authentication.ChallengeAsync());

            app.UseMvc();

            if (!startupOptions.Value.IsService)
            {
                applicationLifetime.ApplicationStopping.Register(ExitAfterTimeout);
            }
        }