From e7d1ceb992e0dfdc708b23ca840ad9cb7554d16b Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Mon, 25 Oct 2021 13:55:44 +0200 Subject: [PATCH] Formatting --- .../Bookmarks/EntityChangedBookmark.cs | 9 ++-- .../Bookmarks/FileSystemEventBookmark.cs | 48 ++++++++----------- .../Services/Bookmarks/IBookmark.cs | 5 +- .../Services/Triggers/TriggerFinder.cs | 6 +-- 4 files changed, 27 insertions(+), 41 deletions(-) diff --git a/src/activities/Elsa.Activities.Entity/Bookmarks/EntityChangedBookmark.cs b/src/activities/Elsa.Activities.Entity/Bookmarks/EntityChangedBookmark.cs index f3c42f740..aa3c9014c 100644 --- a/src/activities/Elsa.Activities.Entity/Bookmarks/EntityChangedBookmark.cs +++ b/src/activities/Elsa.Activities.Entity/Bookmarks/EntityChangedBookmark.cs @@ -14,15 +14,14 @@ namespace Elsa.Activities.Entity.Bookmarks Action = action; } - [ExcludeFromHash] - public string? EntityName { get; } + [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; + return bookmark is EntityChangedBookmark other + && string.Equals(EntityName, other.EntityName, System.StringComparison.OrdinalIgnoreCase) + && Action == other.Action; } } diff --git a/src/activities/Elsa.Activities.File/Bookmarks/FileSystemEventBookmark.cs b/src/activities/Elsa.Activities.File/Bookmarks/FileSystemEventBookmark.cs index 7ade3ed0f..5074d620e 100644 --- a/src/activities/Elsa.Activities.File/Bookmarks/FileSystemEventBookmark.cs +++ b/src/activities/Elsa.Activities.File/Bookmarks/FileSystemEventBookmark.cs @@ -1,6 +1,5 @@ using Elsa.Attributes; using Elsa.Services; - using System; using System.Collections.Generic; using System.IO; @@ -12,7 +11,8 @@ namespace Elsa.Activities.File.Bookmarks public class FileSystemEventBookmark : IBookmark { public FileSystemEventBookmark() - { } + { + } public FileSystemEventBookmark(string? path, string? pattern, WatcherChangeTypes changeTypes, NotifyFilters notifyFilters) { @@ -22,43 +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; } + [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); - } + public bool? Compare(IBookmark bookmark) => + 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); - } + private bool ComparePaths(string? left, string? right) => + Environment.OSVersion.Platform == PlatformID.Unix + ? string.Equals(left, right) + : string.Equals(left, right, StringComparison.OrdinalIgnoreCase); } public class FileCreatedBookmarkProvider : BookmarkProvider { public override async ValueTask> GetBookmarksAsync(BookmarkProviderContext context, CancellationToken cancellationToken) { - var changeTypes = await context.ReadActivityPropertyAsync(a => a.ChangeTypes); - var notifyFilters = await context.ReadActivityPropertyAsync(a => a.NotifyFilters); - var path = await context.ReadActivityPropertyAsync(a => a.Path); - var pattern = await context.ReadActivityPropertyAsync(a => a.Pattern); + var changeTypes = await context.ReadActivityPropertyAsync(a => a.ChangeTypes, cancellationToken); + var notifyFilters = await context.ReadActivityPropertyAsync(a => a.NotifyFilters, cancellationToken); + var path = await context.ReadActivityPropertyAsync(a => a.Path, cancellationToken); + var pattern = await context.ReadActivityPropertyAsync(a => a.Pattern, cancellationToken); var result = Result(new FileSystemEventBookmark(path, pattern, changeTypes, notifyFilters)); return new[] { result }; } diff --git a/src/core/Elsa.Abstractions/Services/Bookmarks/IBookmark.cs b/src/core/Elsa.Abstractions/Services/Bookmarks/IBookmark.cs index a6882059b..f1ff0825d 100644 --- a/src/core/Elsa.Abstractions/Services/Bookmarks/IBookmark.cs +++ b/src/core/Elsa.Abstractions/Services/Bookmarks/IBookmark.cs @@ -5,8 +5,7 @@ namespace Elsa.Services /// /// 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; } + /// if default and no specific compare is done, false if not equal and true otherwise. + bool? Compare(IBookmark bookmark) => 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 84f67e7e1..b5ea75559 100644 --- a/src/core/Elsa.Core/Services/Triggers/TriggerFinder.cs +++ b/src/core/Elsa.Core/Services/Triggers/TriggerFinder.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; -using Elsa.Services.Bookmarks; namespace Elsa.Services.Triggers { @@ -24,12 +23,10 @@ namespace Elsa.Services.Triggers var filterList = filters as ICollection ?? filters.ToList(); if (!filterList.Any()) - { return scopedTriggers.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(); + var matches = new List(); foreach (var scoped in scopedTriggers) { @@ -37,6 +34,7 @@ namespace Elsa.Services.Triggers continue; var result = scoped.Bookmark.Compare(bookmark); + if (result == null || result.Value) matches.Add(scoped); }