< Summary

Information
Class: Elsa.Workflows.Runtime.BookmarkResumer
Assembly: Elsa.Workflows.Runtime
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Services/BookmarkResumer.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 60
Coverable lines: 60
Total lines: 108
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 6
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
ResumeAsync(...)100%210%
ResumeAsync()100%210%
ResumeAsync()100%210%
ResumeAsync()100%210%
ResumeAsync()100%210%
ResumeAsync()0%4260%

File(s)

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

#LineLine coverage
 1using Elsa.Workflows.Helpers;
 2using Elsa.Workflows.Runtime.Exceptions;
 3using Elsa.Workflows.Runtime.Filters;
 4using Elsa.Workflows.Runtime.Messages;
 5using Elsa.Workflows.Runtime.Options;
 6using Microsoft.Extensions.Logging;
 7
 8namespace Elsa.Workflows.Runtime;
 9
 10/// <inheritdoc />
 11[Obsolete("Use WorkflowResumer instead.")]
 012public class BookmarkResumer(IWorkflowRuntime workflowRuntime, IBookmarkStore bookmarkStore, IStimulusHasher stimulusHas
 13{
 14    /// <inheritdoc />
 15    public Task<ResumeBookmarkResult> ResumeAsync<TActivity>(object stimulus, ResumeBookmarkOptions? options = null, Can
 16    {
 017        return ResumeAsync<TActivity>(stimulus, null, options, cancellationToken);
 18    }
 19
 20    /// <inheritdoc />
 21    public async Task<ResumeBookmarkResult> ResumeAsync<TActivity>(object stimulus, string? workflowInstanceId = null, R
 22    {
 023        var activityTypeName = ActivityTypeNameHelper.GenerateTypeName<TActivity>();
 024        var stimulusHash = stimulusHasher.Hash(activityTypeName, stimulus);
 025        var bookmarkFilter = new BookmarkFilter
 026        {
 027            Name = activityTypeName,
 028            WorkflowInstanceId = workflowInstanceId,
 029            Hash = stimulusHash,
 030        };
 031        return await ResumeAsync(bookmarkFilter, options, cancellationToken);
 032    }
 33
 34    /// <inheritdoc />
 35    public async Task<ResumeBookmarkResult> ResumeAsync(string bookmarkId, IDictionary<string, object> input, Cancellati
 36    {
 037        var bookmarkFilter = new BookmarkFilter
 038        {
 039            BookmarkId = bookmarkId
 040        };
 041        var options = new ResumeBookmarkOptions
 042        {
 043            Input = input
 044        };
 045        return await ResumeAsync(bookmarkFilter, options, cancellationToken);
 046    }
 47
 48    /// <inheritdoc />
 49    public async Task<ResumeBookmarkResult> ResumeAsync<TActivity>(string bookmarkId, ResumeBookmarkOptions? options = n
 50    {
 051        var activityTypeName = ActivityTypeNameHelper.GenerateTypeName<TActivity>();
 052        var bookmarkFilter = new BookmarkFilter
 053        {
 054            Name = activityTypeName,
 055            BookmarkId = bookmarkId
 056        };
 057        return await ResumeAsync(bookmarkFilter, options, cancellationToken);
 058    }
 59
 60    public async Task<ResumeBookmarkResult> ResumeAsync(ResumeBookmarkRequest request, CancellationToken cancellationTok
 61    {
 062        var runRequest = new RunWorkflowInstanceRequest
 063        {
 064            Input = request.Input,
 065            Properties = request.Properties,
 066            ActivityHandle = request.ActivityHandle,
 067            BookmarkId = request.BookmarkId
 068        };
 69
 070        var workflowInstanceId = request.WorkflowInstanceId;
 071        var workflowClient = await workflowRuntime.CreateClientAsync(workflowInstanceId, cancellationToken);
 072        var response = await workflowClient.RunInstanceAsync(runRequest, cancellationToken);
 073        return ResumeBookmarkResult.Found(response);
 074    }
 75
 76    /// <inheritdoc />
 77    public async Task<ResumeBookmarkResult> ResumeAsync(BookmarkFilter filter, ResumeBookmarkOptions? options = null, Ca
 78    {
 079        var bookmark = await bookmarkStore.FindAsync(filter, cancellationToken);
 80
 081        if (bookmark == null)
 82        {
 083            logger.LogDebug("Bookmark not found in store for filter {@Filter}", filter);
 084            return ResumeBookmarkResult.NotFound();
 85        }
 86
 087        var workflowClient = await workflowRuntime.CreateClientAsync(bookmark.WorkflowInstanceId, cancellationToken);
 088        var runRequest = new RunWorkflowInstanceRequest
 089        {
 090            Input = options?.Input,
 091            Properties = options?.Properties,
 092            BookmarkId = bookmark.Id
 093        };
 94
 95        try
 96        {
 097            var response = await workflowClient.RunInstanceAsync(runRequest, cancellationToken);
 098            logger.LogDebug("Resumed workflow instance {WorkflowInstanceId} with bookmark {BookmarkId}", bookmark.Workfl
 099            return ResumeBookmarkResult.Found(response);
 100        }
 0101        catch (WorkflowInstanceNotFoundException)
 102        {
 103            // The workflow instance does not (yet) exist in the DB.
 0104            logger.LogDebug("No workflow instance with ID {WorkflowInstanceId} found for bookmark {BookmarkId} at this t
 0105            return ResumeBookmarkResult.NotFound();
 106        }
 0107    }
 108}