diff --git a/src/activities/Elsa.Activities.Entity/Bookmarks/EntityChangedBookmark.cs b/src/activities/Elsa.Activities.Entity/Bookmarks/EntityChangedBookmark.cs index 2bb953592..f3c42f740 100644 --- a/src/activities/Elsa.Activities.Entity/Bookmarks/EntityChangedBookmark.cs +++ b/src/activities/Elsa.Activities.Entity/Bookmarks/EntityChangedBookmark.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; +using Elsa.Attributes; using Elsa.Services; namespace Elsa.Activities.Entity.Bookmarks @@ -13,8 +14,16 @@ namespace Elsa.Activities.Entity.Bookmarks Action = action; } + [ExcludeFromHash] public string? EntityName { get; } public EntityChangedAction? Action { get; } + + public bool? Compare(IBookmark bookmark) + { + return bookmark is EntityChangedBookmark other + && string.Equals(EntityName, other.EntityName, System.StringComparison.OrdinalIgnoreCase) + && Action == other.Action; + } } public class EntityChangedWorkflowTriggerProvider : BookmarkProvider diff --git a/src/activities/Elsa.Activities.File/Bookmarks/FileSystemEventBookmark.cs b/src/activities/Elsa.Activities.File/Bookmarks/FileSystemEventBookmark.cs index 3f716e483..7ade3ed0f 100644 --- a/src/activities/Elsa.Activities.File/Bookmarks/FileSystemEventBookmark.cs +++ b/src/activities/Elsa.Activities.File/Bookmarks/FileSystemEventBookmark.cs @@ -1,4 +1,7 @@ +using Elsa.Attributes; using Elsa.Services; + +using System; using System.Collections.Generic; using System.IO; using System.Threading; @@ -19,13 +22,33 @@ namespace Elsa.Activities.File.Bookmarks Pattern = pattern; } + [ExcludeFromHash] public WatcherChangeTypes ChangeTypes { get; set; } + [ExcludeFromHash] public NotifyFilters NotifyFilters { get; set; } + [ExcludeFromHash] public string? Path { get; set; } public string? Pattern { get; set; } + + public bool? Compare(IBookmark bookmark) + { + return bookmark is FileSystemEventBookmark other + && ComparePaths(Path, other.Path) + && ComparePaths(Pattern, other.Pattern) + && ((NotifyFilters & other.NotifyFilters) > 0) + && ((ChangeTypes & other.ChangeTypes) > 0); + } + + private bool ComparePaths(string? left, string? right) + { + if (Environment.OSVersion.Platform == PlatformID.Unix) + return string.Equals(left, right); + else + return string.Equals(left, right, System.StringComparison.OrdinalIgnoreCase); + } } public class FileCreatedBookmarkProvider : BookmarkProvider diff --git a/src/core/Elsa.Abstractions/Services/Bookmarks/IBookmark.cs b/src/core/Elsa.Abstractions/Services/Bookmarks/IBookmark.cs index e3ca8dd59..a6882059b 100644 --- a/src/core/Elsa.Abstractions/Services/Bookmarks/IBookmark.cs +++ b/src/core/Elsa.Abstractions/Services/Bookmarks/IBookmark.cs @@ -1,6 +1,12 @@ -namespace Elsa.Services +namespace Elsa.Services { public interface IBookmark { + /// + /// Compares this bookmark instance with another to check, if the values are equal for the function of the bookmark. + /// + /// + /// if default and no specific compare is done, false if not equal and true otherwise + bool? Compare(IBookmark bookmark) { return null; } } } \ No newline at end of file diff --git a/src/core/Elsa.Core/Services/Triggers/TriggerFinder.cs b/src/core/Elsa.Core/Services/Triggers/TriggerFinder.cs index c36946cde..84f67e7e1 100644 --- a/src/core/Elsa.Core/Services/Triggers/TriggerFinder.cs +++ b/src/core/Elsa.Core/Services/Triggers/TriggerFinder.cs @@ -28,9 +28,20 @@ namespace Elsa.Services.Triggers return scopedTriggers.Select(x => new TriggerFinderResult(x.WorkflowBlueprint, x.ActivityId, x.ActivityType, x.Bookmark)).ToList(); } - var hashes = filterList.Select(x => _bookmarkHasher.Hash(x)).ToList(); - var matchingTriggers = scopedTriggers.Where(x => hashes.Contains(x.BookmarkHash)); - return matchingTriggers.Select(x => new TriggerFinderResult(x.WorkflowBlueprint, x.ActivityId, x.ActivityType, x.Bookmark)).ToList(); + var hashes = filterList.ToDictionary(x => _bookmarkHasher.Hash(x), x => x); + List matches = new(); + + foreach (var scoped in scopedTriggers) + { + if (!hashes.TryGetValue(scoped.BookmarkHash, out var bookmark)) + continue; + + var result = scoped.Bookmark.Compare(bookmark); + if (result == null || result.Value) + matches.Add(scoped); + } + + return matches.Select(x => new TriggerFinderResult(x.WorkflowBlueprint, x.ActivityId, x.ActivityType, x.Bookmark)).ToList(); } } } \ No newline at end of file