< Summary

Information
Class: Elsa.Workflows.Middleware.Activities.ExecutionLogMiddlewareExtensions
Assembly: Elsa.Workflows.Core
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Middleware/Activities/ExecutionLogMiddleware.cs
Line coverage
100%
Covered lines: 1
Uncovered lines: 0
Coverable lines: 1
Total lines: 61
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
UseExecutionLogging(...)100%11100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Middleware/Activities/ExecutionLogMiddleware.cs

#LineLine coverage
 1using Elsa.Workflows.Models;
 2using Elsa.Workflows.Pipelines.ActivityExecution;
 3using JetBrains.Annotations;
 4
 5namespace Elsa.Workflows.Middleware.Activities;
 6
 7/// <summary>
 8/// Adds extension methods to <see cref="ExecutionLogMiddleware"/>.
 9/// </summary>
 10public static class ExecutionLogMiddlewareExtensions
 11{
 12    /// <summary>
 13    /// Installs the <see cref="ExecutionLogMiddleware"/> component in the activity execution pipeline.
 14    /// </summary>
 42115    public static IActivityExecutionPipelineBuilder UseExecutionLogging(this IActivityExecutionPipelineBuilder pipelineB
 16}
 17
 18/// <summary>
 19/// An activity execution middleware component that extracts execution details as <see cref="WorkflowExecutionLogEntry"/
 20/// </summary>
 21[UsedImplicitly]
 22public class ExecutionLogMiddleware(ActivityMiddlewareDelegate next) : IActivityExecutionMiddleware
 23{
 24    /// <inheritdoc />
 25    public async ValueTask InvokeAsync(ActivityExecutionContext context)
 26    {
 27        context.AddExecutionLogEntry(IsActivityBookmarked(context) ? "Resumed" : "Started");
 28
 29        try
 30        {
 31            await next(context);
 32
 33            if (context.Status == ActivityStatus.Running)
 34            {
 35                if (IsActivityBookmarked(context))
 36                    context.AddExecutionLogEntry("Suspended");
 37            }
 38        }
 39        catch (Exception exception)
 40        {
 41            context.AddExecutionLogEntry("Faulted",
 42                message: exception.Message,
 43                payload: new
 44                {
 45                    Exception = exception.GetType().FullName,
 46                    exception.Message,
 47                    exception.Source,
 48                    exception.Data,
 49                    exception.StackTrace,
 50                    InnerException = exception.InnerException?.GetType().FullName,
 51                });
 52
 53            throw;
 54        }
 55    }
 56
 57    private static bool IsActivityBookmarked(ActivityExecutionContext context)
 58    {
 59        return context.WorkflowExecutionContext.Bookmarks.Any(b => b.ActivityNodeId.Equals(context.ActivityNode.NodeId))
 60    }
 61}