Ejemplo n.º 1
0
        public OverseerBootstrapper(IDataContext context)
        {
            _context = context;

            var applicationSettings = _context.GetApplicationSettings();

            _monitoringService = new MonitoringService(applicationSettings.Interval, () =>
            {
                var providerManager = Container.Resolve <PrinterProviderManager>();
                return(providerManager.GetPrinterProviders());
            });

            _monitoringService.StatusUpdate += (sender, args) =>
            {
                StatusHub.PushStatusUpdate(args.Status);
            };
        }
Ejemplo n.º 2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, OverseerBootstrapper bootstrapper, IHubContext <StatusHub> statusHub)
        {
            bootstrapper.Container.Register <Action <MachineStatus> >((c, n) =>
            {
                return(status => StatusHub.PushStatusUpdate(statusHub, status));
            });

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseSpaStaticFiles();

            app.Map("/api", builder =>
            {
                builder.UseAuthentication();
                builder.UseOwin(owin => owin.UseNancy(options => options.Bootstrapper = bootstrapper));
            });

            app.Map("/push", builder =>
            {
                builder.UseSignalR(routes =>
                {
                    routes.MapHub <StatusHub>("/status");
                });
            });

            app.UseSpa(spa =>
            {
                if (env.IsDevelopment())
                {
                    spa.Options.SourcePath = "../OverseerUI";
                    spa.UseAngularCliServer(npmScript: "start");
                }
                else
                {
                    spa.Options.SourcePath = "/OverseerUI";
                }
            });
        }
Ejemplo n.º 3
0
        public static void Start(string endpoint, OverseerBootstrapper bootstrapper)
        {
            Log.Info("Starting Server...");

            bootstrapper.Container.Register <StatusHubService>();
            bootstrapper.Container.Register <Action <MachineStatus> >(s => StatusHub.PushStatusUpdate(s));

            GlobalHost.DependencyResolver.Register(typeof(StatusHub), () =>
            {
                return(bootstrapper.Container.Resolve <StatusHub>());
            });

            GlobalHost.DependencyResolver.Register(typeof(JsonSerializer), () =>
            {
                return(new JsonSerializer
                {
                    ContractResolver = new OverseerContractResolver(),
                    Formatting = Formatting.None
                });
            });

            WebApp.Start(endpoint, app =>
            {
                app.UseOverseerAuthentication(bootstrapper.Container);

                app.MapSignalR("/push", new HubConfiguration
                {
                    EnableDetailedErrors    = true,
                    EnableJavaScriptProxies = true,
                    EnableJSONP             = false
                });

                app.Map("/api", a =>
                {
                    a.UseNancy(new NancyOptions {
                        Bootstrapper = bootstrapper
                    });
                });

                /*
                 * This is needed to support client side routing without the use of hash bang urls.
                 * If the request wasn't for a file, an api request, or a signalr request then redirect to the root to be handled by index.html
                 */
                app.Use(async(IOwinContext context, Func <Task> next) =>
                {
                    await next.Invoke();

                    if (context.Response.StatusCode == 404 &&
                        !Path.HasExtension(context.Request.Path.Value) &&
                        !context.Request.Path.Value.StartsWith("/push") &&
                        !context.Request.Path.Value.StartsWith("/api"))
                    {
                        context.Request.Path = new PathString("/index.html");
                        await next.Invoke();
                    }
                });

                app.UseFileServer(new FileServerOptions
                {
                    EnableDirectoryBrowsing = false,
                    EnableDefaultFiles      = true,
                    DefaultFilesOptions     = { DefaultFileNames = { "index.html" } },
                    FileSystem        = new PhysicalFileSystem(ClientPath),
                    StaticFileOptions = { ContentTypeProvider = new OverseerContentTypeProvider() }
                });
            });

            Log.Info($"Listening at {endpoint}...");
        }