Exemple #1
0
        public void Start()
        {
            _host = new WebHostBuilder()
                    .UseKestrel()
                    .UseContentRoot(Directory.GetCurrentDirectory())
                    .UseUrls("http://localhost:5250")

                    .Configure(app =>
            {
                app.UseWebSockets();

                app.Use(async(http, next) =>
                {
                    if (http.WebSockets.IsWebSocketRequest)
                    {
                        await _webSockets.HandleSocket(http, markActiveConnection).ConfigureAwait(false);
                    }
                    else
                    {
                        await next().ConfigureAwait(false);
                    }
                });

                app.Run(async http =>
                {
                    http.Response.StatusCode  = 200;
                    http.Response.ContentType = "text/plain";
                    await http.Response.WriteAsync($"Nothing to see here at {DateTime.Now}.");
                });
            }).Build();

            _host.Start();
        }
Exemple #2
0
        private void startWebServer(string hostname, int port, WebSocketsHandler webSockets)
        {
#if NET46
            var baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
#else
            var baseDirectory = AppContext.BaseDirectory;
#endif
            var hostBuilder = new WebHostBuilder()
                              .UseKestrel()
                              .UseContentRoot(baseDirectory)
                              .Configure(app =>
            {
                app.UseWebSockets();

                app.Use(async(http, next) =>
                {
                    if (http.WebSockets.IsWebSocketRequest)
                    {
                        await webSockets.HandleSocket(http).ConfigureAwait(false);
                    }
                    else
                    {
                        await next().ConfigureAwait(false);
                    }
                });

#if DEBUG
                configureStaticFiles(app);
#endif

                app.Run(async http =>
                {
                    if (http.Request.Path == "/favicon.ico")
                    {
                        await writeFavicon(http).ConfigureAwait(false);

                        return;
                    }

                    try
                    {
                        http.Response.ContentType = "text/html";

                        await HomeEndpoint.BuildPage(http.Response, _application, _input).ConfigureAwait(false);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.ToString());
                        throw;
                    }
                });
            });

            _server = hostBuilder.Start($"http://{hostname}:{port}");
        }
        public void Start()
        {
            Controller = _input.BuildRemoteController();
            var context = new StorytellerContext(Controller, _input);

            Controller.AssertValid();


            context.Start();

            var port = PortFinder.FindPort(5000);

            if (_input.WebSocketAddressFlag.IsNotEmpty())
            {
                port = new Uri(_input.WebSocketAddressFlag).Port;
            }


            BaseAddress = "http://localhost:" + port;

            var webSockets = new WebSocketsHandler();


            var webSocketsAddress = $"ws://127.0.0.1:{port}";

            // TODO -- fugly as hell. Either do it all the SM way, or rip out SM
            var registry = new WebApplicationRegistry(webSocketsAddress, webSockets, Controller, context);

            _container = new Container(registry);



            var baseDirectory = AppContext.BaseDirectory;
            var host          = new WebHostBuilder()
                                .UseKestrel()
                                .UseContentRoot(baseDirectory)
                                .UseUrls($"http://localhost:{port}")
                                .Configure(app =>
            {
                app.UseWebSockets();

                app.Use(async(http, next) =>
                {
                    if (http.WebSockets.IsWebSocketRequest)
                    {
                        await webSockets.HandleSocket(http).ConfigureAwait(false);
                    }
                    else
                    {
                        await next().ConfigureAwait(false);
                    }
                });

                app.UseStaticFiles(new StaticFileOptions
                {
                    ServeUnknownFileTypes = true,
                    FileProvider          = new PhysicalFileProvider(baseDirectory)
                });

                app.Run(async(http) =>
                {
                    var endpoint = _container.GetInstance <HomeEndpoint>();
                    var html     = endpoint.Index().ToString();

                    http.Response.ContentType = "text/html";
                    await http.Response.WriteAsync(html).ConfigureAwait(false);
                });
            });

            _server = host.Start();


            Controller.AddListener(_container.GetInstance <IClientConnector>());

            _container.GetInstance <AssetFileWatcher>().Start();

            var persistence = _container.GetInstance <IPersistenceController>();

            persistence.StartWatching(context.SpecPath);
            context.AddRemoteListener(persistence);
        }