diff --git a/Elsa.sln b/Elsa.sln index 35515db90..b9ba3a7e6 100644 --- a/Elsa.sln +++ b/Elsa.sln @@ -321,7 +321,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ElsaDashboard.Samples.Blazo EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Elsa.Samples.FaultyWorkflows", "src\samples\aspnet\Elsa.Samples.FaultyWorkflows\Elsa.Samples.FaultyWorkflows.csproj", "{84751112-C2B7-41D4-98F5-D87D7C2E1DAE}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.Activities.Conductor", "src\activities\Elsa.Activities.Conductor\Elsa.Activities.Conductor.csproj", "{4D4022DD-244B-47EE-95FA-7071EC687B24}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Elsa.Activities.Conductor", "src\activities\Elsa.Activities.Conductor\Elsa.Activities.Conductor.csproj", "{4D4022DD-244B-47EE-95FA-7071EC687B24}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "aspnetcore", "aspnetcore", "{39DE1EE2-DF4F-44EB-9F5A-551BEADD6673}" EndProject @@ -653,6 +653,16 @@ Global {3DF05CFC-AC77-489F-9A42-C4FDB599AA69}.Release|Any CPU.Build.0 = Release|Any CPU {D55BC08B-CA82-478A-99F7-EDE90AC33160}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {D55BC08B-CA82-478A-99F7-EDE90AC33160}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D55BC08B-CA82-478A-99F7-EDE90AC33160}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D55BC08B-CA82-478A-99F7-EDE90AC33160}.Release|Any CPU.Build.0 = Release|Any CPU + {775EFD59-F99C-4D38-B54E-9734C9D9649A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {775EFD59-F99C-4D38-B54E-9734C9D9649A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {775EFD59-F99C-4D38-B54E-9734C9D9649A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {775EFD59-F99C-4D38-B54E-9734C9D9649A}.Release|Any CPU.Build.0 = Release|Any CPU + {30A9B140-14F5-4D00-84ED-1447F96D13C8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {30A9B140-14F5-4D00-84ED-1447F96D13C8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {30A9B140-14F5-4D00-84ED-1447F96D13C8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {30A9B140-14F5-4D00-84ED-1447F96D13C8}.Release|Any CPU.Build.0 = Release|Any CPU {BE284508-9582-4FCB-B0DD-0761AB940AD7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {BE284508-9582-4FCB-B0DD-0761AB940AD7}.Debug|Any CPU.Build.0 = Debug|Any CPU {BE284508-9582-4FCB-B0DD-0761AB940AD7}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -661,10 +671,6 @@ Global {3EB488DF-3C28-4DAD-B43E-6062E39629AB}.Debug|Any CPU.Build.0 = Debug|Any CPU {3EB488DF-3C28-4DAD-B43E-6062E39629AB}.Release|Any CPU.ActiveCfg = Release|Any CPU {3EB488DF-3C28-4DAD-B43E-6062E39629AB}.Release|Any CPU.Build.0 = Release|Any CPU - {775EFD59-F99C-4D38-B54E-9734C9D9649A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {775EFD59-F99C-4D38-B54E-9734C9D9649A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {30A9B140-14F5-4D00-84ED-1447F96D13C8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {30A9B140-14F5-4D00-84ED-1447F96D13C8}.Debug|Any CPU.Build.0 = Debug|Any CPU {3E2423CF-50E6-4D2B-8749-17B1EF540FE4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {3E2423CF-50E6-4D2B-8749-17B1EF540FE4}.Debug|Any CPU.Build.0 = Debug|Any CPU {3E2423CF-50E6-4D2B-8749-17B1EF540FE4}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -679,8 +685,12 @@ Global {9ACA06DA-9AFE-41A2-8109-EFED8B9B14A1}.Release|Any CPU.Build.0 = Release|Any CPU {D1644D32-AA51-4D10-942E-F2722DB963B4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {D1644D32-AA51-4D10-942E-F2722DB963B4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D1644D32-AA51-4D10-942E-F2722DB963B4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D1644D32-AA51-4D10-942E-F2722DB963B4}.Release|Any CPU.Build.0 = Release|Any CPU {7756E22A-AD59-46C1-A019-1D28D7217347}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {7756E22A-AD59-46C1-A019-1D28D7217347}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7756E22A-AD59-46C1-A019-1D28D7217347}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7756E22A-AD59-46C1-A019-1D28D7217347}.Release|Any CPU.Build.0 = Release|Any CPU {7B84277D-96EF-4C7F-9D5E-8CBB2D26E5EB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {7B84277D-96EF-4C7F-9D5E-8CBB2D26E5EB}.Debug|Any CPU.Build.0 = Debug|Any CPU {7B84277D-96EF-4C7F-9D5E-8CBB2D26E5EB}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -723,6 +733,8 @@ Global {EE147504-555D-4EFC-A79A-34748666AA6C}.Release|Any CPU.Build.0 = Release|Any CPU {1129868E-BA72-44C4-941C-A28D9001504B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {1129868E-BA72-44C4-941C-A28D9001504B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1129868E-BA72-44C4-941C-A28D9001504B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1129868E-BA72-44C4-941C-A28D9001504B}.Release|Any CPU.Build.0 = Release|Any CPU {24A99602-F743-4B1A-AC96-599F34AE916C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {24A99602-F743-4B1A-AC96-599F34AE916C}.Debug|Any CPU.Build.0 = Debug|Any CPU {24A99602-F743-4B1A-AC96-599F34AE916C}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -848,13 +860,14 @@ Global {B09A6E42-EF42-4693-BA0E-5EE1D7F81FFD} = {DBBD242E-4437-4BDB-919F-A70839BE75FA} {495BE954-E6EA-41A9-8054-A5CA5DD0924E} = {DBBD242E-4437-4BDB-919F-A70839BE75FA} {D86B94DC-A53C-4A67-A820-828DD359C49B} = {4673732F-2853-47BD-91B8-C95C229D2C89} + {F1EF5639-021A-4D22-9D4A-73D57C88EBFA} = {39DE1EE2-DF4F-44EB-9F5A-551BEADD6673} {3A30EFFE-32D8-40B8-9C62-427037BB5424} = {EEBEA8AF-C8A8-4C71-A96C-D5836DE24359} {3DF05CFC-AC77-489F-9A42-C4FDB599AA69} = {8B6B40A8-DF21-4CD2-BABD-474B79D0C3AF} {D55BC08B-CA82-478A-99F7-EDE90AC33160} = {C865B0FD-E505-48F0-BFAF-0D4D7C1B5CA1} - {BE284508-9582-4FCB-B0DD-0761AB940AD7} = {B43B546E-23F3-46E8-ACB7-D04F05CDA180} - {3EB488DF-3C28-4DAD-B43E-6062E39629AB} = {FC9F520F-BA51-4AD2-BFEE-EF787798E734} {775EFD59-F99C-4D38-B54E-9734C9D9649A} = {22E75696-6FE9-436A-9097-EE21C603F818} {30A9B140-14F5-4D00-84ED-1447F96D13C8} = {FC9F520F-BA51-4AD2-BFEE-EF787798E734} + {BE284508-9582-4FCB-B0DD-0761AB940AD7} = {B43B546E-23F3-46E8-ACB7-D04F05CDA180} + {3EB488DF-3C28-4DAD-B43E-6062E39629AB} = {FC9F520F-BA51-4AD2-BFEE-EF787798E734} {3E2423CF-50E6-4D2B-8749-17B1EF540FE4} = {22E75696-6FE9-436A-9097-EE21C603F818} {9937FB02-72D9-4FCD-B31E-8E60CFF1B37F} = {DA71CDAA-8DD3-4D5F-9FBD-8E4B37A2D925} {61C16CA0-B190-4642-A81A-5C03705CA2C1} = {9937FB02-72D9-4FCD-B31E-8E60CFF1B37F} @@ -880,7 +893,6 @@ Global {84751112-C2B7-41D4-98F5-D87D7C2E1DAE} = {22E75696-6FE9-436A-9097-EE21C603F818} {4D4022DD-244B-47EE-95FA-7071EC687B24} = {B43B546E-23F3-46E8-ACB7-D04F05CDA180} {39DE1EE2-DF4F-44EB-9F5A-551BEADD6673} = {4673732F-2853-47BD-91B8-C95C229D2C89} - {F1EF5639-021A-4D22-9D4A-73D57C88EBFA} = {39DE1EE2-DF4F-44EB-9F5A-551BEADD6673} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {8B0975FD-7050-48B0-88C5-48C33378E158} diff --git a/src/activities/webhooks/Elsa.Activities.Webhooks/Elsa.Activities.Webhooks.csproj b/src/activities/webhooks/Elsa.Activities.Webhooks/Elsa.Activities.Webhooks.csproj index 558da474f..17f6b2faf 100644 --- a/src/activities/webhooks/Elsa.Activities.Webhooks/Elsa.Activities.Webhooks.csproj +++ b/src/activities/webhooks/Elsa.Activities.Webhooks/Elsa.Activities.Webhooks.csproj @@ -1,4 +1,4 @@ - + @@ -12,6 +12,10 @@ elsa, workflows, webhooks + + + + @@ -22,11 +26,6 @@ - - - - - diff --git a/src/activities/webhooks/Elsa.Activities.Webhooks/Endpoints/WebhookDefinitions/List.cs b/src/activities/webhooks/Elsa.Activities.Webhooks/Endpoints/WebhookDefinitions/List.cs index 0d497d3d6..385fb42b0 100644 --- a/src/activities/webhooks/Elsa.Activities.Webhooks/Endpoints/WebhookDefinitions/List.cs +++ b/src/activities/webhooks/Elsa.Activities.Webhooks/Endpoints/WebhookDefinitions/List.cs @@ -3,7 +3,6 @@ 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; @@ -40,7 +39,7 @@ namespace Elsa.Activities.Webhooks.Endpoints.WebhookDefinitions OperationId = "WebhookDefinitions.List", Tags = new[] { "WebhookDefinitions" }) ] - public async Task>> Handle(CancellationToken cancellationToken = default) + public async Task>> Handle(CancellationToken cancellationToken = default) { var specification = Specification.Identity; var items = await _store.FindManyAsync(specification, cancellationToken: cancellationToken); diff --git a/src/activities/webhooks/Elsa.Activities.Webhooks/Endpoints/WebhookDefinitions/Put.cs b/src/activities/webhooks/Elsa.Activities.Webhooks/Endpoints/WebhookDefinitions/Put.cs index cb26304ca..bdc60f57c 100644 --- a/src/activities/webhooks/Elsa.Activities.Webhooks/Endpoints/WebhookDefinitions/Put.cs +++ b/src/activities/webhooks/Elsa.Activities.Webhooks/Endpoints/WebhookDefinitions/Put.cs @@ -13,12 +13,12 @@ namespace Elsa.Activities.Webhooks.Endpoints.WebhookDefinitions { [ApiController] [ApiVersion("1")] - [Route("v{apiVersion:apiVersion}/webhook-definitions/{id}")] + [Route("v{apiVersion:apiVersion}/webhook-definitions")] [Produces("application/json")] - public class Put : ControllerBase + public class Update : ControllerBase { private readonly IWebhookDefinitionStore _store; - public Put(IWebhookDefinitionStore store) => _store = store; + public Update(IWebhookDefinitionStore store) => _store = store; [HttpPut] [ProducesResponseType(typeof(WebhookDefinition), StatusCodes.Status200OK)] @@ -44,7 +44,7 @@ namespace Elsa.Activities.Webhooks.Endpoints.WebhookDefinitions webhookDefinition.PayloadTypeName = request.PayloadTypeName?.Trim(); webhookDefinition.IsEnabled = request.IsEnabled; - await _store.SaveAsync(webhookDefinition, cancellationToken); + await _store.UpdateAsync(webhookDefinition, cancellationToken); return Ok(webhookDefinition); } diff --git a/src/activities/webhooks/Elsa.Activities.Webhooks/Extensions/WebhookOptionsBuilderExtensions.cs b/src/activities/webhooks/Elsa.Activities.Webhooks/Extensions/WebhookOptionsBuilderExtensions.cs index 8cf27357c..cdb5e79f5 100644 --- a/src/activities/webhooks/Elsa.Activities.Webhooks/Extensions/WebhookOptionsBuilderExtensions.cs +++ b/src/activities/webhooks/Elsa.Activities.Webhooks/Extensions/WebhookOptionsBuilderExtensions.cs @@ -1,34 +1,18 @@ -using System; using Elsa.Activities.Webhooks.ActivityTypes; using Elsa.Activities.Webhooks.Bookmarks; -using Elsa.Activities.Webhooks.Persistence.Decorators; using Elsa.Services; -using Elsa.Webhooks.Persistence; using Microsoft.Extensions.DependencyInjection; namespace Elsa.Activities.Webhooks.Extensions { public static class WebhookOptionsBuilderExtensions { - public static ElsaOptionsBuilder AddWebhooks( - this ElsaOptionsBuilder elsaOptions, - Action? configure = default) + public static ElsaOptionsBuilder AddWebhooks(this ElsaOptionsBuilder elsaOptions) { - var services = elsaOptions.Services; - - // Configure Webhooks. - var webhookOptionsBuilder = new WebhookOptionsBuilder(elsaOptions.Services); - configure?.Invoke(webhookOptionsBuilder); - - // Services. - services + elsaOptions.Services .AddScoped() - .AddScoped(sp => webhookOptionsBuilder.WebhookOptions.WebhookDefinitionStoreFactory(sp)) .AddBookmarkProvider(); - services.Decorate(); - services.Decorate(); - return elsaOptions; } diff --git a/src/activities/webhooks/Elsa.Activities.Webhooks/Options/WebhookOptions.cs b/src/activities/webhooks/Elsa.Activities.Webhooks/Options/WebhookOptions.cs index 8231b029b..38a6bc577 100644 --- a/src/activities/webhooks/Elsa.Activities.Webhooks/Options/WebhookOptions.cs +++ b/src/activities/webhooks/Elsa.Activities.Webhooks/Options/WebhookOptions.cs @@ -12,6 +12,6 @@ namespace Elsa.Activities.Webhooks.Options WebhookDefinitionStoreFactory = provider => ActivatorUtilities.CreateInstance(provider); } - internal Func WebhookDefinitionStoreFactory { get; set; } + public Func WebhookDefinitionStoreFactory { get; set; } } } diff --git a/src/activities/webhooks/Elsa.Activities.Webhooks/Startup.cs b/src/activities/webhooks/Elsa.Activities.Webhooks/Startup.cs index 8ef7a7437..74c656e6c 100644 --- a/src/activities/webhooks/Elsa.Activities.Webhooks/Startup.cs +++ b/src/activities/webhooks/Elsa.Activities.Webhooks/Startup.cs @@ -1,7 +1,6 @@ using Elsa.Activities.Webhooks.Extensions; using Elsa.Attributes; using Elsa.Services.Startup; -using Elsa.Webhooks.Persistence.EntityFramework.Sqlite; using Microsoft.Extensions.Configuration; namespace Elsa.Activities.Webhooks @@ -11,8 +10,7 @@ namespace Elsa.Activities.Webhooks { public override void ConfigureElsa(ElsaOptionsBuilder elsa, IConfiguration configuration) { - // TODO: Read selected persistence provider from config. - elsa.AddWebhooks(webhooks => webhooks.UseEntityFrameworkPersistence(ef => ef.UseWebhookSqlite())); + elsa.AddWebhooks(); } } } diff --git a/src/activities/webhooks/Elsa.Webhooks.Persistence.EntityFramework.Core/Elsa.Webhooks.Persistence.EntityFramework.Core.csproj b/src/activities/webhooks/Elsa.Webhooks.Persistence.EntityFramework.Core/Elsa.Webhooks.Persistence.EntityFramework.Core.csproj index f35f7aca7..c6b9f6818 100644 --- a/src/activities/webhooks/Elsa.Webhooks.Persistence.EntityFramework.Core/Elsa.Webhooks.Persistence.EntityFramework.Core.csproj +++ b/src/activities/webhooks/Elsa.Webhooks.Persistence.EntityFramework.Core/Elsa.Webhooks.Persistence.EntityFramework.Core.csproj @@ -19,6 +19,7 @@ + diff --git a/src/activities/webhooks/Elsa.Webhooks.Persistence.EntityFramework.Core/EntityFrameworkWebhookStartupBase.cs b/src/activities/webhooks/Elsa.Webhooks.Persistence.EntityFramework.Core/EntityFrameworkWebhookStartupBase.cs new file mode 100644 index 000000000..af5e3f21c --- /dev/null +++ b/src/activities/webhooks/Elsa.Webhooks.Persistence.EntityFramework.Core/EntityFrameworkWebhookStartupBase.cs @@ -0,0 +1,47 @@ +using System; +using Elsa.Activities.Webhooks; +using Elsa.Activities.Webhooks.Persistence.Decorators; +using Elsa.Services.Startup; +using Elsa.Webhooks.Persistence.EntityFramework.Core.Extensions; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; + +namespace Elsa.Webhooks.Persistence.EntityFramework.Core +{ + public abstract class EntityFrameworkWebhookStartupBase : StartupBase + { + protected abstract string ProviderName { get; } + + public override void ConfigureElsa(ElsaOptionsBuilder elsa, IConfiguration configuration) + { + var services = elsa.Services; + var section = configuration.GetSection($"Elsa:Persistence:{ProviderName}"); + var connectionStringName = section.GetValue("ConnectionStringName"); + var connectionString = section.GetValue("ConnectionString"); + + if (string.IsNullOrWhiteSpace(connectionString)) + { + if (string.IsNullOrWhiteSpace(connectionStringName)) + connectionStringName = ProviderName; + + connectionString = configuration.GetConnectionString(connectionStringName); + } + + if (string.IsNullOrWhiteSpace(connectionString)) + connectionString = GetDefaultConnectionString(); + + var webhookOptionsBuilder = new WebhookOptionsBuilder(services); + webhookOptionsBuilder.UseEntityFrameworkPersistence(options => Configure(options, connectionString)); + + services.AddScoped(sp => webhookOptionsBuilder.WebhookOptions.WebhookDefinitionStoreFactory(sp)); + + services.Decorate(); + services.Decorate(); + } + + protected virtual string GetDefaultConnectionString() => throw new Exception($"No connection string specified for the {ProviderName} provider"); + protected abstract void Configure(DbContextOptionsBuilder options, string connectionString); + + } +} \ No newline at end of file diff --git a/src/activities/webhooks/Elsa.Activities.Webhooks/Extensions/WebhookServiceCollectionExtensions.cs b/src/activities/webhooks/Elsa.Webhooks.Persistence.EntityFramework.Core/Extensions/WebhookServiceCollectionExtensions.cs similarity index 99% rename from src/activities/webhooks/Elsa.Activities.Webhooks/Extensions/WebhookServiceCollectionExtensions.cs rename to src/activities/webhooks/Elsa.Webhooks.Persistence.EntityFramework.Core/Extensions/WebhookServiceCollectionExtensions.cs index 3266059f4..42109a562 100644 --- a/src/activities/webhooks/Elsa.Activities.Webhooks/Extensions/WebhookServiceCollectionExtensions.cs +++ b/src/activities/webhooks/Elsa.Webhooks.Persistence.EntityFramework.Core/Extensions/WebhookServiceCollectionExtensions.cs @@ -1,14 +1,14 @@ using System; +using Elsa.Activities.Webhooks; using Elsa.Persistence.EntityFramework.Core; using Elsa.Runtime; -using Elsa.Webhooks.Persistence.EntityFramework.Core; using Elsa.Webhooks.Persistence.EntityFramework.Core.Services; using Elsa.Webhooks.Persistence.EntityFramework.Core.StartupTasks; using Elsa.Webhooks.Persistence.EntityFramework.Core.Stores; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; -namespace Elsa.Activities.Webhooks.Extensions +namespace Elsa.Webhooks.Persistence.EntityFramework.Core.Extensions { public static class WebhookServiceCollectionExtensions { diff --git a/src/activities/webhooks/Elsa.Webhooks.Persistence.EntityFramework.MySql/Startup.cs b/src/activities/webhooks/Elsa.Webhooks.Persistence.EntityFramework.MySql/Startup.cs new file mode 100644 index 000000000..90496e3c0 --- /dev/null +++ b/src/activities/webhooks/Elsa.Webhooks.Persistence.EntityFramework.MySql/Startup.cs @@ -0,0 +1,13 @@ +using Elsa.Attributes; +using Elsa.Webhooks.Persistence.EntityFramework.Core; +using Microsoft.EntityFrameworkCore; + +namespace Elsa.Webhooks.Persistence.EntityFramework.MySql +{ + [Feature("Webhooks:Persistence:EntityFrameworkCore:MySql")] + public class Startup : EntityFrameworkWebhookStartupBase + { + protected override string ProviderName => "MySql"; + protected override void Configure(DbContextOptionsBuilder options, string connectionString) => options.UseWebhookMySql(connectionString); + } +} \ No newline at end of file diff --git a/src/activities/webhooks/Elsa.Webhooks.Persistence.EntityFramework.MySql/WebhookDbContextOptionsBuilderExtensions.cs b/src/activities/webhooks/Elsa.Webhooks.Persistence.EntityFramework.MySql/WebhookDbContextOptionsBuilderExtensions.cs index 1dbaccb4e..6921fd63b 100644 --- a/src/activities/webhooks/Elsa.Webhooks.Persistence.EntityFramework.MySql/WebhookDbContextOptionsBuilderExtensions.cs +++ b/src/activities/webhooks/Elsa.Webhooks.Persistence.EntityFramework.MySql/WebhookDbContextOptionsBuilderExtensions.cs @@ -1,5 +1,6 @@ using Elsa.Webhooks.Persistence.EntityFramework.Core; using Microsoft.EntityFrameworkCore; +using Pomelo.EntityFrameworkCore.MySql.Infrastructure; namespace Elsa.Webhooks.Persistence.EntityFramework.MySql { @@ -11,6 +12,7 @@ namespace Elsa.Webhooks.Persistence.EntityFramework.MySql public static DbContextOptionsBuilder UseWebhookMySql(this DbContextOptionsBuilder builder, string connectionString) => builder.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString), db => db .MigrationsAssembly(typeof(WebhookMySqlElsaContextFactory).Assembly.GetName().Name) - .MigrationsHistoryTable(WebhookContext.MigrationsHistoryTable, WebhookContext.ElsaSchema)); + .MigrationsHistoryTable(WebhookContext.MigrationsHistoryTable, WebhookContext.ElsaSchema) + .SchemaBehavior(MySqlSchemaBehavior.Ignore)); } } \ No newline at end of file diff --git a/src/activities/webhooks/Elsa.Webhooks.Persistence.EntityFramework.PostgreSql/Startup.cs b/src/activities/webhooks/Elsa.Webhooks.Persistence.EntityFramework.PostgreSql/Startup.cs new file mode 100644 index 000000000..c141f08c6 --- /dev/null +++ b/src/activities/webhooks/Elsa.Webhooks.Persistence.EntityFramework.PostgreSql/Startup.cs @@ -0,0 +1,13 @@ +using Elsa.Attributes; +using Elsa.Webhooks.Persistence.EntityFramework.Core; +using Microsoft.EntityFrameworkCore; + +namespace Elsa.Webhooks.Persistence.EntityFramework.PostgreSql +{ + [Feature("Webhooks:Persistence:EntityFrameworkCore:PostgreSql")] + public class Startup : EntityFrameworkWebhookStartupBase + { + protected override string ProviderName => "PostgreSql"; + protected override void Configure(DbContextOptionsBuilder options, string connectionString) => options.UseWebhookPostgreSql(connectionString); + } +} \ No newline at end of file diff --git a/src/activities/webhooks/Elsa.Webhooks.Persistence.EntityFramework.SqlServer/Startup.cs b/src/activities/webhooks/Elsa.Webhooks.Persistence.EntityFramework.SqlServer/Startup.cs new file mode 100644 index 000000000..6557a7350 --- /dev/null +++ b/src/activities/webhooks/Elsa.Webhooks.Persistence.EntityFramework.SqlServer/Startup.cs @@ -0,0 +1,13 @@ +using Elsa.Attributes; +using Elsa.Webhooks.Persistence.EntityFramework.Core; +using Microsoft.EntityFrameworkCore; + +namespace Elsa.Webhooks.Persistence.EntityFramework.SqlServer +{ + [Feature("Webhooks:Persistence:EntityFrameworkCore:SqlServer")] + public class Startup : EntityFrameworkWebhookStartupBase + { + protected override string ProviderName => "SqlServer"; + protected override void Configure(DbContextOptionsBuilder options, string connectionString) => options.UseWebhookSqlServer(connectionString); + } +} \ No newline at end of file diff --git a/src/activities/webhooks/Elsa.Webhooks.Persistence.EntityFramework.Sqlite/Startup.cs b/src/activities/webhooks/Elsa.Webhooks.Persistence.EntityFramework.Sqlite/Startup.cs new file mode 100644 index 000000000..07b50dcc6 --- /dev/null +++ b/src/activities/webhooks/Elsa.Webhooks.Persistence.EntityFramework.Sqlite/Startup.cs @@ -0,0 +1,14 @@ +using Elsa.Attributes; +using Elsa.Webhooks.Persistence.EntityFramework.Core; +using Microsoft.EntityFrameworkCore; + +namespace Elsa.Webhooks.Persistence.EntityFramework.Sqlite +{ + [Feature("Webhooks:Persistence:EntityFrameworkCore:Sqlite")] + public class Startup : EntityFrameworkWebhookStartupBase + { + protected override string ProviderName => "Sqlite"; + protected override string GetDefaultConnectionString() => "Data Source=elsa.sqlite.db;Cache=Shared;"; + protected override void Configure(DbContextOptionsBuilder options, string connectionString) => options.UseWebhookSqlite(connectionString); + } +} \ No newline at end of file diff --git a/src/activities/webhooks/Elsa.Webhooks.Persistence.MongoDb/Extensions/WebhookServiceCollectionExtensions.cs b/src/activities/webhooks/Elsa.Webhooks.Persistence.MongoDb/Extensions/WebhookServiceCollectionExtensions.cs index e456cc35c..0f698b571 100644 --- a/src/activities/webhooks/Elsa.Webhooks.Persistence.MongoDb/Extensions/WebhookServiceCollectionExtensions.cs +++ b/src/activities/webhooks/Elsa.Webhooks.Persistence.MongoDb/Extensions/WebhookServiceCollectionExtensions.cs @@ -11,37 +11,35 @@ namespace Elsa.Webhooks.Persistence.MongoDb.Extensions { public static class WebhookServiceCollectionExtensions { - public static ElsaOptionsBuilder UseMongoDbPersistence(this ElsaOptionsBuilder elsa, Action configureOptions) => UseMongoDbPersistence(elsa, configureOptions); + public static WebhookOptionsBuilder UseWebhookMongoDbPersistence(this WebhookOptionsBuilder webhookOptions, Action configureOptions) => UseWebhookMongoDbPersistence(webhookOptions, configureOptions); - public static ElsaOptionsBuilder UseMongoDbPersistence(this ElsaOptionsBuilder elsa, Action configureOptions) where TDbContext : ElsaMongoDbContext + public static WebhookOptionsBuilder UseWebhookMongoDbPersistence(this WebhookOptionsBuilder webhookOptions, Action configureOptions) where TDbContext : ElsaMongoDbContext { - AddCore(elsa); - elsa.Services.Configure(configureOptions); + AddCore(webhookOptions); + webhookOptions.Services.Configure(configureOptions); - return elsa; + return webhookOptions; } - public static ElsaOptionsBuilder UseMongoDbPersistence(this ElsaOptionsBuilder elsa, IConfiguration configuration) => UseMongoDbPersistence(elsa, configuration); + public static WebhookOptionsBuilder UseWebhookMongoDbPersistence(this WebhookOptionsBuilder webhookOptions, IConfiguration configuration) => UseWebhookMongoDbPersistence(webhookOptions, configuration); - public static ElsaOptionsBuilder UseMongoDbPersistence(this ElsaOptionsBuilder elsa, IConfiguration configuration) where TDbContext : ElsaMongoDbContext + public static WebhookOptionsBuilder UseWebhookMongoDbPersistence(this WebhookOptionsBuilder webhookOptions, IConfiguration configuration) where TDbContext : ElsaMongoDbContext { - AddCore(elsa); - elsa.Services.Configure(configuration); - return elsa; + AddCore(webhookOptions); + webhookOptions.Services.Configure(configuration); + return webhookOptions; } - private static void AddCore(ElsaOptionsBuilder elsa) where TDbContext : ElsaMongoDbContext + private static void AddCore(WebhookOptionsBuilder webhookOptions) where TDbContext : ElsaMongoDbContext { - elsa.Services + webhookOptions.Services .AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton(sp => sp.GetRequiredService().WebhookDefinitions) .AddStartupTask(); - var webhookOptionsBuilder = new WebhookOptionsBuilder(elsa.Services); - - webhookOptionsBuilder.UseWebhookDefinitionStore(sp => sp.GetRequiredService()); + webhookOptions.UseWebhookDefinitionStore(sp => sp.GetRequiredService()); DatabaseRegister.RegisterMapsAndSerializers(); } diff --git a/src/activities/webhooks/Elsa.Webhooks.Persistence.MongoDb/Services/DatabaseInitializer.cs b/src/activities/webhooks/Elsa.Webhooks.Persistence.MongoDb/Services/DatabaseInitializer.cs index a9f136291..212f522fe 100644 --- a/src/activities/webhooks/Elsa.Webhooks.Persistence.MongoDb/Services/DatabaseInitializer.cs +++ b/src/activities/webhooks/Elsa.Webhooks.Persistence.MongoDb/Services/DatabaseInitializer.cs @@ -28,10 +28,9 @@ namespace Elsa.Webhooks.Persistence.MongoDb.Services var builder = Builders.IndexKeys; var tenantKeysDefinition = builder.Ascending(x => x.TenantId); var nameKeysDefinition = builder.Ascending(x => x.Name); - var webhookIdDefinition = builder.Ascending(x => x.Id); - var collection = _mongoContext.WebhookDefinitions; - await CreateIndexesAsync(_mongoContext.WebhookDefinitions, cancellationToken, tenantKeysDefinition, webhookIdDefinition, nameKeysDefinition); - await collection.Indexes.CreateOneAsync(new CreateIndexModel(webhookIdDefinition, new CreateIndexOptions { Unique = true }), cancellationToken: cancellationToken); + var pathKeysDefinition = builder.Ascending(x => x.Path); + var payloadKeysDefinition = builder.Ascending(x => x.PayloadTypeName); + await CreateIndexesAsync(_mongoContext.WebhookDefinitions, cancellationToken, tenantKeysDefinition, nameKeysDefinition, pathKeysDefinition, payloadKeysDefinition); } private async Task CreateIndexesAsync(IMongoCollection collection, CancellationToken cancellationToken, params IndexKeysDefinition[] definitions) diff --git a/src/activities/webhooks/Elsa.Webhooks.Persistence.MongoDb/Startup.cs b/src/activities/webhooks/Elsa.Webhooks.Persistence.MongoDb/Startup.cs new file mode 100644 index 000000000..c8295b9dd --- /dev/null +++ b/src/activities/webhooks/Elsa.Webhooks.Persistence.MongoDb/Startup.cs @@ -0,0 +1,41 @@ +using Elsa.Activities.Webhooks; +using Elsa.Activities.Webhooks.Persistence.Decorators; +using Elsa.Attributes; +using Elsa.Persistence.MongoDb.Options; +using Elsa.Services.Startup; +using Elsa.Webhooks.Persistence.MongoDb.Extensions; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; + +namespace Elsa.Webhooks.Persistence.MongoDb +{ + [Feature("Webhooks:Persistence:MongoDb")] + public class Startup : StartupBase + { + public override void ConfigureElsa(ElsaOptionsBuilder elsa, IConfiguration configuration) + { + var services = elsa.Services; + var section = configuration.GetSection($"Elsa:Persistence:MongoDb"); + var connectionStringName = section.GetValue("ConnectionStringName"); + var connectionString = section.GetValue("ConnectionString"); + + if (string.IsNullOrWhiteSpace(connectionString)) + { + if (string.IsNullOrWhiteSpace(connectionStringName)) + connectionStringName = "MongoDb"; + + connectionString = configuration.GetConnectionString(connectionStringName); + } + + if (string.IsNullOrWhiteSpace(connectionString)) + connectionString = "mongodb://localhost:27017/Elsa"; + + var webhookOptionsBuilder = new WebhookOptionsBuilder(services); + webhookOptionsBuilder.UseWebhookMongoDbPersistence(options => options.ConnectionString = connectionString); + + services.AddScoped(sp => webhookOptionsBuilder.WebhookOptions.WebhookDefinitionStoreFactory(sp)); + services.Decorate(); + services.Decorate(); + } + } +} diff --git a/src/activities/webhooks/Elsa.Webhooks.Persistence.YesSql/Documents/WebhookDefinitionDocument.cs b/src/activities/webhooks/Elsa.Webhooks.Persistence.YesSql/Documents/WebhookDefinitionDocument.cs index 3f51036c7..77d19a1ed 100644 --- a/src/activities/webhooks/Elsa.Webhooks.Persistence.YesSql/Documents/WebhookDefinitionDocument.cs +++ b/src/activities/webhooks/Elsa.Webhooks.Persistence.YesSql/Documents/WebhookDefinitionDocument.cs @@ -4,7 +4,7 @@ namespace Elsa.Webhooks.Persistence.YesSql.Documents { public class WebhookDefinitionDocument : YesSqlDocument { - public string WebhookDefinitionId { get; set; } = default!; + public string DefinitionId { get; set; } = default!; public string? TenantId { get; set; } public string Name { get; set; } = default!; public string Path { get; set; } = default!; diff --git a/src/activities/webhooks/Elsa.Webhooks.Persistence.YesSql/Elsa.Webhooks.Persistence.YesSql.csproj b/src/activities/webhooks/Elsa.Webhooks.Persistence.YesSql/Elsa.Webhooks.Persistence.YesSql.csproj index 276cdc71e..51288f19c 100644 --- a/src/activities/webhooks/Elsa.Webhooks.Persistence.YesSql/Elsa.Webhooks.Persistence.YesSql.csproj +++ b/src/activities/webhooks/Elsa.Webhooks.Persistence.YesSql/Elsa.Webhooks.Persistence.YesSql.csproj @@ -1,4 +1,4 @@ - + diff --git a/src/activities/webhooks/Elsa.Webhooks.Persistence.YesSql/Extensions/WebhookServiceCollectionExtensions.cs b/src/activities/webhooks/Elsa.Webhooks.Persistence.YesSql/Extensions/WebhookServiceCollectionExtensions.cs index b17632c1f..c1e5bdfd5 100644 --- a/src/activities/webhooks/Elsa.Webhooks.Persistence.YesSql/Extensions/WebhookServiceCollectionExtensions.cs +++ b/src/activities/webhooks/Elsa.Webhooks.Persistence.YesSql/Extensions/WebhookServiceCollectionExtensions.cs @@ -1,41 +1,45 @@ using System; +using System.Data; using Elsa.Activities.Webhooks; +using Elsa.Webhooks.Persistence.YesSql.Services; using Elsa.Persistence.YesSql; +using Elsa.Runtime; +using Elsa.Webhooks.Persistence.YesSql.Indexes; using Elsa.Webhooks.Persistence.YesSql.Stores; using Microsoft.Extensions.DependencyInjection; using YesSql; using YesSql.Indexes; -using Elsa.Runtime; -using Elsa.Webhooks.Persistence.YesSql.Mapping; -using Elsa.Persistence.YesSql.Services; +using YesSql.Provider.Sqlite; using Elsa.Persistence.YesSql.Data; -using Elsa.Webhooks.Persistence.YesSql.Indexes; +using Elsa.Webhooks.Persistence.YesSql.Mapping; namespace Elsa.Webhooks.Persistence.YesSql.Extensions { public static class WebhookServiceCollectionExtensions { - public static ElsaOptionsBuilder UseYesSqlPersistence(this ElsaOptionsBuilder elsa, Action configure) + 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 configure) => webhookOptions.UseWebhookYesSqlPersistence((_, config) => configure(config)); + + public static WebhookOptionsBuilder UseWebhookYesSqlPersistence(this WebhookOptionsBuilder webhookOptions, Action configure) { - elsa.Services + webhookOptions.Services .AddScoped() .AddSingleton(sp => CreateStore(sp, configure)) - .AddSingleton() - .AddScoped(CreateSession) - .AddScoped() .AddStartupTask() - .AddStartupTask() .AddDataMigration() .AddAutoMapperProfile() .AddIndexProvider(); - var webhookOptionsBuilder = new WebhookOptionsBuilder(elsa.Services); + webhookOptions.UseWebhookDefinitionStore(sp => sp.GetRequiredService()); - webhookOptionsBuilder.UseWebhookDefinitionStore(sp => sp.GetRequiredService()); - - return elsa; + return webhookOptions; } + public static IServiceCollection AddIndexProvider(this IServiceCollection services) where T : class, IIndexProvider => services.AddSingleton(); + public static IServiceCollection AddScopedIndexProvider(this IServiceCollection services) where T : class, IIndexProvider => services.AddScoped(); + + public static IServiceCollection AddDataMigration(this IServiceCollection services) where T : class, IDataMigration => services.AddScoped(); + private static IStore CreateStore( IServiceProvider serviceProvider, Action configure) @@ -59,7 +63,7 @@ namespace Elsa.Webhooks.Persistence.YesSql.Extensions private static ISession CreateSession(IServiceProvider serviceProvider) { - var provider = serviceProvider.GetRequiredService(); + var provider = serviceProvider.GetRequiredService(); return provider.CreateSession(); } } diff --git a/src/activities/webhooks/Elsa.Webhooks.Persistence.YesSql/Indexes/WebhookDefinitionIndex.cs b/src/activities/webhooks/Elsa.Webhooks.Persistence.YesSql/Indexes/WebhookDefinitionIndex.cs index 3c9ae4194..9897ee541 100644 --- a/src/activities/webhooks/Elsa.Webhooks.Persistence.YesSql/Indexes/WebhookDefinitionIndex.cs +++ b/src/activities/webhooks/Elsa.Webhooks.Persistence.YesSql/Indexes/WebhookDefinitionIndex.cs @@ -6,7 +6,7 @@ namespace Elsa.Webhooks.Persistence.YesSql.Indexes { public class WebhookDefinitionIndex : MapIndex { - public string WebhookDefinitionId { get; set; } = default!; + public string DefinitionId { get; set; } = default!; public string? TenantId { get; set; } public bool IsEnabled { get; set; } } @@ -21,7 +21,7 @@ namespace Elsa.Webhooks.Persistence.YesSql.Indexes .Map( webhookDefinition => new WebhookDefinitionIndex { - WebhookDefinitionId = webhookDefinition.WebhookDefinitionId, + DefinitionId = webhookDefinition.DefinitionId, TenantId = webhookDefinition.TenantId, IsEnabled = webhookDefinition.IsEnabled } diff --git a/src/activities/webhooks/Elsa.Webhooks.Persistence.YesSql/Mapping/AutoMapperProfile.cs b/src/activities/webhooks/Elsa.Webhooks.Persistence.YesSql/Mapping/AutoMapperProfile.cs index 86f3b1dad..59811bb2b 100644 --- a/src/activities/webhooks/Elsa.Webhooks.Persistence.YesSql/Mapping/AutoMapperProfile.cs +++ b/src/activities/webhooks/Elsa.Webhooks.Persistence.YesSql/Mapping/AutoMapperProfile.cs @@ -9,9 +9,10 @@ namespace Elsa.Webhooks.Persistence.YesSql.Mapping public AutoMapperProfile() { CreateMap() + .ForMember(d => d.DefinitionId, d => d.MapFrom(s => s.Id)) .ForMember(d => d.Id, d => d.Ignore()) .ReverseMap() - .ForMember(d => d.Id, d => d.MapFrom(s => s.Id)); + .ForMember(d => d.Id, d => d.MapFrom(s => s.DefinitionId)); } } } diff --git a/src/activities/webhooks/Elsa.Webhooks.Persistence.YesSql/Migrations.cs b/src/activities/webhooks/Elsa.Webhooks.Persistence.YesSql/Migrations.cs index 7a76e8f6c..c8455ec3f 100644 --- a/src/activities/webhooks/Elsa.Webhooks.Persistence.YesSql/Migrations.cs +++ b/src/activities/webhooks/Elsa.Webhooks.Persistence.YesSql/Migrations.cs @@ -11,7 +11,7 @@ namespace Elsa.Webhooks.Persistence.YesSql { SchemaBuilder.CreateMapIndexTable( table => table - .Column(nameof(WebhookDefinitionIndex.WebhookDefinitionId)) + .Column(nameof(WebhookDefinitionIndex.DefinitionId)) .Column(nameof(WebhookDefinitionIndex.TenantId)) .Column(nameof(WebhookDefinitionIndex.IsEnabled)), CollectionNames.WebhookDefinitions); diff --git a/src/activities/webhooks/Elsa.Webhooks.Persistence.YesSql/Services/DatabaseInitializer.cs b/src/activities/webhooks/Elsa.Webhooks.Persistence.YesSql/Services/DatabaseInitializer.cs new file mode 100644 index 000000000..cc9a3e3b2 --- /dev/null +++ b/src/activities/webhooks/Elsa.Webhooks.Persistence.YesSql/Services/DatabaseInitializer.cs @@ -0,0 +1,25 @@ +using System.Threading; +using System.Threading.Tasks; +using Elsa.Services; +using Elsa.Webhooks.Persistence.YesSql.Data; +using YesSql; + +namespace Elsa.Webhooks.Persistence.YesSql.Services +{ + public class DatabaseInitializer : IStartupTask + { + private readonly IStore _store; + + public DatabaseInitializer(IStore store) + { + _store = store; + } + + public int Order => 0; + + public async Task ExecuteAsync(CancellationToken cancellationToken = default) + { + await _store.InitializeCollectionAsync(CollectionNames.WebhookDefinitions); + } + } +} diff --git a/src/activities/webhooks/Elsa.Webhooks.Persistence.YesSql/Startups.cs b/src/activities/webhooks/Elsa.Webhooks.Persistence.YesSql/Startups.cs new file mode 100644 index 000000000..51081f3cf --- /dev/null +++ b/src/activities/webhooks/Elsa.Webhooks.Persistence.YesSql/Startups.cs @@ -0,0 +1,78 @@ +using System; +using Elsa.Activities.Webhooks; +using Elsa.Activities.Webhooks.Persistence.Decorators; +using Elsa.Attributes; +using Elsa.Services.Startup; +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; +using YesSql.Provider.SqlServer; + +namespace Elsa.Webhooks.Persistence.YesSql +{ + [Feature("Webhooks:Persistence:YesSql:Sqlite")] + public class SqliteStartup : YesSqlStartupBase + { + protected override string ProviderName => "Sqlite"; + protected override string GetDefaultConnectionString() => "Data Source=elsa.yessql.db;Cache=Shared"; + protected override void Configure(global::YesSql.IConfiguration options, string connectionString) => options.UseSqLite(connectionString); + } + + [Feature("Webhooks:Persistence:YesSql:SqlServer")] + public class SqlServerStartup : YesSqlStartupBase + { + protected override string ProviderName => "SqlServer"; + protected override void Configure(global::YesSql.IConfiguration options, string connectionString) => options.UseSqlServer(connectionString); + } + + [Feature("Webhooks:Persistence:YesSql:MySql")] + public class MySqlStartup : YesSqlStartupBase + { + protected override string ProviderName => "MySql"; + protected override void Configure(global::YesSql.IConfiguration options, string connectionString) => options.UseMySql(connectionString); + } + + [Feature("Webhooks:Persistence:YesSql:PostgreSql")] + public class PostgreSqlStartup : YesSqlStartupBase + { + protected override string ProviderName => "PostgreSql"; + protected override void Configure(global::YesSql.IConfiguration options, string connectionString) => options.UsePostgreSql(connectionString); + } + + public abstract class YesSqlStartupBase : StartupBase + { + protected abstract string ProviderName { get; } + + public override void ConfigureElsa(ElsaOptionsBuilder elsa, IConfiguration configuration) + { + var services = elsa.Services; + var section = configuration.GetSection($"Elsa:Persistence:{ProviderName}"); + var connectionStringName = section.GetValue("ConnectionStringName"); + var connectionString = section.GetValue("ConnectionString"); + + if (string.IsNullOrWhiteSpace(connectionString)) + { + if (string.IsNullOrWhiteSpace(connectionStringName)) + connectionStringName = ProviderName; + + connectionString = configuration.GetConnectionString(connectionStringName); + } + + if (string.IsNullOrWhiteSpace(connectionString)) + connectionString = GetDefaultConnectionString(); + + var webhookOptionsBuilder = new WebhookOptionsBuilder(services); + webhookOptionsBuilder.UseWebhookYesSqlPersistence(options => Configure(options, connectionString)); + + services.AddScoped(sp => webhookOptionsBuilder.WebhookOptions.WebhookDefinitionStoreFactory(sp)); + services.Decorate(); + services.Decorate(); + } + + protected virtual string GetDefaultConnectionString() => throw new Exception($"No connection string specified for the {ProviderName} provider"); + protected abstract void Configure(global::YesSql.IConfiguration options, string connectionString); + } +} diff --git a/src/activities/webhooks/Elsa.Webhooks.Persistence.YesSql/Stores/YesSqlWebhookDefinitionStore.cs b/src/activities/webhooks/Elsa.Webhooks.Persistence.YesSql/Stores/YesSqlWebhookDefinitionStore.cs index e1002acf6..6d6cfbb78 100644 --- a/src/activities/webhooks/Elsa.Webhooks.Persistence.YesSql/Stores/YesSqlWebhookDefinitionStore.cs +++ b/src/activities/webhooks/Elsa.Webhooks.Persistence.YesSql/Stores/YesSqlWebhookDefinitionStore.cs @@ -21,13 +21,13 @@ namespace Elsa.Webhooks.Persistence.YesSql.Stores { } - protected override async Task FindDocumentAsync(ISession session, WebhookDefinition entity, CancellationToken cancellationToken) => await Query(session, x => x.WebhookDefinitionId == entity.Id).FirstOrDefaultAsync(); + protected override async Task FindDocumentAsync(ISession session, WebhookDefinition entity, CancellationToken cancellationToken) => await Query(session, x => x.DefinitionId == entity.Id).FirstOrDefaultAsync(); protected override IQuery MapSpecification(ISession session, ISpecification specification) { return specification switch { - EntityIdSpecification s => Query(session, x => x.WebhookDefinitionId == s.Id), + EntityIdSpecification s => Query(session, x => x.DefinitionId == s.Id), _ => AutoMapSpecification(session, specification) }; } diff --git a/src/designer/elsa-workflows-studio/src/components/screens/webhook-definition-editor/elsa-webhook-definition-editor-screen/elsa-webhook-definition-editor-screen.tsx b/src/designer/elsa-workflows-studio/src/components/screens/webhook-definition-editor/elsa-webhook-definition-editor-screen/elsa-webhook-definition-editor-screen.tsx index f99812138..e912d2cb5 100644 --- a/src/designer/elsa-workflows-studio/src/components/screens/webhook-definition-editor/elsa-webhook-definition-editor-screen/elsa-webhook-definition-editor-screen.tsx +++ b/src/designer/elsa-workflows-studio/src/components/screens/webhook-definition-editor/elsa-webhook-definition-editor-screen/elsa-webhook-definition-editor-screen.tsx @@ -94,7 +94,6 @@ export class ElsaWebhookDefinitionEditorScreen { this.saving = true; try { - if (request.id == null) webhookDefinition = await client.webhookDefinitionsApi.save(request); else diff --git a/src/samples/server/Elsa.Samples.Server.Host/Elsa.Samples.Server.Host.csproj b/src/samples/server/Elsa.Samples.Server.Host/Elsa.Samples.Server.Host.csproj index 32b93819f..3d2644be1 100644 --- a/src/samples/server/Elsa.Samples.Server.Host/Elsa.Samples.Server.Host.csproj +++ b/src/samples/server/Elsa.Samples.Server.Host/Elsa.Samples.Server.Host.csproj @@ -24,6 +24,10 @@ + + + + diff --git a/src/samples/server/Elsa.Samples.Server.Host/README.md b/src/samples/server/Elsa.Samples.Server.Host/README.md new file mode 100644 index 000000000..ea7b451d1 --- /dev/null +++ b/src/samples/server/Elsa.Samples.Server.Host/README.md @@ -0,0 +1,143 @@ +### Configure persistence in appsettings.json + +EF Sqlite +``` +"Elsa": { +"Features": [ + "Persistence:EntityFrameworkCore:Sqlite", + ... + ], +} +``` + +EF MySQL +``` +"Elsa": { +"Features": [ + "Persistence:EntityFrameworkCore:MySql", + ... + ], +} +``` + +EF SQL Server +``` +"Elsa": { +"Features": [ + "Persistence:EntityFrameworkCore:SqlServer", + ... + ], +} +``` + +EF Postgre +``` +"Elsa": { +"Features": [ + "Persistence:EntityFrameworkCore:PostgreSql", + ... + ], +} +``` + +EF MongoDB +``` +"Elsa": { +"Features": [ + "Persistence:MongoDb", + ... + ], +} +``` + +YesSql Sqlite +``` +"Elsa": { +"Features": [ + "Persistence:YesSql:Sqlite", + ... + ], +} +``` + +YesSql MySQL +``` +"Elsa": { +"Features": [ + "Persistence:YesSql:MySql", + ... + ], +} +``` + +YesSql SQL Server +``` +"Elsa": { +"Features": [ + "Persistence:YesSql:SqlServer", + ... + ], +} +``` + +YesSql Postgre +``` +"Elsa": { +"Features": [ + "Persistence:YesSql:PostgreSql", + ... + ], +} +``` + +### 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 + +``` + "ConnectionStrings": { + ... + "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;", + "MongoDb": "mongodb://localhost:27017/Elsa", + "PostgreSql": "Server=127.0.0.1;Port=5433;Database=elsa;User Id=postgres;Password=Password12!;" + }, +``` + +### Connection strings +MySql +https://www.connectionstrings.com/mysql/ +SQL Server +https://www.connectionstrings.com/sql-server/ +Postgres +https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING +MongoDb +https://docs.mongodb.com/manual/reference/connection-string/ \ No newline at end of file diff --git a/src/samples/server/Elsa.Samples.Server.Host/Startup.cs b/src/samples/server/Elsa.Samples.Server.Host/Startup.cs index 21277d1dd..4178a5ff0 100644 --- a/src/samples/server/Elsa.Samples.Server.Host/Startup.cs +++ b/src/samples/server/Elsa.Samples.Server.Host/Startup.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using Elsa.Samples.Server.Host.Activities; using Elsa.Server.Hangfire.Extensions; using Hangfire; using Microsoft.AspNetCore.Builder; @@ -32,7 +33,6 @@ namespace Elsa.Samples.Server.Host { typeof(Elsa.Activities.Console.Startup), typeof(Elsa.Activities.Http.Startup), - typeof(Elsa.Activities.Webhooks.Startup), typeof(Elsa.Activities.AzureServiceBus.Startup), typeof(Elsa.Activities.Conductor.Startup), typeof(Elsa.Activities.UserTask.Startup), @@ -51,6 +51,16 @@ namespace Elsa.Samples.Server.Host typeof(Persistence.YesSql.PostgreSqlStartup), typeof(Elsa.Server.Hangfire.Startup), typeof(Elsa.Scripting.JavaScript.Startup), + typeof(Elsa.Activities.Webhooks.Startup), + typeof(Webhooks.Persistence.EntityFramework.Sqlite.Startup), + typeof(Webhooks.Persistence.EntityFramework.SqlServer.Startup), + typeof(Webhooks.Persistence.EntityFramework.MySql.Startup), + typeof(Webhooks.Persistence.EntityFramework.PostgreSql.Startup), + typeof(Webhooks.Persistence.MongoDb.Startup), + typeof(Webhooks.Persistence.YesSql.SqliteStartup), + typeof(Webhooks.Persistence.YesSql.SqlServerStartup), + typeof(Webhooks.Persistence.YesSql.MySqlStartup), + typeof(Webhooks.Persistence.YesSql.PostgreSqlStartup), }; services diff --git a/src/samples/server/Elsa.Samples.Server.Host/appsettings.json b/src/samples/server/Elsa.Samples.Server.Host/appsettings.json index 2f4d069c8..4a9984de6 100644 --- a/src/samples/server/Elsa.Samples.Server.Host/appsettings.json +++ b/src/samples/server/Elsa.Samples.Server.Host/appsettings.json @@ -11,9 +11,11 @@ "ConnectionStrings": { "RabbitMq": "amqp://localhost:5672", "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;", - "MongoDb": "mongodb://localhost:27017/Elsa" + "Sqlite": "Data Source=elsa.sqlite.yes.db;Cache=Shared;", + "MongoDb": "mongodb://localhost:27017/Elsa", + "PostgreSql": "Server=127.0.0.1;Port=5432;Database=elsa;User Id=postgres;Password=password;" }, "Elsa": { "Features": [ @@ -26,8 +28,25 @@ "JavaScript:Activities", "UserTask", "Conductor", - "Telnyx" + "Telnyx", + "Webhooks", + "Webhooks:Persistence:EntityFrameworkCore:Sqlite" ], + "Persistence:MySql": { + "ConnectionStringName": "MySql" + }, + "Persistence:SqlServer": { + "ConnectionStringName": "SqlServer" + }, + "Persistence:Sqlite": { + "ConnectionStringName": "Sqlite" + }, + "Persistence:MongoDb": { + "ConnectionStringName": "MongoDb" + }, + "Persistence:PostgreSql": { + "ConnectionStringName": "PostgreSql" + }, "WorkflowChannels": { "Channels": [ "High", @@ -35,10 +54,7 @@ "Low" ], "Default": "Normal" - }, - "Persistence:Sqlite": { - "ConnectionStringName": "Sqlite" - }, + }, "Http": { "BaseUrl": "https://localhost:11000", "BasePath": "/workflows"