Work on YesSql persistence for Webhooks
Work on YesSql persistence for Webhooks
This commit is contained in:
parent
e2ee25f56b
commit
130147f5c9
|
|
@ -3,11 +3,9 @@ using System.Net.Mime;
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Elsa.Activities.Webhooks.Swagger.Examples;
|
||||
using Elsa.Models;
|
||||
using Elsa.Persistence.Specifications;
|
||||
using Elsa.Server.Api.Models;
|
||||
using Elsa.Server.Api.Services;
|
||||
using Elsa.Server.Api.Swagger.Examples;
|
||||
using Elsa.Webhooks.Models;
|
||||
using Elsa.Webhooks.Persistence;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
|
@ -41,7 +39,7 @@ namespace Elsa.Activities.Webhooks.Endpoints.WebhookDefinitions
|
|||
OperationId = "WebhookDefinitions.List",
|
||||
Tags = new[] { "WebhookDefinitions" })
|
||||
]
|
||||
public async Task<ActionResult<PagedList<WorkflowDefinition>>> Handle(CancellationToken cancellationToken = default)
|
||||
public async Task<ActionResult<PagedList<WebhookDefinition>>> Handle(CancellationToken cancellationToken = default)
|
||||
{
|
||||
var specification = Specification<WebhookDefinition>.Identity;
|
||||
var items = await _store.FindManyAsync(specification, cancellationToken: cancellationToken);
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ namespace Elsa.Webhooks.Persistence.EntityFramework.Core
|
|||
if (string.IsNullOrWhiteSpace(connectionString))
|
||||
connectionString = GetDefaultConnectionString();
|
||||
|
||||
var webhookOptionsBuilder = new WebhookOptionsBuilder(elsa.Services);
|
||||
var webhookOptionsBuilder = new WebhookOptionsBuilder(services);
|
||||
webhookOptionsBuilder.UseEntityFrameworkPersistence(options => Configure(options, connectionString));
|
||||
|
||||
services.AddScoped(sp => webhookOptionsBuilder.WebhookOptions.WebhookDefinitionStoreFactory(sp));
|
||||
|
|
|
|||
|
|
@ -17,12 +17,12 @@ namespace Elsa.Webhooks.Persistence.YesSql.Extensions
|
|||
{
|
||||
public static class WebhookServiceCollectionExtensions
|
||||
{
|
||||
public static ElsaOptionsBuilder UseWebhookYesSqlPersistence(this ElsaOptionsBuilder elsa) => elsa.UseWebhookYesSqlPersistence(config => config.UseSqLite("Data Source=elsa.yessql.db;Cache=Shared", IsolationLevel.ReadUncommitted));
|
||||
public static ElsaOptionsBuilder UseWebhookYesSqlPersistence(this ElsaOptionsBuilder elsa, Action<IConfiguration> configure) => elsa.UseWebhookYesSqlPersistence((_, config) => configure(config));
|
||||
public static WebhookOptionsBuilder UseWebhookYesSqlPersistence(this WebhookOptionsBuilder webhookOptions) => webhookOptions.UseWebhookYesSqlPersistence(config => config.UseSqLite("Data Source=elsa.yessql.db;Cache=Shared", IsolationLevel.ReadUncommitted));
|
||||
public static WebhookOptionsBuilder UseWebhookYesSqlPersistence(this WebhookOptionsBuilder webhookOptions, Action<IConfiguration> configure) => webhookOptions.UseWebhookYesSqlPersistence((_, config) => configure(config));
|
||||
|
||||
public static ElsaOptionsBuilder UseWebhookYesSqlPersistence(this ElsaOptionsBuilder elsa, Action<IServiceProvider, IConfiguration> configure)
|
||||
public static WebhookOptionsBuilder UseWebhookYesSqlPersistence(this WebhookOptionsBuilder webhookOptions, Action<IServiceProvider, IConfiguration> configure)
|
||||
{
|
||||
elsa.Services
|
||||
webhookOptions.Services
|
||||
.AddScoped<YesSqlWebhookDefinitionStore>()
|
||||
.AddSingleton(sp => CreateStore(sp, configure))
|
||||
.AddSingleton<ISessionProvider, SessionProvider>()
|
||||
|
|
@ -34,11 +34,11 @@ namespace Elsa.Webhooks.Persistence.YesSql.Extensions
|
|||
.AddAutoMapperProfile<AutoMapperProfile>()
|
||||
.AddIndexProvider<WebhookDefinitionIndexProvider>();
|
||||
|
||||
var webhookOptionsBuilder = new WebhookOptionsBuilder(elsa.Services);
|
||||
var webhookOptionsBuilder = new WebhookOptionsBuilder(webhookOptions.Services);
|
||||
|
||||
webhookOptionsBuilder.UseWebhookDefinitionStore(sp => sp.GetRequiredService<YesSqlWebhookDefinitionStore>());
|
||||
|
||||
return elsa;
|
||||
return webhookOptions;
|
||||
}
|
||||
|
||||
private static IStore CreateStore(
|
||||
|
|
|
|||
|
|
@ -1,8 +1,13 @@
|
|||
using System;
|
||||
using Elsa.Activities.Webhooks;
|
||||
using Elsa.Activities.Webhooks.Persistence.Decorators;
|
||||
using Elsa.Attributes;
|
||||
using Elsa.Services.Startup;
|
||||
//using Elsa.Webhooks.Persistence.EntityFramework.Core.Extensions;
|
||||
//using Elsa.Webhooks.Persistence.YesSql.Extensions;
|
||||
using Elsa.Webhooks.Persistence.YesSql.Extensions;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using YesSql.Provider.MySql;
|
||||
using YesSql.Provider.PostgreSql;
|
||||
using YesSql.Provider.Sqlite;
|
||||
|
|
@ -45,6 +50,7 @@ namespace Elsa.Webhooks.Persistence.YesSql
|
|||
|
||||
public override void ConfigureElsa(ElsaOptionsBuilder elsa, IConfiguration configuration)
|
||||
{
|
||||
var services = elsa.Services;
|
||||
var section = configuration.GetSection($"Elsa:Persistence:{ProviderName}");
|
||||
var connectionStringName = section.GetValue<string>("ConnectionStringName");
|
||||
var connectionString = section.GetValue<string>("ConnectionString");
|
||||
|
|
@ -60,7 +66,15 @@ namespace Elsa.Webhooks.Persistence.YesSql
|
|||
if (string.IsNullOrWhiteSpace(connectionString))
|
||||
connectionString = GetDefaultConnectionString();
|
||||
|
||||
elsa.UseWebhookYesSqlPersistence(options => Configure(options, connectionString));
|
||||
//elsa.UseWebhookYesSqlPersistence(options => Configure(options, connectionString));
|
||||
|
||||
var webhookOptionsBuilder = new WebhookOptionsBuilder(services);
|
||||
webhookOptionsBuilder.UseWebhookYesSqlPersistence(options => Configure(options, connectionString));
|
||||
|
||||
services.AddScoped(sp => webhookOptionsBuilder.WebhookOptions.WebhookDefinitionStoreFactory(sp));
|
||||
|
||||
services.Decorate<IWebhookDefinitionStore, InitializingWebhookDefinitionStore>();
|
||||
services.Decorate<IWebhookDefinitionStore, EventPublishingWebhookDefinitionStore>();
|
||||
}
|
||||
|
||||
protected virtual string GetDefaultConnectionString() => throw new Exception($"No connection string specified for the {ProviderName} provider");
|
||||
|
|
|
|||
|
|
@ -90,6 +90,35 @@ YesSql Postgre
|
|||
}
|
||||
```
|
||||
|
||||
### Configure modular activity providers such as Webhooks
|
||||
It is required to add modular activity provider and additional persistence feature for your modular activity provider.
|
||||
The persistence providers should match for Elsa Core and modular activity providers.
|
||||
Two examples below are given to set up Elsa Core and Webhooks persistence as follow.
|
||||
|
||||
EF Sqlite
|
||||
```
|
||||
"Elsa": {
|
||||
"Features": [
|
||||
"Persistence:EntityFrameworkCore:Sqlite",
|
||||
"Webhooks"
|
||||
"Webhooks:Persistence:EntityFrameworkCore:Sqlite",
|
||||
...
|
||||
],
|
||||
}
|
||||
```
|
||||
|
||||
EF MongoDB
|
||||
```
|
||||
"Elsa": {
|
||||
"Features": [
|
||||
"Persistence:MongoDb",
|
||||
"Webhooks"
|
||||
"Webhooks:Persistence:MongoDb",
|
||||
...
|
||||
],
|
||||
}
|
||||
```
|
||||
|
||||
### Configure connection strings for each persistence
|
||||
|
||||
```
|
||||
|
|
@ -102,7 +131,7 @@ YesSql Postgre
|
|||
},
|
||||
```
|
||||
|
||||
### Connection string examples
|
||||
### Connection strings
|
||||
MySql
|
||||
https://www.connectionstrings.com/mysql/
|
||||
SQL Server
|
||||
|
|
|
|||
|
|
@ -13,12 +13,12 @@
|
|||
"Redis": "localhost:6379,abortConnect=false",
|
||||
"MySql": "Server=LAPTOP-B76STK67;Database=Elsa;Uid=myUsername;Pwd=myPassword;",
|
||||
"SqlServer": "Server=LAPTOP-B76STK67;Database=Elsa;Integrated Security=true;MultipleActiveResultSets=True;Max Pool Size=500;Connection Timeout=3600",
|
||||
"Sqlite": "Data Source=elsa.sqlite.db;Cache=Shared;",
|
||||
"Sqlite": "Data Source=elsa.sqlite.yes.db;Cache=Shared;",
|
||||
"MongoDb": "mongodb://localhost:27017/Elsa"
|
||||
},
|
||||
"Elsa": {
|
||||
"Features": [
|
||||
"Persistence:EntityFrameworkCore:Sqlite",
|
||||
"Persistence:YesSql:Sqlite",
|
||||
"Console",
|
||||
"Http",
|
||||
"Email",
|
||||
|
|
@ -27,7 +27,7 @@
|
|||
"UserTask",
|
||||
"Conductor",
|
||||
"Webhooks",
|
||||
"Webhooks:Persistence:EntityFrameworkCore:Sqlite"
|
||||
"Webhooks:Persistence:YesSql:Sqlite"
|
||||
],
|
||||
"Persistence:MySql": {
|
||||
"ConnectionStringName": "MySql"
|
||||
|
|
|
|||
Loading…
Reference in a new issue