2023-10-10 10:34:32 +00:00
|
|
|
using Elsa.Extensions;
|
2024-04-19 19:57:55 +00:00
|
|
|
using Elsa.Workflows.Activities;
|
2024-03-30 20:22:35 +00:00
|
|
|
using Elsa.Workflows.Enums;
|
|
|
|
|
using Elsa.Workflows.Management.Options;
|
Add a more generic UIHandler to customize how inputAttributes can be handle by UI (#4688)
* add a more generic UIHandler to customize how inputAttributes can be handle by the ui
* Add IPropertyUIHandlerResolver and update PropertyUIHandlerResolver
Introduced a new interface, IPropertyUIHandlerResolver, to resolve UI options for a property. Refactored PropertyUIHandlerResolver to implement this interface and removed the unnecessary partial class structure. Also, cleaned up some unnecessary usings in various files for better code organization.
* Refactor variable name and description in InputDescriptor
The 'uISpecifications' variable in the InputDescriptor model is renamed to 'uiSpecifications' for better readability. Additionally, the associated comment was revised to explain that the dictionary is used by the UI.
* "Refactor codebase for improved organization and cleaner architecture"
The codebase has been significantly refactored, moving several classes to more appropriate namespaces for improved organization and cleaner architecture. This includes shifting UI hint handlers, activities, and memory-related components, amongst others. The changes should improve code readability and maintainability, but as this is a broad refactoring effort, thorough regression testing is advised.
* Add CheckList UIHint with associated handler and provider
This update introduces a new UIHint called CheckList to the Elsa.Workflows.Core. This includes the necessary handler and provider classes. The handler is registered in the WorkflowsFeature.cs, and the CheckList UIHint key has been added to the InputUIHints.cs. Various associated files have been created in both the Elsa.Api.Client and Elsa.Workflows.Core project to support this new UIHint.
---------
Co-authored-by: Jérémie DEVILLARD <jdevillard@users.noreply.github.com>
Co-authored-by: Sipke Schoorstra <sipkeschoorstra@outlook.com>
2023-12-26 17:56:29 +00:00
|
|
|
using Elsa.Workflows.Models;
|
2023-10-10 10:34:32 +00:00
|
|
|
using Elsa.Workflows.Runtime.Contracts;
|
|
|
|
|
using Elsa.Workflows.Runtime.Entities;
|
Add a more generic UIHandler to customize how inputAttributes can be handle by UI (#4688)
* add a more generic UIHandler to customize how inputAttributes can be handle by the ui
* Add IPropertyUIHandlerResolver and update PropertyUIHandlerResolver
Introduced a new interface, IPropertyUIHandlerResolver, to resolve UI options for a property. Refactored PropertyUIHandlerResolver to implement this interface and removed the unnecessary partial class structure. Also, cleaned up some unnecessary usings in various files for better code organization.
* Refactor variable name and description in InputDescriptor
The 'uISpecifications' variable in the InputDescriptor model is renamed to 'uiSpecifications' for better readability. Additionally, the associated comment was revised to explain that the dictionary is used by the UI.
* "Refactor codebase for improved organization and cleaner architecture"
The codebase has been significantly refactored, moving several classes to more appropriate namespaces for improved organization and cleaner architecture. This includes shifting UI hint handlers, activities, and memory-related components, amongst others. The changes should improve code readability and maintainability, but as this is a broad refactoring effort, thorough regression testing is advised.
* Add CheckList UIHint with associated handler and provider
This update introduces a new UIHint called CheckList to the Elsa.Workflows.Core. This includes the necessary handler and provider classes. The handler is registered in the WorkflowsFeature.cs, and the CheckList UIHint key has been added to the InputUIHints.cs. Various associated files have been created in both the Elsa.Api.Client and Elsa.Workflows.Core project to support this new UIHint.
---------
Co-authored-by: Jérémie DEVILLARD <jdevillard@users.noreply.github.com>
Co-authored-by: Sipke Schoorstra <sipkeschoorstra@outlook.com>
2023-12-26 17:56:29 +00:00
|
|
|
using Elsa.Workflows.State;
|
2024-03-30 20:22:35 +00:00
|
|
|
using Humanizer;
|
|
|
|
|
using Microsoft.Extensions.Options;
|
2023-10-10 10:34:32 +00:00
|
|
|
|
|
|
|
|
namespace Elsa.Workflows.Runtime.Services;
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
2024-04-12 13:00:00 +00:00
|
|
|
public class DefaultActivityExecutionMapper(IOptions<ManagementOptions> options) : IActivityExecutionMapper
|
|
|
|
|
{
|
|
|
|
|
private const string LogPersistenceModeKey = "logPersistenceMode";
|
|
|
|
|
|
2023-10-10 10:34:32 +00:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public ActivityExecutionRecord Map(ActivityExecutionContext source)
|
2024-04-12 13:00:00 +00:00
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
* {
|
|
|
|
|
* "logPersistenceMode": {
|
|
|
|
|
* "default": "default",
|
|
|
|
|
* "inputs": { k : v },
|
|
|
|
|
* "outputs": { k: v }
|
|
|
|
|
* }
|
|
|
|
|
* }
|
|
|
|
|
*/
|
|
|
|
|
|
2024-04-19 19:57:55 +00:00
|
|
|
var workflow = (Workflow?)source.GetAncestors().FirstOrDefault(x => x.Activity is Workflow)?.Activity ?? source.WorkflowExecutionContext.Workflow;
|
|
|
|
|
var workflowPersistenceProperty = GetDefaultPersistenceMode(workflow.CustomProperties, () => options.Value.LogPersistenceMode);
|
2024-04-12 13:00:00 +00:00
|
|
|
var activityPersistenceProperties = source.Activity.CustomProperties.GetValueOrDefault<IDictionary<string, object?>>(LogPersistenceModeKey, () => new Dictionary<string, object?>());
|
|
|
|
|
var activityPersistencePropertyDefault = GetDefaultPersistenceMode(source.Activity.CustomProperties, () => workflowPersistenceProperty);
|
|
|
|
|
|
2023-10-10 10:34:32 +00:00
|
|
|
// Get any outcomes that were added to the activity execution context.
|
2023-10-13 08:34:21 +00:00
|
|
|
var outcomes = source.JournalData.TryGetValue("Outcomes", out var resultValue) ? resultValue as string[] : default;
|
|
|
|
|
var payload = new Dictionary<string, object>();
|
|
|
|
|
|
|
|
|
|
if (outcomes != null)
|
|
|
|
|
payload.Add("Outcomes", outcomes);
|
|
|
|
|
|
|
|
|
|
// Get any outputs that were added to the activity execution context.
|
|
|
|
|
var activity = source.Activity;
|
|
|
|
|
var expressionExecutionContext = source.ExpressionExecutionContext;
|
|
|
|
|
var activityDescriptor = source.ActivityDescriptor;
|
|
|
|
|
var outputDescriptors = activityDescriptor.Outputs;
|
|
|
|
|
|
|
|
|
|
var outputs = outputDescriptors.ToDictionary(x => x.Name, x =>
|
|
|
|
|
{
|
|
|
|
|
if (x.IsSerializable == false)
|
|
|
|
|
return "(not serializable)";
|
|
|
|
|
|
|
|
|
|
var cachedValue = activity.GetOutput(expressionExecutionContext, x.Name);
|
|
|
|
|
|
|
|
|
|
if (cachedValue != default)
|
|
|
|
|
return cachedValue;
|
|
|
|
|
|
|
|
|
|
if (x.ValueGetter(activity) is Output output && source.TryGet(output.MemoryBlockReference(), out var outputValue))
|
|
|
|
|
return outputValue;
|
|
|
|
|
|
|
|
|
|
return default;
|
|
|
|
|
});
|
2024-04-12 13:00:00 +00:00
|
|
|
|
|
|
|
|
outputs = StorePropertyUsingPersistenceMode(outputs, activityPersistenceProperties!.GetValueOrDefault("outputs", () => new Dictionary<string, object>())!, activityPersistencePropertyDefault);
|
|
|
|
|
var activityState = StorePropertyUsingPersistenceMode(source.ActivityState, activityPersistenceProperties!.GetValueOrDefault("inputs", () => new Dictionary<string, object>())!, activityPersistencePropertyDefault);
|
|
|
|
|
|
2023-10-13 08:34:21 +00:00
|
|
|
return new ActivityExecutionRecord
|
|
|
|
|
{
|
|
|
|
|
Id = source.Id,
|
|
|
|
|
ActivityId = source.Activity.Id,
|
2023-10-25 20:46:06 +00:00
|
|
|
ActivityNodeId = source.NodeId,
|
2023-10-13 08:34:21 +00:00
|
|
|
WorkflowInstanceId = source.WorkflowExecutionContext.Id,
|
|
|
|
|
ActivityType = source.Activity.Type,
|
|
|
|
|
ActivityName = source.Activity.Name,
|
2024-03-30 20:22:35 +00:00
|
|
|
ActivityState = activityState,
|
2023-10-13 08:34:21 +00:00
|
|
|
Outputs = outputs,
|
2024-03-08 07:54:08 +00:00
|
|
|
Properties = source.Properties,
|
2023-10-13 08:34:21 +00:00
|
|
|
Payload = payload,
|
|
|
|
|
Exception = ExceptionState.FromException(source.Exception),
|
|
|
|
|
ActivityTypeVersion = source.Activity.Version,
|
|
|
|
|
StartedAt = source.StartedAt,
|
|
|
|
|
HasBookmarks = source.Bookmarks.Any(),
|
|
|
|
|
Status = GetAggregateStatus(source),
|
|
|
|
|
CompletedAt = source.CompletedAt
|
|
|
|
|
};
|
2024-04-12 13:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static LogPersistenceMode GetDefaultPersistenceMode(IDictionary<string, object> customProperties, Func<LogPersistenceMode> defaultFactory)
|
|
|
|
|
{
|
|
|
|
|
var properties = customProperties.GetValueOrDefault<IDictionary<string, object?>>(LogPersistenceModeKey, () => new Dictionary<string, object?>());
|
|
|
|
|
var persistencePropertyDefault = properties!.GetValueOrDefault("default", defaultFactory);
|
|
|
|
|
|
|
|
|
|
if (persistencePropertyDefault == LogPersistenceMode.Default)
|
|
|
|
|
return defaultFactory();
|
|
|
|
|
return persistencePropertyDefault;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static Dictionary<string, object?> StorePropertyUsingPersistenceMode(IDictionary<string, object?> inputs,
|
|
|
|
|
IDictionary<string, object> persistenceModeConfiguration,
|
|
|
|
|
LogPersistenceMode defaultLogPersistenceMode)
|
|
|
|
|
{
|
|
|
|
|
var result = new Dictionary<string, object?>();
|
|
|
|
|
|
|
|
|
|
foreach (var input in inputs)
|
|
|
|
|
{
|
|
|
|
|
var persistence = persistenceModeConfiguration.GetValueOrDefault(input.Key.Camelize(), () => defaultLogPersistenceMode);
|
|
|
|
|
if (persistence.Equals(LogPersistenceMode.Include)
|
|
|
|
|
|| (persistence.Equals(LogPersistenceMode.Default) && defaultLogPersistenceMode is LogPersistenceMode.Include or LogPersistenceMode.Default))
|
|
|
|
|
result.Add(input.Key, input.Value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-10 10:34:32 +00:00
|
|
|
private ActivityStatus GetAggregateStatus(ActivityExecutionContext context)
|
|
|
|
|
{
|
|
|
|
|
// If any child activity is faulted, the aggregate status is faulted.
|
|
|
|
|
var descendantContexts = context.GetDescendants().ToList();
|
2023-10-13 08:34:21 +00:00
|
|
|
|
2023-10-10 10:34:32 +00:00
|
|
|
if (descendantContexts.Any(x => x.Status == ActivityStatus.Faulted))
|
|
|
|
|
return ActivityStatus.Faulted;
|
|
|
|
|
|
|
|
|
|
return context.Status;
|
|
|
|
|
}
|
|
|
|
|
}
|