Esempio n. 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));
        }
Esempio n. 2
0
        public async Task <IEnumerable <RunWorkflowResult> > StartWorkflowsAsync(
            IEnumerable <TriggerFinderResult> results,
            WorkflowInput?input = default,
            string?contextId    = default,
            CancellationToken cancellationToken = default)
        {
            var runWorkflowResults = new List <RunWorkflowResult>();

            foreach (var result in results)
            {
                var workflowBlueprint = await _workflowRegistry.GetWorkflowAsync(result.WorkflowDefinitionId, VersionOptions.Published, cancellationToken);

                var runWorkflowResult = await StartWorkflowAsync(workflowBlueprint !, result.ActivityId, input, contextId : contextId, cancellationToken : cancellationToken);

                runWorkflowResults.Add(runWorkflowResult);
            }

            return(runWorkflowResults);
        }