2021-05-24 12:32:12 +00:00
|
|
|
using System;
|
2021-04-04 13:19:54 +00:00
|
|
|
using Elsa.Activities.UserTask.Extensions;
|
2021-05-23 20:54:20 +00:00
|
|
|
using Elsa.Caching.Rebus.Extensions;
|
2021-01-31 11:51:51 +00:00
|
|
|
using Elsa.Persistence.EntityFramework.Core.Extensions;
|
2021-05-23 20:54:20 +00:00
|
|
|
using Elsa.Persistence.EntityFramework.SqlServer;
|
|
|
|
|
using Elsa.Rebus.RabbitMq;
|
2021-04-29 20:43:41 +00:00
|
|
|
using Elsa.Samples.Server.Host.Activities;
|
2021-05-24 12:32:12 +00:00
|
|
|
using Hangfire;
|
2019-11-22 22:07:31 +00:00
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
2021-05-23 20:54:20 +00:00
|
|
|
using Quartz;
|
2019-11-22 22:07:31 +00:00
|
|
|
|
2020-12-27 10:53:52 +00:00
|
|
|
namespace Elsa.Samples.Server.Host
|
2019-11-22 22:07:31 +00:00
|
|
|
{
|
|
|
|
|
public class Startup
|
|
|
|
|
{
|
|
|
|
|
public Startup(IWebHostEnvironment environment, IConfiguration configuration)
|
|
|
|
|
{
|
|
|
|
|
Environment = environment;
|
|
|
|
|
Configuration = configuration;
|
|
|
|
|
}
|
2019-11-24 14:25:16 +00:00
|
|
|
|
|
|
|
|
private IWebHostEnvironment Environment { get; }
|
|
|
|
|
private IConfiguration Configuration { get; }
|
2019-11-22 22:07:31 +00:00
|
|
|
|
|
|
|
|
public void ConfigureServices(IServiceCollection services)
|
|
|
|
|
{
|
|
|
|
|
var elsaSection = Configuration.GetSection("Elsa");
|
2021-05-23 20:54:20 +00:00
|
|
|
var sqlServerConnectionString = Configuration.GetConnectionString("SqlServer");
|
2021-04-01 16:53:26 +00:00
|
|
|
|
2021-04-04 13:19:54 +00:00
|
|
|
services.AddControllers();
|
|
|
|
|
|
2019-11-22 22:07:31 +00:00
|
|
|
services
|
2021-04-29 20:43:41 +00:00
|
|
|
.AddActivityPropertyOptionsProvider<VehicleActivity>()
|
|
|
|
|
.AddRuntimeSelectItemsProvider<VehicleActivity>()
|
2021-05-22 19:31:00 +00:00
|
|
|
//.AddRedis(Configuration.GetConnectionString("Redis"))
|
2021-01-31 11:51:51 +00:00
|
|
|
.AddElsa(elsa => elsa
|
2021-05-23 20:54:20 +00:00
|
|
|
.WithContainerName(Configuration["ContainerName"] ?? System.Environment.MachineName)
|
|
|
|
|
.UseEntityFrameworkPersistence(ef => ef.UseSqlServer(sqlServerConnectionString))
|
|
|
|
|
.UseRabbitMq(Configuration.GetConnectionString("RabbitMq"))
|
|
|
|
|
.UseRebusCacheSignal()
|
2021-05-22 11:58:21 +00:00
|
|
|
//.UseRedisCacheSignal()
|
2020-12-26 11:21:08 +00:00
|
|
|
.AddConsoleActivities()
|
|
|
|
|
.AddHttpActivities(elsaSection.GetSection("Http").Bind)
|
|
|
|
|
.AddEmailActivities(elsaSection.GetSection("Smtp").Bind)
|
2021-05-24 09:31:11 +00:00
|
|
|
.AddQuartzTemporalActivities()
|
|
|
|
|
// .AddQuartzTemporalActivities(configureQuartz: quartz => quartz.UsePersistentStore(store =>
|
|
|
|
|
// {
|
|
|
|
|
// store.UseJsonSerializer();
|
|
|
|
|
// store.UseSqlServer(sqlServerConnectionString);
|
|
|
|
|
// store.UseClustering();
|
|
|
|
|
// }))
|
2021-05-21 19:39:16 +00:00
|
|
|
//.AddHangfireTemporalActivities(hangfire => hangfire.UseInMemoryStorage(), (_, hangfireServer) => hangfireServer.SchedulePollingInterval = TimeSpan.FromSeconds(5))
|
2021-05-24 12:40:08 +00:00
|
|
|
//.AddHangfireTemporalActivities(hangfire => hangfire.UseSqlServerStorage(sqlServerConnectionString), (_, hangfireServer) => hangfireServer.SchedulePollingInterval = TimeSpan.FromSeconds(5))
|
2021-04-03 12:48:54 +00:00
|
|
|
.AddJavaScriptActivities()
|
2021-04-04 13:19:54 +00:00
|
|
|
.AddUserTaskActivities()
|
2021-05-08 18:44:09 +00:00
|
|
|
.AddActivitiesFrom<Startup>()
|
|
|
|
|
.AddWorkflowsFrom<Startup>()
|
2020-12-26 11:21:08 +00:00
|
|
|
);
|
2020-01-16 20:23:45 +00:00
|
|
|
|
2021-04-29 20:43:41 +00:00
|
|
|
// Elsa API endpoints.
|
2020-01-16 20:23:45 +00:00
|
|
|
services
|
2020-10-19 20:12:11 +00:00
|
|
|
.AddElsaApiEndpoints()
|
2021-01-19 19:17:14 +00:00
|
|
|
.AddElsaSwagger();
|
2021-03-11 12:17:38 +00:00
|
|
|
|
2021-02-16 08:55:13 +00:00
|
|
|
// Allow arbitrary client browser apps to access the API for demo purposes only.
|
|
|
|
|
// In a production environment, make sure to allow only origins you trust.
|
2021-03-11 12:17:38 +00:00
|
|
|
services.AddCors(cors => cors.AddDefaultPolicy(policy => policy.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin().WithExposedHeaders("Content-Disposition")));
|
2019-11-22 22:07:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Configure(IApplicationBuilder app)
|
|
|
|
|
{
|
|
|
|
|
if (Environment.IsDevelopment())
|
|
|
|
|
{
|
|
|
|
|
app.UseDeveloperExceptionPage();
|
2020-11-11 20:32:12 +00:00
|
|
|
app.UseSwagger();
|
|
|
|
|
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "Elsa"));
|
2019-11-22 22:07:31 +00:00
|
|
|
}
|
|
|
|
|
|
2020-02-15 19:32:16 +00:00
|
|
|
app
|
|
|
|
|
.UseCors()
|
2020-10-20 21:17:08 +00:00
|
|
|
.UseHttpActivities()
|
|
|
|
|
.UseRouting()
|
2021-03-17 12:07:14 +00:00
|
|
|
.UseEndpoints(endpoints =>
|
|
|
|
|
{
|
|
|
|
|
endpoints.MapControllers();
|
|
|
|
|
});
|
2019-11-22 22:07:31 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|