| | | 1 | | using Elsa.Workflows.Models; |
| | | 2 | | using Elsa.Workflows.Runtime.Filters; |
| | | 3 | | using Elsa.Workflows.Runtime.Requests; |
| | | 4 | | |
| | | 5 | | namespace Elsa.Workflows.Runtime; |
| | | 6 | | |
| | | 7 | | /// <inheritdoc /> |
| | 437 | 8 | | public class BookmarkUpdater(IBookmarkManager bookmarkManager, IBookmarkStore bookmarkStore) : IBookmarkUpdater |
| | | 9 | | { |
| | | 10 | | /// <inheritdoc /> |
| | | 11 | | public async Task UpdateBookmarksAsync(UpdateBookmarksRequest request, CancellationToken cancellationToken = default |
| | | 12 | | { |
| | 466 | 13 | | var instanceId = request.WorkflowExecutionContext.Id; |
| | 466 | 14 | | await RemoveBookmarksAsync(instanceId, request.Diff.Removed.ToList(), cancellationToken); |
| | 466 | 15 | | await StoreBookmarksAsync(request.WorkflowExecutionContext, request.Diff.Added.ToList(), cancellationToken); |
| | 466 | 16 | | } |
| | | 17 | | |
| | | 18 | | private async Task RemoveBookmarksAsync(string workflowInstanceId, ICollection<Bookmark> bookmarks, CancellationToke |
| | | 19 | | { |
| | 466 | 20 | | if (bookmarks.Count == 0) |
| | 424 | 21 | | return; |
| | | 22 | | |
| | 88 | 23 | | var matchingIds = bookmarks.Select(x => x.Id).ToList(); |
| | 42 | 24 | | var filter = new BookmarkFilter |
| | 42 | 25 | | { |
| | 42 | 26 | | BookmarkIds = matchingIds, |
| | 42 | 27 | | WorkflowInstanceId = workflowInstanceId |
| | 42 | 28 | | }; |
| | 42 | 29 | | await bookmarkManager.DeleteManyAsync(filter, cancellationToken); |
| | 466 | 30 | | } |
| | | 31 | | |
| | | 32 | | private async Task StoreBookmarksAsync(WorkflowExecutionContext context, ICollection<Bookmark> bookmarks, Cancellati |
| | | 33 | | { |
| | 466 | 34 | | if (bookmarks.Count == 0) |
| | 416 | 35 | | return; |
| | | 36 | | |
| | 214 | 37 | | foreach (var bookmark in bookmarks) |
| | | 38 | | { |
| | 57 | 39 | | var storedBookmark = context.MapBookmark(bookmark); |
| | 57 | 40 | | await bookmarkStore.SaveAsync(storedBookmark, cancellationToken); |
| | | 41 | | } |
| | 466 | 42 | | } |
| | | 43 | | } |