Code formatting

This commit is contained in:
Sipke Schoorstra 2021-04-02 16:55:04 +02:00
parent 461e38bb32
commit 9bcc32d15a
3 changed files with 65 additions and 57 deletions

View file

@ -10,13 +10,13 @@ namespace Elsa.Services
/// </summary>
public class WorkflowExecutionContextForWorkflowBlueprintFactory : ICreatesWorkflowExecutionContextForWorkflowBlueprint
{
readonly IServiceProvider serviceProvider;
readonly IWorkflowFactory workflowFactory;
private readonly IServiceProvider _serviceProvider;
private readonly IWorkflowFactory _workflowFactory;
public WorkflowExecutionContextForWorkflowBlueprintFactory(IServiceProvider serviceProvider, IWorkflowFactory workflowFactory)
{
this.serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
this.workflowFactory = workflowFactory ?? throw new ArgumentNullException(nameof(workflowFactory));
_serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
_workflowFactory = workflowFactory ?? throw new ArgumentNullException(nameof(workflowFactory));
}
/// <summary>
@ -27,8 +27,8 @@ namespace Elsa.Services
/// <returns>A task for a workflow execution context</returns>
public async Task<WorkflowExecutionContext> CreateWorkflowExecutionContextAsync(IWorkflowBlueprint workflowBlueprint, CancellationToken cancellationToken = default)
{
var workflowInstance = await workflowFactory.InstantiateAsync(workflowBlueprint, cancellationToken: cancellationToken);
return new WorkflowExecutionContext(serviceProvider, workflowBlueprint, workflowInstance);
var workflowInstance = await _workflowFactory.InstantiateAsync(workflowBlueprint, cancellationToken: cancellationToken);
return new WorkflowExecutionContext(_serviceProvider, workflowBlueprint, workflowInstance);
}
}
}

View file

@ -18,9 +18,10 @@ namespace Elsa.Triggers
readonly IEnumerable<IBookmarkProvider> bookmarkProviders;
readonly ICreatesActivityExecutionContextForActivityBlueprint activityExecutionContextFactory;
public TriggersForActivityBlueprintAndWorkflowProvider(IBookmarkHasher bookmarkHasher,
IEnumerable<IBookmarkProvider> bookmarkProviders,
ICreatesActivityExecutionContextForActivityBlueprint activityExecutionContextFactory)
public TriggersForActivityBlueprintAndWorkflowProvider(
IBookmarkHasher bookmarkHasher,
IEnumerable<IBookmarkProvider> bookmarkProviders,
ICreatesActivityExecutionContextForActivityBlueprint activityExecutionContextFactory)
{
this.bookmarkHasher = bookmarkHasher ?? throw new System.ArgumentNullException(nameof(bookmarkHasher));
this.bookmarkProviders = bookmarkProviders ?? throw new System.ArgumentNullException(nameof(bookmarkProviders));
@ -35,10 +36,11 @@ namespace Elsa.Triggers
/// <param name="activityTypes">A dictionary of all of the activity types (by name)</param>
/// <param name="cancellationToken">An optional cancellation token</param>
/// <returns>A task exposing a collection of workflow triggers for the activity and workflow.</returns>
public async Task<IEnumerable<WorkflowTrigger>> GetTriggersForActivityBlueprintAsync(IActivityBlueprint activityBlueprint,
WorkflowExecutionContext workflowExecutionContext,
IDictionary<string, ActivityType> activityTypes,
CancellationToken cancellationToken = default)
public async Task<IEnumerable<WorkflowTrigger>> GetTriggersForActivityBlueprintAsync(
IActivityBlueprint activityBlueprint,
WorkflowExecutionContext workflowExecutionContext,
IDictionary<string, ActivityType> activityTypes,
CancellationToken cancellationToken = default)
{
var bookmarkProviderContext = GetBookmarkProviderContext(activityBlueprint, workflowExecutionContext, cancellationToken, activityTypes);
var supportedBookmarkProviders = await GetSupportedBookmarkProvidersForContextAsync(bookmarkProviderContext)
@ -46,23 +48,26 @@ namespace Elsa.Triggers
var tasksOfListsOfTriggers = supportedBookmarkProviders
.Select(bookmarkProvider => GetTriggersForBookmarkProvider(bookmarkProvider,
bookmarkProviderContext,
activityBlueprint,
workflowExecutionContext.WorkflowBlueprint,
cancellationToken));
bookmarkProviderContext,
activityBlueprint,
workflowExecutionContext.WorkflowBlueprint,
cancellationToken));
return (await Task.WhenAll(tasksOfListsOfTriggers))
.SelectMany(x => x)
.ToList();
}
BookmarkProviderContext GetBookmarkProviderContext(IActivityBlueprint activity,
WorkflowExecutionContext workflowExecutionContext,
CancellationToken cancellationToken,
IDictionary<string,ActivityType> activityTypes)
private BookmarkProviderContext GetBookmarkProviderContext(
IActivityBlueprint activity,
WorkflowExecutionContext workflowExecutionContext,
CancellationToken cancellationToken,
IDictionary<string, ActivityType> activityTypes)
{
var activityExecutionContext = activityExecutionContextFactory.CreateActivityExecutionContext(activity,
workflowExecutionContext,
cancellationToken);
var activityExecutionContext = activityExecutionContextFactory.CreateActivityExecutionContext(
activity,
workflowExecutionContext,
cancellationToken);
var activityType = activityTypes[activity.Type];
return new BookmarkProviderContext(activityExecutionContext, activityType, BookmarkIndexingMode.WorkflowBlueprint);
}
@ -74,11 +79,12 @@ namespace Elsa.Triggers
yield return provider;
}
async Task<IList<WorkflowTrigger>> GetTriggersForBookmarkProvider(IBookmarkProvider provider,
BookmarkProviderContext context,
IActivityBlueprint activityBlueprint,
IWorkflowBlueprint workflowBlueprint,
CancellationToken cancellationToken = default)
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

View file

@ -15,20 +15,21 @@ namespace Elsa.Triggers
/// </summary>
public class TriggersForBlueprintsProvider : IGetsTriggersForWorkflowBlueprints
{
readonly IActivityTypeService activityTypeService;
readonly ICreatesWorkflowExecutionContextForWorkflowBlueprint workflowExecutionContextFactory;
readonly IGetsTriggersForActivityBlueprintAndWorkflow triggerProvider;
readonly IGetsStartActivitiesForCompositeActivityBlueprint startingActivitiesProvider;
readonly IActivityTypeService _activityTypeService;
readonly ICreatesWorkflowExecutionContextForWorkflowBlueprint _workflowExecutionContextFactory;
readonly IGetsTriggersForActivityBlueprintAndWorkflow _triggerProvider;
readonly IGetsStartActivitiesForCompositeActivityBlueprint _startingActivitiesProvider;
public TriggersForBlueprintsProvider(IActivityTypeService activityTypeService,
ICreatesWorkflowExecutionContextForWorkflowBlueprint workflowExecutionContextFactory,
IGetsTriggersForActivityBlueprintAndWorkflow triggerProvider,
IGetsStartActivitiesForCompositeActivityBlueprint startingActivitiesProvider)
public TriggersForBlueprintsProvider(
IActivityTypeService activityTypeService,
ICreatesWorkflowExecutionContextForWorkflowBlueprint workflowExecutionContextFactory,
IGetsTriggersForActivityBlueprintAndWorkflow triggerProvider,
IGetsStartActivitiesForCompositeActivityBlueprint startingActivitiesProvider)
{
this.activityTypeService = activityTypeService ?? throw new ArgumentNullException(nameof(activityTypeService));
this.workflowExecutionContextFactory = workflowExecutionContextFactory ?? throw new ArgumentNullException(nameof(workflowExecutionContextFactory));
this.triggerProvider = triggerProvider ?? throw new ArgumentNullException(nameof(triggerProvider));
this.startingActivitiesProvider = startingActivitiesProvider ?? throw new ArgumentNullException(nameof(startingActivitiesProvider));
_activityTypeService = activityTypeService ?? throw new ArgumentNullException(nameof(activityTypeService));
_workflowExecutionContextFactory = workflowExecutionContextFactory ?? throw new ArgumentNullException(nameof(workflowExecutionContextFactory));
_triggerProvider = triggerProvider ?? throw new ArgumentNullException(nameof(triggerProvider));
_startingActivitiesProvider = startingActivitiesProvider ?? throw new ArgumentNullException(nameof(startingActivitiesProvider));
}
/// <summary>
@ -37,31 +38,32 @@ namespace Elsa.Triggers
/// <param name="workflowBlueprints">The workflow blueprints for which to get triggers.</param>
/// <param name="cancellationToken">An optional cancellation token.</param>
/// <returns>A task which exposes an enumerable collection of workflow triggers.</returns>
public async Task<IEnumerable<WorkflowTrigger>> GetTriggersAsync(IEnumerable<IWorkflowBlueprint> workflowBlueprints,
CancellationToken cancellationToken = default)
public async Task<IEnumerable<WorkflowTrigger>> GetTriggersAsync(
IEnumerable<IWorkflowBlueprint> workflowBlueprints,
CancellationToken cancellationToken = default)
{
var activityTypes = (await activityTypeService.GetActivityTypesAsync(cancellationToken))
.ToDictionary(x => x.TypeName);
var activityTypes = (await _activityTypeService.GetActivityTypesAsync(cancellationToken)).ToDictionary(x => x.TypeName);
var tasksOfListsOfTriggers = workflowBlueprints.Select(workflowBlueprint => GetWorkflowTriggersForWorkflowBlueprintAsync(workflowBlueprint, activityTypes, cancellationToken));
var tasksOfListsOfTriggers = workflowBlueprints
.Select(workflowBlueprint => GetWorkflowTriggersForWorkflowBlueprintAsync(workflowBlueprint, activityTypes, cancellationToken));
return (await Task.WhenAll(tasksOfListsOfTriggers))
.SelectMany(x => x)
.ToList();
}
async Task<IList<WorkflowTrigger>> GetWorkflowTriggersForWorkflowBlueprintAsync(IWorkflowBlueprint workflowBlueprint,
IDictionary<string, ActivityType> activityTypes,
CancellationToken cancellationToken)
private async Task<IList<WorkflowTrigger>> GetWorkflowTriggersForWorkflowBlueprintAsync(
IWorkflowBlueprint workflowBlueprint,
IDictionary<string, ActivityType> activityTypes,
CancellationToken cancellationToken)
{
var startingActivityBlueprints = startingActivitiesProvider.GetStartActivities(workflowBlueprint);
var workflowExecutionContext = await workflowExecutionContextFactory.CreateWorkflowExecutionContextAsync(workflowBlueprint, cancellationToken);
var startingActivityBlueprints = _startingActivitiesProvider.GetStartActivities(workflowBlueprint);
var workflowExecutionContext = await _workflowExecutionContextFactory.CreateWorkflowExecutionContextAsync(workflowBlueprint, cancellationToken);
var tasksOfCollectionsOfTriggers = startingActivityBlueprints
.Select(async activityBlueprint => await triggerProvider.GetTriggersForActivityBlueprintAsync(activityBlueprint,
workflowExecutionContext,
activityTypes,
cancellationToken));
.Select(async activityBlueprint => await _triggerProvider.GetTriggersForActivityBlueprintAsync(activityBlueprint,
workflowExecutionContext,
activityTypes,
cancellationToken));
return (await Task.WhenAll(tasksOfCollectionsOfTriggers))
.SelectMany(x => x)
.ToList();