Last active
August 3, 2021 08:43
-
-
Save sfmskywalker/ab8abe1021e6632b5bcff99116ad6e23 to your computer and use it in GitHub Desktop.
Revisions
-
sfmskywalker revised this gist
Aug 3, 2021 . 1 changed file with 38 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ using System.Threading; using System.Threading.Tasks; using DocumentManagement.Core.Events; using Elsa.Models; using Elsa.Services; using MediatR; using Open.Linq.AsyncExtensions; namespace DocumentManagement.Workflows.Handlers { /// <summary> /// Handles the <see cref="NewDocumentReceived"/> event by starting new workflows associated with the document type. /// </summary> public class StartDocumentWorkflows : INotificationHandler<NewDocumentReceived> { private readonly IWorkflowRegistry _workflowRegistry; private readonly IWorkflowDefinitionDispatcher _workflowDispatcher; public StartDocumentWorkflows(IWorkflowRegistry workflowRegistry, IWorkflowDefinitionDispatcher workflowDispatcher) { _workflowRegistry = workflowRegistry; _workflowDispatcher = workflowDispatcher; } public async Task Handle(NewDocumentReceived notification, CancellationToken cancellationToken) { var document = notification.Document; var documentTypeId = document.DocumentTypeId; // Get all workflow blueprints tagged with the received document type ID. var workflowBlueprints = await _workflowRegistry.FindManyAsync(x => x.IsPublished && x.Tag == documentTypeId, cancellationToken).ToList(); // Dispatch each workflow. Each workflow will be correlated by Document ID. foreach (var workflowBlueprint in workflowBlueprints) await _workflowDispatcher.DispatchAsync(new ExecuteWorkflowDefinitionRequest(workflowBlueprint.Id, CorrelationId: document.Id, Input: new WorkflowInput(document.Id)), cancellationToken); } } } -
sfmskywalker revised this gist
Aug 3, 2021 . 1 changed file with 2 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -20,14 +20,13 @@ public StartHelloFileWorkflow(IWorkflowRegistry workflowRegistry, IWorkflowDefin _workflowRegistry = workflowRegistry; _workflowDispatcher = workflowDispatcher; } public async Task Handle(NewDocumentReceived notification, CancellationToken cancellationToken) { var document = notification.Document; // Get our HelloFile workflow. var workflow = await _workflowRegistry.FindAsync(x => x.Name == "HelloFile" && x.IsPublished, cancellationToken); if (workflow == null) return; // Do nothing. -
sfmskywalker revised this gist
Aug 3, 2021 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,6 @@ using Elsa.Models; using Elsa.Services; using MediatR; namespace DocumentManagement.Workflows.Handlers { @@ -30,6 +29,9 @@ public async Task Handle(NewDocumentReceived notification, CancellationToken can var workflow = await _workflowRegistry.GetAsync("HelloFile", default, VersionOptions.Published, cancellationToken); if (workflow == null) return; // Do nothing. // Dispatch the workflow. await _workflowDispatcher.DispatchAsync(new ExecuteWorkflowDefinitionRequest(workflow!.Id, Input: new WorkflowInput(document.Id)), cancellationToken); } -
sfmskywalker revised this gist
Aug 3, 2021 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,6 @@ using MediatR; using Open.Linq.AsyncExtensions; namespace DocumentManagement.Workflows.Handlers { /// <summary> -
sfmskywalker created this gist
Aug 3, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ using System.Threading; using System.Threading.Tasks; using DocumentManagement.Core.Events; using Elsa.Models; using Elsa.Services; using MediatR; using Open.Linq.AsyncExtensions; namespace DocumentManagement.Workflows.Handlers { /// <summary> /// Handles the <see cref="NewDocumentReceived"/> event by starting the HelloFile workflow. /// </summary> public class StartHelloFileWorkflow : INotificationHandler<NewDocumentReceived> { private readonly IWorkflowRegistry _workflowRegistry; private readonly IWorkflowDefinitionDispatcher _workflowDispatcher; public StartHelloFileWorkflow(IWorkflowRegistry workflowRegistry, IWorkflowDefinitionDispatcher workflowDispatcher) { _workflowRegistry = workflowRegistry; _workflowDispatcher = workflowDispatcher; } public async Task Handle(NewDocumentReceived notification, CancellationToken cancellationToken) { var document = notification.Document; // Get our HelloFile workflow. var workflow = await _workflowRegistry.GetAsync("HelloFile", default, VersionOptions.Published, cancellationToken); // Dispatch the workflow. await _workflowDispatcher.DispatchAsync(new ExecuteWorkflowDefinitionRequest(workflow!.Id, Input: new WorkflowInput(document.Id)), cancellationToken); } } }