From 882ea8cf571c6cb04152e1045eeff21852c24df4 Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Thu, 13 Mar 2025 11:54:28 +0100 Subject: [PATCH 1/4] Refactor variable merging logic in ActivityExecutionContext Replaced LINQ-based logic with a dictionary approach to merge variables. This ensures that variables are consistently merged by either name or ID when name is absent. It improves code clarity and handles edge cases more robustly. --- .../Contexts/ActivityExecutionContext.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/modules/Elsa.Workflows.Core/Contexts/ActivityExecutionContext.cs b/src/modules/Elsa.Workflows.Core/Contexts/ActivityExecutionContext.cs index 6ecc474d1..ceae56077 100644 --- a/src/modules/Elsa.Workflows.Core/Contexts/ActivityExecutionContext.cs +++ b/src/modules/Elsa.Workflows.Core/Contexts/ActivityExecutionContext.cs @@ -124,7 +124,20 @@ public partial class ActivityExecutionContext : IExecutionContext, IDisposable { var containerVariables = (Activity as IVariableContainer)?.Variables ?? Enumerable.Empty(); var dynamicVariables = DynamicVariables; - return containerVariables.Concat(dynamicVariables).DistinctBy(x => x.Name); + var mergedVariables = new Dictionary(); + + foreach (var containerVariable in containerVariables) + { + var name = !string.IsNullOrEmpty(containerVariable.Name) ? containerVariable.Name : containerVariable.Id; + mergedVariables[name] = containerVariable; + } + + foreach (var dynamicVariable in dynamicVariables) + { + var name = !string.IsNullOrEmpty(dynamicVariable.Name) ? dynamicVariable.Name : dynamicVariable.Id; + mergedVariables[name] = dynamicVariable; + } + return mergedVariables.Values; } } From e3e298984f0c568fc0c89058cc805ad5e65e4292 Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Thu, 13 Mar 2025 11:54:46 +0100 Subject: [PATCH 2/4] Refactor Variable class and add WithId method Replaced `default` with `null` to improve readability and clarify initialization. Added a `WithId` method to allow assigning an ID to `Variable` instances for enhanced configurability. These changes improve usability and maintain consistency in the codebase. --- src/modules/Elsa.Workflows.Core/Memory/Variable.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/modules/Elsa.Workflows.Core/Memory/Variable.cs b/src/modules/Elsa.Workflows.Core/Memory/Variable.cs index 78b577070..d3ed28f2f 100644 --- a/src/modules/Elsa.Workflows.Core/Memory/Variable.cs +++ b/src/modules/Elsa.Workflows.Core/Memory/Variable.cs @@ -21,7 +21,7 @@ public class Variable : MemoryBlockReference } /// - public Variable(string name, object? value = default) : this() + public Variable(string name, object? value = null) : this() { Name = name; Value = value; @@ -30,7 +30,7 @@ public class Variable : MemoryBlockReference /// /// The name of the variable. /// - public string Name { get; set; } = default!; + public string Name { get; set; } = null!; /// /// A default value for the variable. @@ -89,6 +89,12 @@ public class Variable : Variable StorageDriverType = typeof(TDriver); return this; } + + public Variable WithId(string id) + { + Id = id; + return this; + } } /// From e288ecb954a888244dda198e6270c4a90ac31200 Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Thu, 13 Mar 2025 11:54:54 +0100 Subject: [PATCH 3/4] Add SQL Server service to Docker Compose configuration Introduced an SQL Server service using the official 2022 image. Configured environment variables, ports, and a volume for persistent data storage. This addition supports development and testing scenarios requiring SQL Server. --- docker/docker-compose.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 137a6cc77..31b609b1e 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -12,6 +12,16 @@ ports: - "5432:5432" + sqlserver: + image: mcr.microsoft.com/mssql/server:2022-latest + environment: + - ACCEPT_EULA=Y + - MSSQL_SA_PASSWORD=!Elsa2025@ + ports: + - 1433:1433 + volumes: + - sqlserver_data:/var/opt/mssql + mysql: image: mysql:8.0 container_name: mysql @@ -126,6 +136,7 @@ - "14000:8080" volumes: + sqlserver_data: postgres-data: oracle-data-free1: mysql_data2: From ff60c4c461db0e2d2aa504a7b9b2d5c066721206 Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Thu, 13 Mar 2025 11:55:07 +0100 Subject: [PATCH 4/4] Add SQL Server connection string to appsettings.json This change introduces a connection string for SQL Server to the configuration file. It enables the application to connect to a SQL Server database for data persistence and retrieval. --- src/apps/Elsa.Server.Web/appsettings.json | 1 + 1 file changed, 1 insertion(+) diff --git a/src/apps/Elsa.Server.Web/appsettings.json b/src/apps/Elsa.Server.Web/appsettings.json index 9010bf944..3fc86acdb 100644 --- a/src/apps/Elsa.Server.Web/appsettings.json +++ b/src/apps/Elsa.Server.Web/appsettings.json @@ -13,6 +13,7 @@ "AllowedHosts": "*", "ConnectionStrings": { "Sqlite": "Data Source=App_Data/elsa.sqlite.db;Cache=Shared;", + "SqlServer": "Server=localhost,1433;Initial Catalog=Elsa;User=sa;Password=!Elsa2025@;Encrypt=false;PersistSecurityInfo=false", "MySql": "Server=localhost;Database=elsa;Uid=admin;Pwd=password;", "PostgreSql": "Server=localhost;Username=elsa;Database=elsa;Port=5432;Password=elsa;SSLMode=Prefer;MaxPoolSize=2000;Timeout=60", "Citus": "Server=localhost;Username=citus;Database=citus;Port=9700;Password=citus;SSLMode=Prefer;MaxPoolSize=2000;Timeout=60",