2021-06-18 13:53:10 +00:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
2021-05-30 13:04:33 +00:00
|
|
|
using Elsa.Activities.Conductor.Extensions;
|
2021-04-04 13:19:54 +00:00
|
|
|
using Elsa.Activities.UserTask.Extensions;
|
2021-01-31 11:51:51 +00:00
|
|
|
using Elsa.Persistence.EntityFramework.Core.Extensions;
|
|
|
|
|
using Elsa.Persistence.EntityFramework.Sqlite;
|
2021-06-11 20:32:31 +00:00
|
|
|
using Elsa.Providers.WorkflowStorage;
|
2021-04-29 20:43:41 +00:00
|
|
|
using Elsa.Samples.Server.Host.Activities;
|
2019-11-22 22:07:31 +00:00
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2021-06-02 16:42:57 +00:00
|
|
|
using Microsoft.Extensions.Hosting;
|
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-05-24 15:57:21 +00:00
|
|
|
var sqliteConnectionString = Configuration.GetConnectionString("Sqlite");
|
2021-05-27 15:48:46 +00:00
|
|
|
var mongoDbConnectionString = Configuration.GetConnectionString("MongoDb");
|
2021-04-01 16:53:26 +00:00
|
|
|
|
2021-04-04 13:19:54 +00:00
|
|
|
services.AddControllers();
|
|
|
|
|
|
2021-06-18 13:22:57 +00:00
|
|
|
//List<Assembly> assemblies = Assembly.GetExecutingAssembly().GetReferencedAssemblies().Select((item) => Assembly.Load(item)).ToList();
|
|
|
|
|
List<Assembly> assemblies = AppDomain.CurrentDomain.GetAssemblies().ToList<Assembly>();
|
|
|
|
|
|
2019-11-22 22:07:31 +00:00
|
|
|
services
|
2021-04-29 20:43:41 +00:00
|
|
|
.AddActivityPropertyOptionsProvider<VehicleActivity>()
|
|
|
|
|
.AddRuntimeSelectItemsProvider<VehicleActivity>()
|
2021-01-31 11:51:51 +00:00
|
|
|
.AddElsa(elsa => elsa
|
2021-06-04 08:39:22 +00:00
|
|
|
.UseEntityFrameworkPersistence(ef => ef.UseSqlite())
|
2021-05-31 09:35:06 +00:00
|
|
|
//.WithContainerName(Configuration["ContainerName"] ?? System.Environment.MachineName)
|
2021-05-30 11:30:07 +00:00
|
|
|
//.UseEntityFrameworkPersistence(ef => ef.UseSqlite(sqliteConnectionString))
|
|
|
|
|
//.UseMongoDbPersistence(options => options.ConnectionString = mongoDbConnectionString)
|
|
|
|
|
//.UseYesSqlPersistence(config => config.UsePostgreSql("Server=localhost;Port=5432;Database=yessql5;User Id=root;Password=Password12!;"))
|
|
|
|
|
//.UseRabbitMq(Configuration.GetConnectionString("RabbitMq"))
|
2021-05-31 09:35:06 +00:00
|
|
|
//.UseRebusCacheSignal()
|
2021-05-30 11:30:07 +00:00
|
|
|
//.UseRedisCacheSignal()
|
2021-06-11 20:32:31 +00:00
|
|
|
.UseDefaultWorkflowStorageProvider<TransientWorkflowStorageProvider>()
|
2020-12-26 11:21:08 +00:00
|
|
|
.AddConsoleActivities()
|
2021-06-18 13:22:57 +00:00
|
|
|
|
2020-12-26 11:21:08 +00:00
|
|
|
.AddHttpActivities(elsaSection.GetSection("Http").Bind)
|
|
|
|
|
.AddEmailActivities(elsaSection.GetSection("Smtp").Bind)
|
2021-02-28 15:44:23 +00:00
|
|
|
.AddQuartzTemporalActivities()
|
2021-05-24 09:31:11 +00:00
|
|
|
// .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-30 13:04:33 +00:00
|
|
|
.AddConductorActivities(options => elsaSection.GetSection("Conductor").Bind(options))
|
2021-05-08 18:44:09 +00:00
|
|
|
.AddActivitiesFrom<Startup>()
|
|
|
|
|
.AddWorkflowsFrom<Startup>()
|
2021-06-18 13:22:57 +00:00
|
|
|
.AddFeatures(assemblies, elsaSection.GetSection("Features").Get<List<string>>())
|
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-06-18 13:22:57 +00:00
|
|
|
//AddFeatures();
|
|
|
|
|
|
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-05-27 15:48:46 +00:00
|
|
|
.UseEndpoints(endpoints => { endpoints.MapControllers(); });
|
2019-11-22 22:07:31 +00:00
|
|
|
}
|
2021-06-18 13:22:57 +00:00
|
|
|
|
2019-11-22 22:07:31 +00:00
|
|
|
}
|
|
|
|
|
}
|