public static IApplicationBuilder UseDiagnostics(
            this IApplicationBuilder app,
            DiagnosticsSettings options)
        {
            app.UseWebSockets();

            if (options.Mode == DiagnosticsMode.Production)
            {
                var assembly = typeof(DiagnosticsMiddleware).GetTypeInfo().Assembly;
                var provider = new EmbeddedFileProvider(assembly, $"{assembly.GetName().Name}.resources");

                app.UseStaticFiles(new StaticFileOptions()
                {
                    FileProvider = provider,
                    RequestPath  = new PathString($"{options.BasePath}{DiagnosticsMiddleware.Resource_Root}")
                });
            }

            var hub     = app.ApplicationServices.GetService <IMessagingHub>();
            var manager = app.ApplicationServices.GetService <ISocketConnectionManager>();

            app.MapWebSocket($"{options.BasePath}/ws",
                             new SocketConnection((socket, text) => {
                Console.WriteLine("Socket: {0}", text);
                hub.SendJson(text);
                return(Task.CompletedTask);
            }),
                             manager);

            app.UseMiddleware <DiagnosticsMiddleware>(options);

            return(app);
        }
        public static IApplicationBuilder UseDiagnostics(
            this IApplicationBuilder app,
            Action <DiagnosticsSettings> configure = null)
        {
            var options = new DiagnosticsSettings();

            configure?.Invoke(options);
            return(UseDiagnostics(app, options));
        }
Exemple #3
0
        public void Start(DiagnosticsSettings settings, IContainer container)
        {
            _settings = settings;

            var url = $"http://localhost:{settings.WebsocketPort}";

            Console.WriteLine($"Diagnostics listening on {url}");
            _host = new WebHostBuilder()
                    .UseKestrel()
                    .UseContentRoot(Directory.GetCurrentDirectory())
                    .UseUrls(url)
                    .UseStructureMap(container)
                    .UseStartup <DiagnosticsServerStartup>()
                    .Build();

            _host.Start();
        }
Exemple #4
0
        public static IApplicationBuilder UseDiagnostics(
            this IApplicationBuilder app,
            DiagnosticsSettings options)
        {
            app.UseJasperWebSockets();

            var assembly = typeof(DiagnosticsMiddleware).GetTypeInfo().Assembly;
            var provider = new EmbeddedFileProvider(assembly, $"{assembly.GetName().Name}.resources");

            app.UseStaticFiles(new StaticFileOptions()
            {
                FileProvider = provider,
                RequestPath  = options.BasePath
            });

            app.UseMiddleware <DiagnosticsMiddleware>(options);

            return(app);
        }
 public DiagnosticsMiddleware(RequestDelegate next, DiagnosticsSettings settings)
 {
     _next     = next;
     _settings = settings;
     _assets   = new WebpackAssetCache();
 }