diff --git a/src/modules/Elsa.Alterations.Core/Contexts/AlterationHandlerContext.cs b/src/modules/Elsa.Alterations.Core/Contexts/AlterationHandlerContext.cs index b883fcdb4..f583f6cd3 100644 --- a/src/modules/Elsa.Alterations.Core/Contexts/AlterationHandlerContext.cs +++ b/src/modules/Elsa.Alterations.Core/Contexts/AlterationHandlerContext.cs @@ -74,11 +74,12 @@ public class AlterationContext /// /// Logs a message. /// + /// The event name to log. /// The message to log. /// The log level. - public void Log(string message, LogLevel logLevel = LogLevel.Information) + public void Log(string eventName, string message, LogLevel logLevel = LogLevel.Information) { - AlterationLog.Add(message, logLevel); + AlterationLog.Add(message, logLevel, eventName); } /// @@ -104,7 +105,7 @@ public class AlterationContext public void Succeed(string message) { HasSucceeded = true; - Log(message, LogLevel.Information); + Log($"Alteration {Alteration.GetType().Name} succeeded", message, LogLevel.Information); } /// @@ -123,6 +124,6 @@ public class AlterationContext public void Fail(string? message = default) { HasFailed = true; - Log(message ?? $"{Alteration.GetType().Name} failed", LogLevel.Error); + Log($"Alteration {Alteration.GetType().Name} failed", message ?? $"{Alteration.GetType().Name} failed", LogLevel.Error); } } \ No newline at end of file diff --git a/src/modules/Elsa.Alterations.Core/Models/AlterationLog.cs b/src/modules/Elsa.Alterations.Core/Models/AlterationLog.cs index 1130d39e7..727f8c87b 100644 --- a/src/modules/Elsa.Alterations.Core/Models/AlterationLog.cs +++ b/src/modules/Elsa.Alterations.Core/Models/AlterationLog.cs @@ -24,15 +24,16 @@ public class AlterationLog /// Gets the log entries. /// public IReadOnlyCollection LogEntries => _logEntries.ToList().AsReadOnly(); - + /// /// Adds a log entry. /// /// The message. /// The log level. - public void Add(string message, LogLevel logLevel = LogLevel.Information) + /// The event that generated the log entry. + public void Add(string message, LogLevel logLevel = LogLevel.Information, string? eventName = null) { - var entry = new AlterationLogEntry(message, logLevel, _systemClock.UtcNow); + var entry = new AlterationLogEntry(message, logLevel, _systemClock.UtcNow, eventName); _logEntries.Add(entry); } diff --git a/src/modules/Elsa.Alterations.Core/Models/AlterationLogEntry.cs b/src/modules/Elsa.Alterations.Core/Models/AlterationLogEntry.cs index af8b7d8ae..77b772c65 100644 --- a/src/modules/Elsa.Alterations.Core/Models/AlterationLogEntry.cs +++ b/src/modules/Elsa.Alterations.Core/Models/AlterationLogEntry.cs @@ -8,4 +8,5 @@ namespace Elsa.Alterations.Core.Models; /// The log message. /// The log level. /// The timestamp when the log entry was created. -public record AlterationLogEntry(string Message, LogLevel LogLevel, DateTimeOffset Timestamp); \ No newline at end of file +/// The event that generated the log entry. +public record AlterationLogEntry(string Message, LogLevel LogLevel, DateTimeOffset Timestamp, string? EventName = null); \ No newline at end of file diff --git a/src/modules/Elsa.Alterations/Middleware/Workflows/RunAlterationsMiddleware.cs b/src/modules/Elsa.Alterations/Middleware/Workflows/RunAlterationsMiddleware.cs index c038da498..f412a8cb7 100644 --- a/src/modules/Elsa.Alterations/Middleware/Workflows/RunAlterationsMiddleware.cs +++ b/src/modules/Elsa.Alterations/Middleware/Workflows/RunAlterationsMiddleware.cs @@ -50,5 +50,9 @@ internal class RunAlterationsMiddleware(WorkflowMiddlewareDelegate next, IEnumer // Execute commit handlers. foreach (var commitAction in commitActions) await commitAction(); + + // Add alteration logs to the workflow execution log. + foreach (var alterationLogEntry in log.LogEntries) + workflowExecutionContext.AddExecutionLogEntry(alterationLogEntry.EventName ?? alterationLogEntry.Message, alterationLogEntry.Message); } } \ No newline at end of file diff --git a/src/modules/Elsa.EntityFrameworkCore.PostgreSql/Handlers/DbExceptionTransformer.cs b/src/modules/Elsa.EntityFrameworkCore.PostgreSql/Handlers/DbExceptionTransformer.cs index b822bc3e8..cca8723af 100644 --- a/src/modules/Elsa.EntityFrameworkCore.PostgreSql/Handlers/DbExceptionTransformer.cs +++ b/src/modules/Elsa.EntityFrameworkCore.PostgreSql/Handlers/DbExceptionTransformer.cs @@ -20,8 +20,9 @@ public class DbExceptionTransformer : IDbExceptionHandler expando) - { - var jsObject = engine.Intrinsics.Object.Construct([]); - - foreach (var kvp in expando) - { - var value = kvp.Value; - var jsValue = ConvertToJsValue(engine, value); - var propertyDescriptor = new PropertyDescriptor(jsValue, true, true, true); - jsObject.DefineOwnProperty(kvp.Key, propertyDescriptor); - } - - return jsObject; - } - - private static JsValue ConvertToJsValue(Engine engine, object? value) - { - if (value == null) - return JsValue.Null; - - if (value is IDictionary dict) - return ConvertToJsObject(engine, dict); - - var valueType = value.GetType(); - if (valueType.IsCollectionType()) - { - var list = (ICollection)value; - var jsArray = engine.Intrinsics.Array.Construct(list.Count); - var index = 0; - - foreach (var item in list) - jsArray.Set(index++, ConvertToJsValue(engine, item), true); - - return jsArray; - } - - if (value is string str) - return JsValue.FromObject(engine, str); - - if (value is int or double or float or decimal) - return JsValue.FromObject(engine, Convert.ToDouble(value)); - - if (value is bool b) - return JsValue.FromObject(engine, b); - - return JsValue.FromObject(engine, value); - } -} \ No newline at end of file diff --git a/src/modules/Elsa.JavaScript/ObjectConverters/ExpandoObjectConverter.cs b/src/modules/Elsa.JavaScript/ObjectConverters/ExpandoObjectConverter.cs deleted file mode 100644 index 23976a57c..000000000 --- a/src/modules/Elsa.JavaScript/ObjectConverters/ExpandoObjectConverter.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System.Dynamic; -using Elsa.JavaScript.Helpers; -using Jint; -using Jint.Native; -using Jint.Runtime.Interop; - -namespace Elsa.JavaScript.ObjectConverters; - -internal class ExpandoObjectConverter : IObjectConverter -{ - public bool TryConvert(Engine engine, object value, out JsValue result) - { - if (value is ExpandoObject expandoObject) - { - result = ConverterHelper.ConvertToJsObject(engine, expandoObject); - return true; - } - - result = JsValue.Null; - return false; - } -} \ No newline at end of file diff --git a/src/modules/Elsa.JavaScript/Services/JintJavaScriptEvaluator.cs b/src/modules/Elsa.JavaScript/Services/JintJavaScriptEvaluator.cs index cece9a3a2..3baad6659 100644 --- a/src/modules/Elsa.JavaScript/Services/JintJavaScriptEvaluator.cs +++ b/src/modules/Elsa.JavaScript/Services/JintJavaScriptEvaluator.cs @@ -90,7 +90,7 @@ public class JintJavaScriptEvaluator(IConfiguration configuration, INotification private void ConfigureObjectConverters(Jint.Options options) { - options.Interop.ObjectConverters.AddRange([new ByteArrayConverter(), new ExpandoObjectConverter()]); + options.Interop.ObjectConverters.AddRange([new ByteArrayConverter()]); } private void ConfigureArgumentGetters(Engine engine, ExpressionEvaluatorOptions options) diff --git a/src/modules/Elsa.MongoDb/Common/MongoDbStore.cs b/src/modules/Elsa.MongoDb/Common/MongoDbStore.cs index 44763c3a7..1384bb060 100644 --- a/src/modules/Elsa.MongoDb/Common/MongoDbStore.cs +++ b/src/modules/Elsa.MongoDb/Common/MongoDbStore.cs @@ -43,6 +43,10 @@ public class MongoDbStore(IMongoCollection collection, ITe public async Task AddManyAsync(IEnumerable documents, CancellationToken cancellationToken = default) { var documentsList = documents.ToList(); + + if (!documentsList.Any()) + return; + await ApplyTenantIdAsync(documentsList, cancellationToken); await collection.InsertManyAsync(documentsList, new InsertManyOptions(), cancellationToken); } diff --git a/src/modules/Elsa.Workflows.Core/Exceptions/DataProcessingException.cs b/src/modules/Elsa.Workflows.Core/Exceptions/DataProcessingException.cs index 2af7ab1e2..ddd2676a7 100644 --- a/src/modules/Elsa.Workflows.Core/Exceptions/DataProcessingException.cs +++ b/src/modules/Elsa.Workflows.Core/Exceptions/DataProcessingException.cs @@ -1,8 +1,4 @@ namespace Elsa.Workflows.Exceptions; /// An exception that occurs during data processing. -public class DataProcessingException(bool isUkViolation, string message, Exception exception) : Exception(message, exception) -{ - /// Gets a value indicating whether the exception is a Unique Key violation. - public bool IsUkViolation { get; } = isUkViolation; -} +public class DataProcessingException(string message, Exception exception) : Exception(message, exception); diff --git a/src/modules/Elsa.Workflows.Core/Exceptions/UniqueKeyConstraintViolationException.cs b/src/modules/Elsa.Workflows.Core/Exceptions/UniqueKeyConstraintViolationException.cs new file mode 100644 index 000000000..26f87ff5e --- /dev/null +++ b/src/modules/Elsa.Workflows.Core/Exceptions/UniqueKeyConstraintViolationException.cs @@ -0,0 +1,4 @@ +namespace Elsa.Workflows.Exceptions; + +/// An exception that when a unique key constraint has been violated. +public class UniqueKeyConstraintViolationException(string message, Exception exception) : Exception(message, exception); diff --git a/test/integration/Elsa.Workflows.IntegrationTests/Scenarios/JavaScriptListsAndArrays/Tests.cs b/test/integration/Elsa.Workflows.IntegrationTests/Scenarios/JavaScriptListsAndArrays/Tests.cs index dddabed51..537b86c0d 100644 --- a/test/integration/Elsa.Workflows.IntegrationTests/Scenarios/JavaScriptListsAndArrays/Tests.cs +++ b/test/integration/Elsa.Workflows.IntegrationTests/Scenarios/JavaScriptListsAndArrays/Tests.cs @@ -79,9 +79,11 @@ public class Tests Assert.Equal(43, magicNumber); } - [Theory(DisplayName = "Can sort array and list properties as mutable arrays")] + [Theory(DisplayName = "Can sort array and list properties as mutable arrays", Skip = "Not supported yet. See https://github.com/elsa-workflows/elsa-core/issues/5912")] [MemberData(nameof(ArraySortEnumerableData))] - // See also: https://github.com/sebastienros/jint/issues/1942 + // See also: + // - https://github.com/sebastienros/jint/issues/1942 + // - https://github.com/elsa-workflows/elsa-core/issues/5912 public async Task Test5(IEnumerable collection) { dynamic dynamicObject = new ExpandoObject();