Пример #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app,
                              IOptions <SuperDumpSettings> settings,
                              IServiceProvider serviceProvider,
                              SlackNotificationService sns,
                              IAuthorizationHelper authorizationHelper,
                              ILoggerFactory loggerFactory)
        {
            Task.Run(async() => await app.ApplicationServices.GetService <BundleRepository>().Populate());
            Task.Run(async() => await app.ApplicationServices.GetService <RelationshipRepository>().Populate());
            Task.Run(async() => await app.ApplicationServices.GetService <IdenticalDumpRepository>().Populate());
            if (settings.Value.UseJiraIntegration)
            {
                Task.Run(async() => await app.ApplicationServices.GetService <JiraIssueRepository>().Populate());
            }

            if (settings.Value.UseHttpsRedirection)
            {
                app.UseHttpsRedirection();
            }

            app.UseStaticFiles();
            app.UseRouting();

            if (settings.Value.UseLdapAuthentication)
            {
                app.UseAuthentication();
                app.UseAuthorization();
                app.UseSwaggerAuthorizationMiddleware(authorizationHelper);
            }
            else
            {
                app.UseAuthorization();
                app.MapWhen(context => context.Request.Path.StartsWithSegments("/Login") || context.Request.Path.StartsWithSegments("/api/Token"),
                            appBuilder => appBuilder.Run(async context => {
                    context.Response.StatusCode = 404;
                    await context.Response.WriteAsync("");
                }));
            }

            if (settings.Value.UseAllRequestLogging)
            {
                ILogger logger = loggerFactory.CreateLogger("SuperDumpServiceRequests");
                app.Use(async(context, next) => {
                    logger.LogRequest(context);
                    await next.Invoke();
                });
            }

            app.UseHangfireDashboard("/hangfire", new DashboardOptions {
                Authorization = new[] { new CustomAuthorizeFilter(authorizationHelper) }
            });

            app.UseHangfireServer(new BackgroundJobServerOptions {
                Queues      = new[] { "download" },
                WorkerCount = settings.Value.MaxConcurrentBundleExtraction
            });
            app.UseHangfireServer(new BackgroundJobServerOptions {
                Queues      = new[] { "analysis" },
                WorkerCount = settings.Value.MaxConcurrentAnalysis
            });
            app.UseHangfireServer(new BackgroundJobServerOptions {
                Queues      = new[] { "elasticsearch" },
                WorkerCount = 1
            });
            app.UseHangfireServer(new BackgroundJobServerOptions {
                Queues      = new[] { "retention" },
                WorkerCount = 1
            });
            app.UseHangfireServer(new BackgroundJobServerOptions {
                Queues      = new[] { "similarityanalysis" },
                WorkerCount = 8
            });
            if (settings.Value.UseJiraIntegration)
            {
                app.UseHangfireServer(new BackgroundJobServerOptions {
                    Queues      = new[] { "jirastatus" },
                    WorkerCount = 2
                });

                JiraIssueRepository jiraIssueRepository = app.ApplicationServices.GetService <JiraIssueRepository>();
                jiraIssueRepository.StartRefreshHangfireJob();
                jiraIssueRepository.StartBundleSearchHangfireJob();
            }
            app.ApplicationServices.GetService <DumpRetentionService>().StartService();
            if (settings.Value.UseAmazonSqs)
            {
                app.UseHangfireServer(new BackgroundJobServerOptions {
                    Queues      = new[] { "amazon-sqs-poll" },
                    WorkerCount = 2
                });
                AmazonSqsPollingService amazonSqsService = app.ApplicationServices.GetService <AmazonSqsPollingService>();
                amazonSqsService.StartHangfireJob();
            }

            GlobalJobFilters.Filters.Add(new AutomaticRetryAttribute {
                Attempts = 0
            });

            app.UseSwagger();
            app.UseSwaggerUI(c => {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
            });
            app.UseHealthChecks("/healthcheck");

            LogProvider.SetCurrentLogProvider(new ColouredConsoleLogProvider());

            if (env.EnvironmentName == "Development")
            {
                app.UseDeveloperExceptionPage();
                BrowserLinkExtensions.UseBrowserLink(app);                 // using the extension method directly somehow did not work in .NET Core 2.0 (ambiguous extension method)
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseWebSockets();
            app.MapWebSocketManager("/cmd", serviceProvider.GetService <WebTermHandler>());

            //app.UseMvcWithDefaultRoute();
            //app.UseMvc();
            app.UseEndpoints(endpoints => {
                endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");
            });
        }
Пример #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, ILoggerFactory loggerFactory, IOptions <SuperDumpSettings> settings, IServiceProvider serviceProvider, SlackNotificationService sns)
        {
            app.ApplicationServices.GetService <BundleRepository>().Populate();
            app.ApplicationServices.GetService <DumpRepository>().Populate();

            //foreach(var b in app.ApplicationServices.GetService<BundleRepository>().GetAll()) {
            //	foreach(var d in app.ApplicationServices.GetService<DumpRepository>().Get(b.BundleId)) {
            //		var msg = sns.GetMessage2(d);
            //		Console.WriteLine(msg);
            //	}
            //}

            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            app.UseHangfireDashboard("/hangfire", new DashboardOptions {
                Authorization = new[] { new CustomAuthorizeFilter() }
            });

            app.UseHangfireServer(new BackgroundJobServerOptions {
                Queues      = new[] { "download" },
                WorkerCount = settings.Value.MaxConcurrentBundleExtraction
            });
            app.UseHangfireServer(new BackgroundJobServerOptions {
                Queues      = new[] { "analysis" },
                WorkerCount = settings.Value.MaxConcurrentAnalysis
            });
            app.UseHangfireServer(new BackgroundJobServerOptions {
                Queues      = new[] { "elasticsearch" },
                WorkerCount = 1
            });
            app.UseHangfireServer(new BackgroundJobServerOptions {
                Queues      = new[] { "retention" },
                WorkerCount = 1
            });

            app.ApplicationServices.GetService <DumpRetentionService>().StartService();

            GlobalJobFilters.Filters.Add(new AutomaticRetryAttribute {
                Attempts = 0
            });

            app.UseSwagger();
            app.UseSwaggerUi();

            LogProvider.SetCurrentLogProvider(new ColouredConsoleLogProvider());

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                BrowserLinkExtensions.UseBrowserLink(app);                 // using the extension method directly somehow did not work in .NET Core 2.0 (ambiguous extension method)
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            app.UseWebSockets();
            app.MapWebSocketManager("/cmd", serviceProvider.GetService <WebTermHandler>());

            app.UseMvc(routes => {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
Пример #3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IOptions <SuperDumpSettings> settings, IServiceProvider serviceProvider, SlackNotificationService sns, IAuthorizationHelper authorizationHelper)
        {
            app.ApplicationServices.GetService <BundleRepository>().Populate();
            app.ApplicationServices.GetService <DumpRepository>().Populate();
            Task.Run(async() => await app.ApplicationServices.GetService <RelationshipRepository>().Populate());

            // configure Logger
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));

            var fileLogConfig = Configuration.GetSection("FileLogging");
            var logPath       = Path.GetDirectoryName(fileLogConfig.GetValue <string>("PathFormat"));

            Directory.CreateDirectory(logPath);
            loggerFactory.AddFile(Configuration.GetSection("FileLogging"));
            loggerFactory.AddFile(Configuration.GetSection("RequestFileLogging"));
            loggerFactory.AddDebug();


            if (settings.Value.UseHttpsRedirection)
            {
                app.UseHttpsRedirection();
            }
            if (settings.Value.UseLdapAuthentication)
            {
                app.UseAuthentication();
                app.UseSwaggerAuthorizationMiddleware(authorizationHelper);                //TODO remove?
            }
            else
            {
                app.MapWhen(context => context.Request.Path.StartsWithSegments("/Login") || context.Request.Path.StartsWithSegments("/api/Token"),                //TODO find other way to make the Login controller inaccessible
                            appBuilder => appBuilder.Run(async context => {
                    context.Response.StatusCode = 404;
                    await context.Response.WriteAsync("");
                }));
            }

            ILogger logger = loggerFactory.CreateLogger("SuperDumpServiceRequests");

            app.Use(async(context, next) => {
                logger.LogRequest(context);
                await next.Invoke();
            });

            app.UseHangfireDashboard("/hangfire", new DashboardOptions {
                Authorization = new[] { new CustomAuthorizeFilter(authorizationHelper) }
            });

            app.UseHangfireServer(new BackgroundJobServerOptions {
                Queues      = new[] { "download" },
                WorkerCount = settings.Value.MaxConcurrentBundleExtraction
            });
            app.UseHangfireServer(new BackgroundJobServerOptions {
                Queues      = new[] { "analysis" },
                WorkerCount = settings.Value.MaxConcurrentAnalysis
            });
            app.UseHangfireServer(new BackgroundJobServerOptions {
                Queues      = new[] { "elasticsearch" },
                WorkerCount = 1
            });
            app.UseHangfireServer(new BackgroundJobServerOptions {
                Queues      = new[] { "retention" },
                WorkerCount = 1
            });
            app.UseHangfireServer(new BackgroundJobServerOptions {
                Queues      = new[] { "similarityanalysis" },
                WorkerCount = 8
            });

            app.ApplicationServices.GetService <DumpRetentionService>().StartService();

            GlobalJobFilters.Filters.Add(new AutomaticRetryAttribute {
                Attempts = 0
            });

            app.UseSwagger();
            app.UseSwaggerUi();

            LogProvider.SetCurrentLogProvider(new ColouredConsoleLogProvider());

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                BrowserLinkExtensions.UseBrowserLink(app);                 // using the extension method directly somehow did not work in .NET Core 2.0 (ambiguous extension method)
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            app.UseWebSockets();
            app.MapWebSocketManager("/cmd", serviceProvider.GetService <WebTermHandler>());

            app.UseMvcWithDefaultRoute();
        }
Пример #4
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IOptions <SuperDumpSettings> settings, IServiceProvider serviceProvider, SlackNotificationService sns)
        {
            app.ApplicationServices.GetService <BundleRepository>().Populate();
            app.ApplicationServices.GetService <DumpRepository>().Populate();
            Task.Run(async() => await app.ApplicationServices.GetService <RelationshipRepository>().Populate());

            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            app.UseHangfireDashboard("/hangfire", new DashboardOptions {
                Authorization = new[] { new CustomAuthorizeFilter() }
            });

            app.UseHangfireServer(new BackgroundJobServerOptions {
                Queues      = new[] { "download" },
                WorkerCount = settings.Value.MaxConcurrentBundleExtraction
            });
            app.UseHangfireServer(new BackgroundJobServerOptions {
                Queues      = new[] { "analysis" },
                WorkerCount = settings.Value.MaxConcurrentAnalysis
            });
            app.UseHangfireServer(new BackgroundJobServerOptions {
                Queues      = new[] { "elasticsearch" },
                WorkerCount = 1
            });
            app.UseHangfireServer(new BackgroundJobServerOptions {
                Queues      = new[] { "retention" },
                WorkerCount = 1
            });
            app.UseHangfireServer(new BackgroundJobServerOptions {
                Queues      = new[] { "similarityanalysis" },
                WorkerCount = 8
            });

            app.ApplicationServices.GetService <DumpRetentionService>().StartService();

            GlobalJobFilters.Filters.Add(new AutomaticRetryAttribute {
                Attempts = 0
            });

            app.UseSwagger();
            app.UseSwaggerUi();

            LogProvider.SetCurrentLogProvider(new ColouredConsoleLogProvider());

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                BrowserLinkExtensions.UseBrowserLink(app);                 // using the extension method directly somehow did not work in .NET Core 2.0 (ambiguous extension method)
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            app.UseWebSockets();
            app.MapWebSocketManager("/cmd", serviceProvider.GetService <WebTermHandler>());

            app.UseMvcWithDefaultRoute();
        }