Beispiel #1
0
        private async Task <ScheduledActivity> GetActivityToScheduleAsync(WorkflowInstance workflowInstance, CancellationToken cancellationToken)
        {
            var currentActivity = workflowInstance.CurrentActivity;

            if (currentActivity != null)
            {
                return(currentActivity);
            }

            var workflowBlueprint = await _workflowRegistry.GetWorkflowAsync(workflowInstance.DefinitionId, VersionOptions.SpecificVersion(workflowInstance.Version), cancellationToken);

            if (workflowBlueprint == null)
            {
                throw new WorkflowException($"Could not find associated workflow definition {workflowInstance.DefinitionId} with version {workflowInstance.Version}");
            }

            var startActivity = _startingActivitiesProvider.GetStartActivities(workflowBlueprint).FirstOrDefault();

            if (startActivity == null)
            {
                throw new WorkflowException($"Cannot revive workflow {workflowInstance.Id} because it has no start activities");
            }

            return(new ScheduledActivity(startActivity.Id));
        }
Beispiel #2
0
        private void BuildCompositeActivities(
            IEnumerable <IActivityBuilder> compositeActivityBuilders,
            ICollection <IActivityBlueprint> activityBlueprints,
            ICollection <IConnection> connections,
            IDictionary <string, IDictionary <string, IActivityPropertyValueProvider> > activityPropertyProviders)
        {
            using var scope = ServiceProvider.CreateScope();
            foreach (var activityBuilder in compositeActivityBuilders)
            {
                var compositeActivity        = (CompositeActivity)ActivatorUtilities.CreateInstance(scope.ServiceProvider, activityBuilder.ActivityType);
                var compositeActivityBuilder = _compositeActivityBuilderFactory();
                compositeActivityBuilder.ActivityId = activityBuilder.ActivityId;
                compositeActivity.Build(compositeActivityBuilder);

                var compositeActivityBlueprint = compositeActivityBuilder.Build($"{activityBuilder.ActivityId}:activity");
                var activityDictionary         = compositeActivityBlueprint.Activities.ToDictionary(x => x.Id);

                activityBlueprints.AddRange(compositeActivityBlueprint.Activities);
                connections.AddRange(compositeActivityBlueprint.Connections.Select(x => new Connection(activityDictionary[x.Source.Activity.Id], activityDictionary[x.Target.Activity.Id], x.Source.Outcome)));
                activityPropertyProviders.AddRange(compositeActivityBlueprint.ActivityPropertyProviders);

                compositeActivityBlueprint.Activities  = compositeActivityBlueprint.Activities;
                compositeActivityBlueprint.Connections = compositeActivityBlueprint.Connections;
                compositeActivityBlueprint.ActivityPropertyProviders = compositeActivityBlueprint.ActivityPropertyProviders;

                // Connect the composite activity to its starting activities.
                var startActivities = _startingActivitiesProvider.GetStartActivities(compositeActivityBlueprint).ToList();
                connections.AddRange(startActivities.Select(x => new Connection(compositeActivityBlueprint, x, CompositeActivity.Enter)));
            }
        }
Beispiel #3
0
        private async Task <bool> BeginWorkflow(WorkflowExecutionContext workflowExecutionContext, IActivityBlueprint?activity, object?input, CancellationToken cancellationToken)
        {
            if (activity == null)
            {
                activity = _startingActivitiesProvider.GetStartActivities(workflowExecutionContext.WorkflowBlueprint).FirstOrDefault() ?? workflowExecutionContext.WorkflowBlueprint.Activities.First();
            }

            if (!await CanExecuteAsync(workflowExecutionContext, activity, input, false, cancellationToken))
            {
                return(false);
            }

            workflowExecutionContext.Begin();
            workflowExecutionContext.ScheduleActivity(activity.Id, input);
            await RunAsync(workflowExecutionContext, Execute, cancellationToken);

            return(true);
        }
Beispiel #4
0
        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 tasksOfCollectionsOfTriggers = startingActivityBlueprints
                                               .Select(async activityBlueprint => await _triggerProvider.GetTriggersForActivityBlueprintAsync(activityBlueprint,
                                                                                                                                              workflowExecutionContext,
                                                                                                                                              activityTypes,
                                                                                                                                              cancellationToken));

            return((await Task.WhenAll(tasksOfCollectionsOfTriggers))
                   .SelectMany(x => x)
                   .ToList());
        }
 public static IEnumerable <IActivityBlueprint> GetStartActivities <T>(this IGetsStartActivitiesForCompositeActivityBlueprint startActivitiesProvider,
                                                                       ICompositeActivityBlueprint workflowBlueprint) where T : IActivity
 => startActivitiesProvider.GetStartActivities(workflowBlueprint, typeof(T));
 public static IEnumerable <IActivityBlueprint> GetStartActivities(this IGetsStartActivitiesForCompositeActivityBlueprint startActivitiesProvider,
                                                                   ICompositeActivityBlueprint workflowBlueprint,
                                                                   Type activityType)
 => startActivitiesProvider.GetStartActivities(workflowBlueprint, activityType.Name);
 public static IEnumerable <IActivityBlueprint> GetStartActivities(this IGetsStartActivitiesForCompositeActivityBlueprint startActivitiesProvider,
                                                                   ICompositeActivityBlueprint workflowBlueprint,
                                                                   string activityType)
 => startActivitiesProvider.GetStartActivities(workflowBlueprint).Where(x => x.Type == activityType);