Formatting
This commit is contained in:
parent
510153de3a
commit
e7d1ceb992
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<FileSystemEventBookmark, WatchDirectory>
|
||||
{
|
||||
public override async ValueTask<IEnumerable<BookmarkResult>> GetBookmarksAsync(BookmarkProviderContext<WatchDirectory> 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 };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,7 @@ namespace Elsa.Services
|
|||
/// <summary>
|
||||
/// Compares this bookmark instance with another to check, if the values are equal for the function of the bookmark.
|
||||
/// </summary>
|
||||
/// <param name="bookmark"></param>
|
||||
/// <returns><see langword="null"/> if default and no specific compare is done, false if not equal and true otherwise</returns>
|
||||
bool? Compare(IBookmark bookmark) { return null; }
|
||||
/// <returns><see langword="null"/> if default and no specific compare is done, false if not equal and true otherwise.</returns>
|
||||
bool? Compare(IBookmark bookmark) => null;
|
||||
}
|
||||
}
|
||||
|
|
@ -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<IBookmark> ?? 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<WorkflowTrigger> matches = new();
|
||||
var matches = new List<WorkflowTrigger>();
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue