< Summary

Information
Class: Elsa.Workflows.Runtime.DefaultActivityExecutionMapper
Assembly: Elsa.Workflows.Runtime
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Services/DefaultActivityExecutionMapper.cs
Line coverage
100%
Covered lines: 72
Uncovered lines: 0
Coverable lines: 72
Total lines: 103
Line coverage: 100%
Branch coverage
86%
Covered branches: 26
Total branches: 30
Branch coverage: 86.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
MapAsync()81.81%2222100%
GetPersistableInputOutput(...)100%66100%
GetPersistableDictionary(...)100%22100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Services/DefaultActivityExecutionMapper.cs

#LineLine coverage
 1using Elsa.Common;
 2using Elsa.Common.Codecs;
 3using Elsa.Workflows.LogPersistence;
 4using Elsa.Workflows.Management.Options;
 5using Elsa.Workflows.Runtime.Entities;
 6using Elsa.Workflows.Runtime.Extensions;
 7using Elsa.Workflows.State;
 8using Microsoft.Extensions.Options;
 9
 10namespace Elsa.Workflows.Runtime;
 11
 12/// <inheritdoc />
 42713public class DefaultActivityExecutionMapper(
 42714    ISafeSerializer safeSerializer,
 42715    IPayloadSerializer payloadSerializer,
 42716    ICompressionCodecResolver compressionCodecResolver,
 42717    IOptions<ManagementOptions> options) : IActivityExecutionMapper
 18{
 19    /// <inheritdoc />
 20    public async Task<ActivityExecutionRecord> MapAsync(ActivityExecutionContext source)
 21    {
 383222        var outputs = source.GetOutputs();
 383223        var inputs = source.GetInputs();
 383224        var persistenceMap = source.GetLogPersistenceModeMap();
 383225        var persistableInputs = GetPersistableInputOutput(inputs, persistenceMap.Inputs);
 383226        var persistableOutputs = GetPersistableInputOutput(outputs, persistenceMap.Outputs);
 383227        var persistableProperties = GetPersistableDictionary(source.Properties!, persistenceMap.InternalState);
 383228        var persistableJournalData = GetPersistableDictionary(source.JournalData!, persistenceMap.InternalState);
 383229        var cancellationToken = source.CancellationToken;
 30
 383231        var record = new ActivityExecutionRecord
 383232        {
 383233            Id = source.Id,
 383234            ActivityId = source.Activity.Id,
 383235            ActivityNodeId = source.NodeId,
 383236            WorkflowInstanceId = source.WorkflowExecutionContext.Id,
 383237            ActivityType = source.Activity.Type,
 383238            ActivityName = source.Activity.Name,
 383239            ActivityState = persistableInputs,
 383240            Outputs = persistableOutputs,
 383241            Properties = persistableProperties!,
 383242            Metadata = new Dictionary<string, object>(source.Metadata),
 383243            Payload = persistableJournalData!,
 383244            Exception = ExceptionState.FromException(source.Exception),
 383245            ActivityTypeVersion = source.Activity.Version,
 383246            StartedAt = source.StartedAt,
 383247            HasBookmarks = source.Bookmarks.Any(),
 383248            Status = source.Status,
 383249            AggregateFaultCount = source.AggregateFaultCount,
 383250            CompletedAt = source.CompletedAt
 383251        };
 52
 383253        record = record.SanitizeLogMessage();
 383254        var compressionAlgorithm = options.Value.CompressionAlgorithm ?? nameof(None);
 383255        var serializedActivityState = record.ActivityState?.Count > 0 ? safeSerializer.Serialize(record.ActivityState) :
 383256        var compressedSerializedActivityState = serializedActivityState != null ? await compressionCodecResolver.Resolve
 383257        var serializedProperties = record.Properties != null ? payloadSerializer.Serialize(record.Properties) : null;
 383258        var serializedMetadata = record.Metadata != null ? payloadSerializer.Serialize(record.Metadata) : null;
 383259        record.SerializedSnapshot = new()
 383260        {
 383261            Id = record.Id,
 383262            TenantId = record.TenantId,
 383263            WorkflowInstanceId = record.WorkflowInstanceId,
 383264            ActivityId = record.ActivityId,
 383265            ActivityNodeId = record.ActivityNodeId,
 383266            ActivityType = record.ActivityType,
 383267            ActivityTypeVersion = record.ActivityTypeVersion,
 383268            ActivityName = record.ActivityName,
 383269            StartedAt = record.StartedAt,
 383270            HasBookmarks = record.HasBookmarks,
 383271            Status = record.Status,
 383272            AggregateFaultCount = record.AggregateFaultCount,
 383273            CompletedAt = record.CompletedAt,
 383274            SerializedActivityState = compressedSerializedActivityState,
 383275            SerializedActivityStateCompressionAlgorithm = compressionAlgorithm,
 383276            SerializedOutputs = record.Outputs?.Any() == true ? safeSerializer.Serialize(record.Outputs) : null,
 383277            SerializedProperties = serializedProperties,
 383278            SerializedMetadata = serializedMetadata,
 383279            SerializedException = record.Exception != null ? payloadSerializer.Serialize(record.Exception) : null,
 383280            SerializedPayload = record.Payload?.Any() == true ? payloadSerializer.Serialize(record.Payload) : null
 383281        };
 82
 383283        return record;
 383284    }
 85
 86    private IDictionary<string, object?> GetPersistableInputOutput(IDictionary<string, object> state, IDictionary<string
 87    {
 766488        var result = new Dictionary<string, object?>();
 3013689        foreach (var stateEntry in state)
 90        {
 740491            var mode = map.TryGetValue(stateEntry.Key, out var value) ? value : LogPersistenceMode.Include;
 740492            if (mode == LogPersistenceMode.Include)
 739693                result.Add(stateEntry.Key, stateEntry.Value);
 94        }
 95
 766496        return result;
 97    }
 98
 99    private IDictionary<string, object?>? GetPersistableDictionary(IDictionary<string, object?> dictionary, LogPersisten
 100    {
 7664101        return mode == LogPersistenceMode.Include ? new Dictionary<string, object?>(dictionary) : null;
 102    }
 103}