Пример #1
0
        public async Task <IEnumerable <TriggerFinderResult> > FindTriggersAsync(string activityType, IEnumerable <IBookmark> filters, string?tenantId, int skip = 0, int take = int.MaxValue, CancellationToken cancellationToken = default)
        {
            var filterList    = filters as ICollection <IBookmark> ?? filters.ToList();
            var hashes        = filterList.Select(x => _bookmarkHasher.Hash(x)).ToList();
            var specification = new TriggerSpecification(activityType, hashes, tenantId);
            var paging        = Paging.Create(skip, take);
            var orderBy       = new OrderBy <Trigger>(x => x.Id, SortDirection.Ascending);
            var records       = await _triggerStore.FindManyAsync(specification, orderBy, paging, cancellationToken);

            var triggerResults = SelectResults(records);

            if (!filterList.Any())
            {
                return(triggerResults);
            }

            var query =
                from triggerFinderResult in triggerResults
                from filter in filterList
                let result = triggerFinderResult.Bookmark.Compare(filter)
                             where result == null || result.Value
                             select triggerFinderResult;

            return(query);
        }
Пример #2
0
        public async Task <IEnumerable <TriggerFinderResult> > FindTriggersAsync(string activityType, IEnumerable <IBookmark> filters, string?tenantId, CancellationToken cancellationToken = default)
        {
            var allTriggers    = (await _triggerStore.GetAsync(cancellationToken)).ToList();
            var scopedTriggers = allTriggers.Where(x => x.ActivityType == activityType && x.WorkflowBlueprint.TenantId == tenantId);
            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);
            var matches = new List <WorkflowTrigger>();

            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());
        }
Пример #3
0
        private ISpecification <Bookmark> BuildSpecification(string activityType, IEnumerable <IBookmark> bookmarks, string?correlationId, string?tenantId)
        {
            var specification = bookmarks
                                .Select(bookmark => _hasher.Hash(bookmark))
                                .Aggregate(Specification <Bookmark> .None, (current, hash) => current.Or(new BookmarkHashSpecification(hash, activityType, tenantId)));

            if (correlationId != null)
            {
                specification = specification.And(new CorrelationIdSpecification(correlationId));
            }

            return(specification);
        }
Пример #4
0
        public async Task <IEnumerable <TriggerFinderResult> > FindTriggersAsync(string activityType, IEnumerable <IBookmark> filters, string?tenantId, CancellationToken cancellationToken = default)
        {
            var allTriggers    = (await _triggerStore.GetAsync(cancellationToken)).ToList();
            var scopedTriggers = allTriggers.Where(x => x.ActivityType == activityType && x.WorkflowBlueprint.TenantId == tenantId);
            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.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());
        }
Пример #5
0
        private async Task <IList <WorkflowTrigger> > GetTriggersForBookmarkProvider(
            IBookmarkProvider provider,
            BookmarkProviderContext context,
            IActivityBlueprint activityBlueprint,
            IWorkflowBlueprint workflowBlueprint,
            CancellationToken cancellationToken = default)
        {
            var bookmarkResults = (await provider.GetBookmarksAsync(context, cancellationToken)).ToList();

            return(bookmarkResults
                   .Select(x => new WorkflowTrigger(
                               workflowBlueprint.Id,
                               activityBlueprint.Id,
                               x.ActivityTypeName ?? activityBlueprint.Type,
                               _bookmarkHasher.Hash(x.Bookmark),
                               x.Bookmark,
                               workflowBlueprint.TenantId))
                   .ToList());
        }
Пример #6
0
 private ISpecification <Bookmark> BuildSpecification(string activityType, IEnumerable <IBookmark> bookmarks, string?tenantId) =>
 bookmarks
 .Select(trigger => _hasher.Hash(trigger))
 .Aggregate(Specification <Bookmark> .None, (current, hash) => current.Or(new BookmarkHashSpecification(hash, activityType, tenantId)));
Пример #7
0
        async Task <IList <WorkflowTrigger> > GetTriggersForBookmarkProvider(
            IBookmarkProvider provider,
            BookmarkProviderContext context,
            IActivityBlueprint activityBlueprint,
            IWorkflowBlueprint workflowBlueprint,
            CancellationToken cancellationToken = default)
        {
            var bookmarks = (await provider.GetBookmarksAsync(context, cancellationToken)).ToList();

            return(bookmarks
                   .Select(x => new WorkflowTrigger(workflowBlueprint, activityBlueprint.Id, activityBlueprint.Type, bookmarkHasher.Hash(x), x))
                   .ToList());
        }