public async Task Handle(NewDocumentReceived notification, CancellationToken cancellationToken)
        {
            // var document = notification.Document;
            var tagName = _configuration["Elsa:DocumentManager:TagName"];

            _logger.LogInformation($"Start workflow ({tagName}) for document: {notification.Document.Id} and File: {notification.File.FileName}");

            // Get all workflow blueprints tagged with the received tag name.
            var workflowBlueprint = await _workflowRegistry.FindManyAsync(x => x.IsPublished && x.Tag == tagName, cancellationToken);

            // Dispatch each workflow. Each workflow will be correlated by Document ID.
            foreach (var workflow in workflowBlueprint)
            {
                var request = new ExecuteWorkflowDefinitionRequest(
                    workflow.Id,
                    Input: notification
                    // CorrelationId: document.Id
                    );
                await _workflowDispatcher.DispatchAsync(request, cancellationToken);
            }
        }
Пример #2
0
        public async Task <ActionResult <PagedList <WorkflowBlueprintSummaryModel> > > Handle(int?page = default, int?pageSize = default, VersionOptions?version = default, CancellationToken cancellationToken = default)
        {
            version ??= VersionOptions.LatestOrPublished;
            var workflowBlueprints = await _workflowRegistry.FindManyAsync(x => x.WithVersion(version.Value), cancellationToken).ToList();

            var totalCount = workflowBlueprints.Count;
            var skip       = page * pageSize;
            var items      = workflowBlueprints.AsEnumerable();

            if (skip != null)
            {
                items = items.Skip(skip.Value);
            }

            if (pageSize != null)
            {
                items = items.Take(pageSize.Value);
            }

            using var scope = _serviceProvider.CreateScope();
            var mappedItems = _mapper.Map <IEnumerable <WorkflowBlueprintSummaryModel> >(items).ToList();

            return(new PagedList <WorkflowBlueprintSummaryModel>(mappedItems, page, pageSize, totalCount));
        }