public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ApplicationHandler appHandler) { SnLog.WriteInformation("Starting TaskManagement.Web", EventId.TaskManagement.Lifecycle); // make Web API use the standard ASP.NET error configuration //ConfigureErrorHandling(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); //TODO: inject allowed origins dynamically (do not allow everything) app.UseCors("AllowAllOrigins"); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "TaskManagementApi", pattern: "api/{controller=Task}/{action}/{id?}"); endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); endpoints.MapHub <AgentHub>("/agenthub"); endpoints.MapHub <TaskMonitorHub>("/monitorhub"); }); //UNDONE: add Redis backend if SignalR scale out is enabled //if (SenseNet.TaskManagement.Web.Configuration.SignalRSqlEnabled) // GlobalHost.DependencyResolver.UseSqlServer(SenseNet.TaskManagement.Web.Configuration.SignalRDatabaseConnectionString); //TODO: configure global error logging //httpConfiguration.Services.Add(typeof(IExceptionLogger), new WebExceptionLogger()); SnLog.WriteInformation("SenseNet TaskManagement app started.", EventId.TaskManagement.Lifecycle); // load apps appHandler.Initialize(); }
public static string GetFinalizeUrl(this SnTask task) { var app = ApplicationHandler.GetApplication(task.AppId); var combinedUrl = CombineUrls(app, task.FinalizeUrl, task.Id); // there is no local url: try the global if (string.IsNullOrEmpty(combinedUrl) && app != null) { combinedUrl = CombineUrls(app, app.TaskFinalizeUrl); } return(combinedUrl); }
public void Configuration(IAppBuilder appBuilder) { SnLog.Instance = new SnEventLogger(Web.Configuration.LogName, Web.Configuration.LogSourceName); SnLog.WriteInformation("Starting TaskManagement.Web", EventId.TaskManagement.Lifecycle); // make Web API use the standard ASP.NET error configuration ConfigureErrorHandling(); // Branch the pipeline here for requests that start with "/signalr" appBuilder.Map("/signalr", map => { // Setup the CORS middleware to run before SignalR. // By default this will allow all origins. You can // configure the set of origins and/or http verbs by // providing a cors options with a different policy. map.UseCors(CorsOptions.AllowAll); var hubConfiguration = new HubConfiguration { // You can enable JSONP by uncommenting line below. // JSONP requests are insecure but some older browsers (and some // versions of IE) require JSONP to work cross domain // EnableJSONP = true }; // add SQL server backend if SignalR SQL is enabled if (SenseNet.TaskManagement.Web.Configuration.SignalRSqlEnabled) { GlobalHost.DependencyResolver.UseSqlServer(SenseNet.TaskManagement.Web.Configuration.SignalRDatabaseConnectionString); } SnLog.WriteInformation( $"SignalR SQL backplane is{(SenseNet.TaskManagement.Web.Configuration.SignalRSqlEnabled ? string.Empty : " NOT")} enabled.", EventId.TaskManagement.Lifecycle); // Run the SignalR pipeline. We're not using MapSignalR // since this branch already runs under the "/signalr" // path. map.RunSignalR(hubConfiguration); }); var httpConfiguration = new HttpConfiguration(); httpConfiguration.Formatters.Clear(); httpConfiguration.Formatters.Add(new JsonMediaTypeFormatter()); httpConfiguration.Formatters.JsonFormatter.SerializerSettings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }; // Web API routes (moved here from WebApiConfig) httpConfiguration.MapHttpAttributeRoutes(); httpConfiguration.Routes.MapHttpRoute( name: "TaskManagementRegisterTaskApi", routeTemplate: "api/{controller}/{action}/{taskRequest}", defaults: new { taskRequest = RouteParameter.Optional, controller = "Task", action = "RegisterTask" } ); httpConfiguration.Routes.MapHttpRoute( name: "TaskManagementRegisterAppApi", routeTemplate: "api/{controller}/{action}/{appRequest}", defaults: new { taskRequest = RouteParameter.Optional, controller = "Task", action = "RegisterApplication" } ); httpConfiguration.Routes.MapHttpRoute( name: "TaskManagementApi", routeTemplate: "api/{controller}/{action}/{id}", defaults: new { id = RouteParameter.Optional }); // configure global error logging httpConfiguration.Services.Add(typeof(IExceptionLogger), new WebExceptionLogger()); appBuilder.UseWebApi(httpConfiguration); // initialize dead task timer InitializeDeadTaskTimer(); SnLog.WriteInformation("SenseNet TaskManagement app started.", EventId.TaskManagement.Lifecycle); // load apps ApplicationHandler.Initialize(); }