예제 #1
0
        /// <inheritdoc/>
        protected override IWorkflowActivityProcessor CreateProcessorFor(V1WorkflowActivity activity)
        {
            IWorkflowActivityProcessor processor         = base.CreateProcessorFor(activity);
            CancellationToken          cancellationToken = this.CancellationTokenSource.Token;

            switch (processor)
            {
            case ConsumeEventProcessor consumeEventProcessor:
                processor.OfType <V1WorkflowActivityCompletedIntegrationEvent>().SubscribeAsync
                (
                    async result => await this.OnEventResultAsync(consumeEventProcessor, result, cancellationToken),
                    async ex => await this.OnErrorAsync(ex, cancellationToken),
                    async() => await this.OnEventCompletedAsync(consumeEventProcessor, cancellationToken)
                );
                break;

            case ActionProcessor actionProcessor:
                processor.OfType <V1WorkflowActivityCompletedIntegrationEvent>().SubscribeAsync
                (
                    async result => await this.OnActionResultAsync(actionProcessor, result, cancellationToken),
                    async ex => await this.OnErrorAsync(ex, cancellationToken),
                    async() => await this.OnActionCompletedAsync(actionProcessor, cancellationToken)
                );
                break;

            default:
                throw new NotSupportedException($"The specified execution pointer type '{processor.GetType().Name}' is not supported in this context");
            }
            return(processor);
        }
예제 #2
0
 /// <inheritdoc/>
 public virtual IWorkflowActivityProcessor Create(V1WorkflowActivity activity)
 {
     if (activity == null)
     {
         throw new ArgumentNullException(nameof(activity));
     }
     if (!activity.Metadata.TryGetValue(V1WorkflowActivityMetadata.State, out var stateName))
     {
         throw new ArgumentException($"The specified activity '{activity.Id}' is missing the required metadata field '{V1WorkflowActivityMetadata.State}'");
     }
     if (!this.Context.Workflow.Definition.TryGetState(stateName, out var state))
     {
         throw new NullReferenceException($"Failed to find the workflow state with the specified name '{stateName}'");
     }
     try
     {
         return(activity.Type switch
         {
             V1WorkflowActivityType.Action => this.CreateActionActivityProcessor(state, activity),
             V1WorkflowActivityType.Branch => this.CreateBranchActivityProcessor(state, activity),
             V1WorkflowActivityType.ConsumeEvent => this.CreateConsumeEventActivityProcessor(activity),
             V1WorkflowActivityType.End => ActivatorUtilities.CreateInstance <EndProcessor>(this.ServiceProvider, activity, state.End ?? new()),
             V1WorkflowActivityType.Error => throw new NotImplementedException(),//todo
             V1WorkflowActivityType.EventTrigger => this.CreateEventStateTriggerActivityProcessor(state, activity),
             V1WorkflowActivityType.Iteration => this.CreateIterationActivityProcessor(state, activity),
             V1WorkflowActivityType.ProduceEvent => this.CreateProduceEventActivityProcessor(activity),
             V1WorkflowActivityType.Start => ActivatorUtilities.CreateInstance <StartProcessor>(this.ServiceProvider, activity, this.Context.Workflow.Definition.Start ?? new()),
             V1WorkflowActivityType.State => this.CreateStateActivityProcessor(state, activity),
             V1WorkflowActivityType.SubFlow => this.CreateSubflowActivityProcessor(state, activity),
             V1WorkflowActivityType.Transition => this.CreateTransitionActivityProcessor(state, activity),
             _ => throw new NotSupportedException($"The specified {typeof(V1WorkflowActivityType).Name} '{activity.Type}' is not supported"),
         });
     }
        /// <inheritdoc/>
        protected override IWorkflowActivityProcessor CreateProcessorFor(V1WorkflowActivity activity)
        {
            var processor         = base.CreateProcessorFor(activity);
            var cancellationToken = this.CancellationTokenSource.Token;

            switch (processor)
            {
            case ProduceEventProcessor produceEventProcessor:
                processor.OfType <V1WorkflowActivityCompletedIntegrationEvent>()
                .SubscribeAsync
                (
                    async result => await this.OnProduceEventResultAsync(result, cancellationToken),
                    async ex => await this.OnErrorAsync(ex, cancellationToken),
                    async() => await this.OnProduceEventCompletedAsync(processor, cancellationToken)
                );
                break;

            case ConsumeEventProcessor consumeEventProcessor:
                processor.SubscribeAsync
                (
                    async result => await this.OnConsumeEventResultAsync(result, cancellationToken),
                    async ex => await this.OnErrorAsync(ex, cancellationToken),
                    async() => await this.OnConsumeEventCompletedAsync(processor, cancellationToken)
                );
                break;

            default:
                processor.Dispose();
                throw new NotSupportedException($"The specified {nameof(IWorkflowActivityProcessor)} '{processor.GetType()}' is not supported");
            }
            return(processor);
        }
예제 #4
0
 /// <summary>
 /// Initializes a new <see cref="WorkflowActivityProcessor"/>
 /// </summary>
 /// <param name="serviceProvider">The current <see cref="IServiceProvider"/></param>
 /// <param name="loggerFactory">The service used to create <see cref="ILogger"/>s</param>
 /// <param name="context">The current <see cref="IWorkflowRuntimeContext"/></param>
 /// <param name="activityProcessorFactory">The service used to create <see cref="IWorkflowActivityProcessor"/>s</param>
 /// <param name="options">The service used to access the current <see cref="ApplicationOptions"/></param>
 /// <param name="activity">The <see cref="V1WorkflowActivity"/> to process</param>
 /// <param name="action">The <see cref="ActionDefinition"/> to process</param>
 /// <param name="function">The <see cref="FunctionDefinition"/> to process</param>
 public FunctionProcessor(IServiceProvider serviceProvider, ILoggerFactory loggerFactory, IWorkflowRuntimeContext context, IWorkflowActivityProcessorFactory activityProcessorFactory,
                          IOptions <ApplicationOptions> options, V1WorkflowActivity activity, ActionDefinition action, FunctionDefinition function)
     : base(loggerFactory, context, activityProcessorFactory, options, activity, action)
 {
     this.ServiceProvider = serviceProvider;
     this.Function        = function;
 }
예제 #5
0
 /// <summary>
 /// Initializes a new <see cref="TransitionProcessor"/>
 /// </summary>
 /// <param name="loggerFactory">The service used to create <see cref="ILogger"/>s</param>
 /// <param name="context">The current <see cref="IWorkflowRuntimeContext"/></param>
 /// <param name="activityProcessorFactory">The service used to create <see cref="IWorkflowActivityProcessor"/>s</param>
 /// <param name="options">The service used to access the current <see cref="ApplicationOptions"/></param>
 /// <param name="activity">The <see cref="V1WorkflowActivity"/> to process</param>
 /// <param name="state">The <see cref="StateDefinition"/> to process the transition of</param>
 /// <param name="transition">The <see cref="TransitionDefinition"/> to process</param>
 public TransitionProcessor(ILoggerFactory loggerFactory, IWorkflowRuntimeContext context, IWorkflowActivityProcessorFactory activityProcessorFactory,
                            IOptions <ApplicationOptions> options, V1WorkflowActivity activity, StateDefinition state, TransitionDefinition transition)
     : base(loggerFactory, context, activityProcessorFactory, options, activity)
 {
     this.State      = state;
     this.Transition = transition;
 }
예제 #6
0
 /// <summary>
 /// Initializes a new <see cref="WorkflowActivityProcessor"/>
 /// </summary>
 /// <param name="loggerFactory">The service used to create <see cref="ILogger"/>s</param>
 /// <param name="context">The current <see cref="IWorkflowRuntimeContext"/></param>
 /// <param name="activityProcessorFactory">The service used to create <see cref="IWorkflowActivityProcessor"/>s</param>
 /// <param name="jsonSerializer">The service used to serialize/deserialize to/from JSON</param>
 /// <param name="options">The service used to access the current <see cref="ApplicationOptions"/></param>
 /// <param name="activity">The <see cref="V1WorkflowActivity"/> to process</param>
 /// <param name="state">The <see cref="EventStateDefinition"/> to process</param>
 /// <param name="trigger">The <see cref="EventStateTriggerDefinition"/> to process</param>
 public EventStateTriggerProcessor(ILoggerFactory loggerFactory, IWorkflowRuntimeContext context, IWorkflowActivityProcessorFactory activityProcessorFactory, IJsonSerializer jsonSerializer,
                                   IOptions <ApplicationOptions> options, V1WorkflowActivity activity, EventStateDefinition state, EventStateTriggerDefinition trigger)
     : base(loggerFactory, context, activityProcessorFactory, options, activity)
 {
     this.JsonSerializer = jsonSerializer;
     this.State          = state;
     this.Trigger        = trigger;
 }
예제 #7
0
 /// <inheritdoc/>
 public virtual async Task CancelActivityAsync(V1WorkflowActivity activity, CancellationToken cancellationToken = default)
 {
     if (activity == null)
     {
         throw new ArgumentNullException(nameof(activity));
     }
     await this.SynapseRuntimeApi.CancelActivityAsync(activity.Id, cancellationToken);
 }
예제 #8
0
 /// <inheritdoc/>
 public virtual async Task SetActivityMetadataAsync(V1WorkflowActivity activity, CancellationToken cancellationToken = default)
 {
     if (activity == null)
     {
         throw new ArgumentNullException(nameof(activity));
     }
     await this.SynapseRuntimeApi.SetActivityMetadataAsync(new() { Id = activity.Id, Metadata = activity.Metadata }, cancellationToken);
 }
 /// <summary>
 /// Initializes a new <see cref="AsyncFunctionProcessor"/>
 /// </summary>
 /// <param name="loggerFactory">The service used to create <see cref="ILogger"/>s</param>
 /// <param name="context">The current <see cref="IWorkflowRuntimeContext"/></param>
 /// <param name="activityProcessorFactory">The service used to create <see cref="IWorkflowActivityProcessor"/>s</param>
 /// <param name="options">The service used to access the current <see cref="ApplicationOptions"/></param>
 /// <param name="activity">The <see cref="V1WorkflowActivity"/> to process</param>
 /// <param name="state">The <see cref="StateDefinition"/> the <see cref="EventReference"/> to process belongs to</param>
 /// <param name="action">The <see cref="ActionDefinition"/> to process</param>
 /// <param name="triggerEvent">The <see cref="EventDefinition"/> that defines the <see cref="CloudEvent"/> to produce, thus triggering the async call</param>
 /// <param name="resultEvent">The <see cref="EventDefinition"/> that defines the <see cref="CloudEvent"/> to consume, thus ending the async call</param>
 public AsyncFunctionProcessor(ILoggerFactory loggerFactory, IWorkflowRuntimeContext context, IWorkflowActivityProcessorFactory activityProcessorFactory,
                               IOptions <ApplicationOptions> options, V1WorkflowActivity activity, StateDefinition state, ActionDefinition action, EventDefinition triggerEvent, EventDefinition resultEvent)
     : base(loggerFactory, context, activityProcessorFactory, options, activity, action)
 {
     this.State        = state;
     this.TriggerEvent = triggerEvent;
     this.ResultEvent  = resultEvent;
 }
예제 #10
0
 /// <summary>
 /// Resumes the execution of the workflow from the <see cref="EndDefinition"/>
 /// </summary>
 /// <param name="activity">The <see cref="V1WorkflowActivity"/> to resume from</param>
 /// <returns>A new awaitable <see cref="Task"/></returns>
 protected virtual async Task ResumeFromEndAsync(V1WorkflowActivity activity)
 {
     if (activity == null)
     {
         throw new ArgumentNullException(nameof(activity));
     }
     await this.Context.Workflow.SetOutputAsync(activity.Output, this.CancellationToken);
 }
예제 #11
0
 /// <summary>
 /// Resumes the execution of the workflow from the <see cref="StartDefinition"/>
 /// </summary>
 /// <param name="activity">The <see cref="V1WorkflowActivity"/> to resume from</param>
 /// <returns>A new awaitable <see cref="Task"/></returns>
 protected virtual Task ResumeFromStartAsync(V1WorkflowActivity activity)
 {
     if (activity == null)
     {
         throw new ArgumentNullException(nameof(activity));
     }
     //todo: implement
     throw new NotImplementedException();
 }
예제 #12
0
        /// <summary>
        /// Resumes the execution of the workflow from the specified <see cref="TransitionDefinition"/>
        /// </summary>
        /// <param name="activity">The <see cref="V1WorkflowActivity"/> to resume from</param>
        /// <returns>A new awaitable <see cref="Task"/></returns>
        protected virtual async Task ResumeFromTransitionAsync(V1WorkflowActivity activity)
        {
            if (activity == null)
            {
                throw new ArgumentNullException(nameof(activity));
            }
            if (!activity.Metadata.TryGetValue(V1WorkflowActivityMetadata.State, out var stateName))
            {
                throw new ArgumentException($"The specified activity '{activity.Id}' is missing the required metadata field '{V1WorkflowActivityMetadata.State}'");
            }
            if (!this.Context.Workflow.Definition.TryGetState(stateName, out var state))
            {
                throw new NullReferenceException($"Failed to find the workflow state with the specified name '{stateName}'");
            }
            TransitionDefinition transition;

            if (state is SwitchStateDefinition @switch)
            {
                if (!activity.Metadata.TryGetValue(V1WorkflowActivityMetadata.Case, out var caseName))
                {
                    throw new ArgumentException($"The specified activity '{activity.Id}' is missing the required metadata field '{V1WorkflowActivityMetadata.Case}'");
                }
                if ([email protected](caseName, out SwitchCaseDefinition dataCondition))
                {
                    throw new NullReferenceException($"Failed to find a condition with the specified name '{caseName}'");
                }
                transition = dataCondition.Transition !;
                if (transition == null)
                {
                    transition = new() { NextState = dataCondition.TransitionToStateName ! }
                }
                ;
            }
            else
            {
                transition = state.Transition !;
                if (transition == null)
                {
                    transition = new() { NextState = state.TransitionToStateName ! }
                }
                ;
            }
            if (!this.Context.Workflow.Definition.TryGetState(transition.NextState, out StateDefinition nextState))
            {
                throw new NullReferenceException($"Failed to find a state with name '{transition.NextState}' in workflow '{this.Context.Workflow.Definition.Id} {this.Context.Workflow.Definition.Version}'");
            }
            await this.Context.Workflow.TransitionToAsync(nextState, this.CancellationToken);

            var metadata = new Dictionary <string, string>()
            {
                { V1WorkflowActivityMetadata.State, nextState.Name }
            };
            var nextActivity = await this.Context.Workflow.CreateActivityAsync(V1WorkflowActivityType.State, activity.Output, metadata, null, this.CancellationToken);

            var processor = this.CreateActivityProcessor(nextActivity);
            await processor.ProcessAsync(this.CancellationToken);
        }
예제 #13
0
 /// <inheritdoc/>
 public virtual async Task FaultActivityAsync(V1WorkflowActivity activity, Integration.Models.Error error, CancellationToken cancellationToken = default)
 {
     if (activity == null)
     {
         throw new ArgumentNullException(nameof(activity));
     }
     if (error == null)
     {
         throw new ArgumentNullException(nameof(error));
     }
     await this.SynapseRuntimeApi.FaultActivityAsync(new() { Id = activity.Id, Error = error }, cancellationToken);;
 }
예제 #14
0
        /// <inheritdoc/>
        protected override IWorkflowActivityProcessor CreateProcessorFor(V1WorkflowActivity activity)
        {
            var processor = (ActionProcessor)base.CreateProcessorFor(activity);

            processor.SubscribeAsync
            (
                async e => await this.OnNextActionAsync(processor, e),
                async ex => await this.OnActionFaultedAsync(processor, ex),
                async() => await this.OnActionCompletedAsync(processor)
            );
            return(processor);
        }
        /// <inheritdoc/>
        protected override IWorkflowActivityProcessor CreateProcessorFor(V1WorkflowActivity activity)
        {
            var processor = (EventStateTriggerProcessor)base.CreateProcessorFor(activity);

            processor.OfType <V1WorkflowActivityCompletedIntegrationEvent>().SubscribeAsync
            (
                async result => await this.OnTriggerResultAsync(processor, result, this.CancellationTokenSource.Token),
                async ex => await this.OnErrorAsync(ex, this.CancellationTokenSource.Token),
                async() => await this.OnTriggerCompletedAsync(processor, this.CancellationTokenSource.Token)
            );
            return(processor);
        }
        /// <inheritdoc/>
        protected override IWorkflowActivityProcessor CreateProcessorFor(V1WorkflowActivity activity)
        {
            var cancellationToken = this.CancellationTokenSource.Token;
            var processor         = (BranchProcessor)base.CreateProcessorFor(activity);

            processor.OfType <V1WorkflowActivityCompletedIntegrationEvent>().SubscribeAsync
            (
                async e => await this.OnBranchExecutedAsync(processor, e, cancellationToken),
                async ex => await this.OnErrorAsync(ex, cancellationToken),
                async() => await this.OnBranchCompletedAsync(processor, cancellationToken)
            );
            return(processor);
        }
예제 #17
0
        public static IWorkflowNodeViewModel?GetNodeFor(this IGraphViewModel graph, V1WorkflowActivity activity)
        {
            if (activity == null)
            {
                return(null);
            }
            switch (activity.Type)
            {
            case V1WorkflowActivityType.Action:
                return(graph.GetActionNodeFor(activity));

            case V1WorkflowActivityType.Function:
                return(graph.GetActionNodeFor(activity));

            case V1WorkflowActivityType.Transition:
                return(graph.GetTransitionNodeFor(activity));

            case V1WorkflowActivityType.Branch:
                throw new NotImplementedException();     //todo

            case V1WorkflowActivityType.ConsumeEvent:
                throw new NotImplementedException();     //todo

            case V1WorkflowActivityType.End:
                return(graph.Nodes.Values.OfType <EndNodeViewModel>().FirstOrDefault());

            case V1WorkflowActivityType.Error:
                throw new NotImplementedException();     //todo

            case V1WorkflowActivityType.EventTrigger:
                throw new NotImplementedException();     //todo

            case V1WorkflowActivityType.Iteration:
                throw new NotImplementedException();     //todo

            case V1WorkflowActivityType.ProduceEvent:
                throw new NotImplementedException();     //todo

            case V1WorkflowActivityType.Start:
                return(graph.Nodes.Values.OfType <StartNodeViewModel>().FirstOrDefault());

            case V1WorkflowActivityType.State:
                return(graph.GetStateNodeFor(activity));

            case V1WorkflowActivityType.SubFlow:
                throw new NotImplementedException();     //todo

            default:
                return(null);
            }
        }
예제 #18
0
        /// <inheritdoc/>
        public virtual async Task SetActivityOutputAsync(V1WorkflowActivity activity, object?output, CancellationToken cancellationToken = default)
        {
            if (activity == null)
            {
                throw new ArgumentNullException(nameof(activity));
            }
            var outputParam = output as Dynamic;

            if (outputParam == null && output != null)
            {
                outputParam = Dynamic.FromObject(output);
            }
            await this.SynapseRuntimeApi.SetActivityOutputAsync(new() { Id = activity.Id, Output = outputParam }, cancellationToken);
        }
예제 #19
0
 /// <inheritdoc/>
 public virtual async Task FaultActivityAsync(V1WorkflowActivity activity, Exception ex, CancellationToken cancellationToken = default)
 {
     if (activity == null)
     {
         throw new ArgumentNullException(nameof(activity));
     }
     if (ex == null)
     {
         throw new ArgumentNullException(nameof(ex));
     }
     await this.FaultActivityAsync(activity, new Integration.Models.Error()
     {
         Code = ex.GetType().Name.Replace("exception", string.Empty, StringComparison.OrdinalIgnoreCase), Message = ex.Message
     }, cancellationToken);
 }
예제 #20
0
        /// <inheritdoc/>
        public virtual async Task On(V1WorkflowActivity activity, IV1WorkflowActivityIntegrationEvent e, CancellationToken cancellationToken = default)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }
            switch (e)
            {
            case V1WorkflowActivityStartedIntegrationEvent:
            case V1WorkflowActivityResumedIntegrationEvent:
                await this.StartOrResumeActivityAsync(activity, cancellationToken);

                break;

            case V1WorkflowActivitySuspendedIntegrationEvent:
                await this.SuspendActivityAsync(activity, cancellationToken);

                break;

            case V1WorkflowActivitySkippedIntegrationEvent:
                await this.SkipActivityAsync(activity, cancellationToken);

                break;

            case V1WorkflowActivityFaultedIntegrationEvent faultedEvent:
                await this.FaultActivityAsync(activity, faultedEvent.Error, cancellationToken);

                break;

            case V1WorkflowActivityCancelledIntegrationEvent:
                await this.CancelActivityAsync(activity, cancellationToken);

                break;

            case V1WorkflowActivityCompletedIntegrationEvent completedEvent:
                await this.SetActivityOutputAsync(activity, completedEvent.Output, cancellationToken);

                break;

            default:
                throw new NotSupportedException($"The specified workflow activity integration event type '{e.GetType().Name}' is not supported in this context");
            }
        }
예제 #21
0
        /// <summary>
        /// Creates a new child <see cref="IWorkflowActivityProcessor"/> for the specified <see cref="V1WorkflowActivity"/>
        /// </summary>
        /// <param name="activity">The <see cref="V1WorkflowActivity"/> to create a child <see cref="IWorkflowActivityProcessor"/> for</param>
        protected virtual IWorkflowActivityProcessor CreateActivityProcessor(V1WorkflowActivity activity)
        {
            if (activity == null)
            {
                throw new ArgumentNullException(nameof(activity));
            }
            IWorkflowActivityProcessor processor = this.ActivityProcessorFactory.Create(activity);

            switch (processor)
            {
            case IStateProcessor stateProcessor:
                processor.OfType <V1WorkflowActivityCompletedIntegrationEvent>().SubscribeAsync
                (
                    async e => await this.OnStateCompletedAsync(stateProcessor, e),
                    async ex => await this.OnActivityProcessingErrorAsync(stateProcessor, ex),
                    async() => await this.OnActivityProcessingCompletedAsync(stateProcessor)
                );
                break;

            case ITransitionProcessor transitionProcessor:
                processor.OfType <V1WorkflowActivityCompletedIntegrationEvent>().SubscribeAsync
                (
                    async e => await this.OnTransitionCompletedAsync(transitionProcessor, e),
                    async ex => await this.OnActivityProcessingErrorAsync(transitionProcessor, ex),
                    async() => await this.OnActivityProcessingCompletedAsync(transitionProcessor)
                );
                break;

            case IEndProcessor endProcessor:
                processor.OfType <V1WorkflowActivityCompletedIntegrationEvent>().SubscribeAsync
                (
                    async e => await this.OnEndCompletedAsync(endProcessor, e),
                    async ex => await this.OnActivityProcessingErrorAsync(endProcessor, ex),
                    async() => await this.OnCompletedAsync(endProcessor)
                );
                break;
            }
            this.Processors.Add(processor);
            return(processor);
        }
예제 #22
0
        /// <summary>
        /// Resumes the execution of the workflow from the specified <see cref="StateDefinition"/>
        /// </summary>
        /// <param name="activity">The <see cref="V1WorkflowActivity"/> to resume from</param>
        /// <returns>A new awaitable <see cref="Task"/></returns>
        protected virtual async Task ResumeFromStateAsync(V1WorkflowActivity activity)
        {
            if (activity == null)
            {
                throw new ArgumentNullException(nameof(activity));
            }
            if (!activity.Metadata.TryGetValue(V1WorkflowActivityMetadata.State, out var stateName))
            {
                throw new ArgumentException($"The specified activity '{activity.Id}' is missing the required metadata field '{V1WorkflowActivityMetadata.State}'");
            }
            if (!this.Context.Workflow.Definition.TryGetState(stateName, out var state))
            {
                throw new NullReferenceException($"Failed to find the workflow state with the specified name '{stateName}'");
            }
            V1WorkflowActivity nextActivity;
            var metadata = new Dictionary <string, string>()
            {
                { V1WorkflowActivityMetadata.State, state.Name }
            };

            if (state.Transition != null ||
                !string.IsNullOrWhiteSpace(state.TransitionToStateName))
            {
                nextActivity = await this.Context.Workflow.CreateActivityAsync(V1WorkflowActivityType.Transition, activity.Output !.ToObject() !, metadata, null, this.CancellationToken);
            }
            else if (state.End != null ||
                     state.IsEnd)
            {
                nextActivity = await this.Context.Workflow.CreateActivityAsync(V1WorkflowActivityType.End, activity.Output !.ToObject() !, metadata, null, this.CancellationToken);
            }
            else
            {
                throw new InvalidOperationException($"The state '{state.Name}' must declare a transition definition or an end definition for it is part of the main execution logic of the workflow '{this.Context.Workflow.Definition.Id}'");
            }
            var processor = this.CreateActivityProcessor(nextActivity);
            await processor.ProcessAsync(this.CancellationToken);
        }
예제 #23
0
        private static IWorkflowNodeViewModel?GetTransitionNodeFor(this IGraphViewModel graph, V1WorkflowActivity activity)
        {
            var stateNode = (StateNodeViewModel)graph.GetStateNodeFor(activity) !;

            if (!activity.Metadata.TryGetValue("case", out var caseName))
            {
                return(null);
            }
            return(stateNode.Children.Values.OfType <DataCaseNodeViewModel>().FirstOrDefault(node => node != null && node.DataCaseName == caseName));
        }
예제 #24
0
        private static IWorkflowNodeViewModel?GetActionNodeFor(this IGraphViewModel graph, V1WorkflowActivity activity)
        {
            var stateNode = (StateNodeViewModel)graph.GetStateNodeFor(activity) !;

            if (!activity.Metadata.TryGetValue("action", out var actionName))
            {
                throw new InvalidDataException($"The specified activity's metadata does not define a 'action' value");
            }
            return(stateNode.Children.Values.Where(node => typeof(IActionNodeViewModel).IsAssignableFrom(node.GetType())).Select(node => node as IActionNodeViewModel).FirstOrDefault(node => node != null && node.Action.Name == actionName));
        }
예제 #25
0
 private static IWorkflowNodeViewModel?GetStateNodeFor(this IGraphViewModel graph, V1WorkflowActivity activity)
 {
     if (!activity.Metadata.TryGetValue("state", out var stateName))
     {
         throw new InvalidDataException($"The specified activity's metadata does not define a 'state' value");
     }
     return(graph.Clusters.Values.OfType <StateNodeViewModel>().FirstOrDefault(g => g.State.Name == stateName));
 }
예제 #26
0
 public AddV1WorkflowActivity(V1WorkflowActivity workflowActivity)
 {
     this.WorkflowActivity = workflowActivity;
 }
 /// <summary>
 /// Initializes a new <see cref="WorkflowActivityProcessor"/>
 /// </summary>
 /// <param name="loggerFactory">The service used to create <see cref="ILogger"/>s</param>
 /// <param name="context">The current <see cref="IWorkflowRuntimeContext"/></param>
 /// <param name="activityProcessorFactory">The service used to create <see cref="IWorkflowActivityProcessor"/>s</param>
 /// <param name="integrationEventBus">The service used to publish and subscribe to integration events</param>
 /// <param name="options">The service used to access the current <see cref="ApplicationOptions"/></param>
 /// <param name="activity">The <see cref="V1WorkflowActivity"/> to process</param>
 /// <param name="eventDefinition">The <see cref="ServerlessWorkflow.Sdk.Models.EventDefinition"/> that defines the <see cref="V1Event"/> to consume</param>
 public ConsumeEventProcessor(ILoggerFactory loggerFactory, IWorkflowRuntimeContext context, IWorkflowActivityProcessorFactory activityProcessorFactory,
                              IIntegrationEventBus integrationEventBus, IOptions <ApplicationOptions> options, V1WorkflowActivity activity, EventDefinition eventDefinition)
     : base(loggerFactory, context, activityProcessorFactory, options, activity)
 {
     this.IntegrationEventBus = integrationEventBus;
     this.EventDefinition     = eventDefinition;
 }
예제 #28
0
 /// <inheritdoc/>
 public ForEachStateProcessor(ILoggerFactory loggerFactory, IWorkflowRuntimeContext context, IWorkflowActivityProcessorFactory activityProcessorFactory,
                              IOptions <ApplicationOptions> options, V1WorkflowActivity activity, ForEachStateDefinition state)
     : base(loggerFactory, context, activityProcessorFactory, options, activity, state)
 {
 }
예제 #29
0
 /// <summary>
 /// Initializes a new <see cref="WorkflowActivityProcessor"/>
 /// </summary>
 /// <param name="loggerFactory">The service used to create <see cref="ILogger"/>s</param>
 /// <param name="context">The current <see cref="IWorkflowRuntimeContext"/></param>
 /// <param name="activityProcessorFactory">The service used to create <see cref="IWorkflowActivityProcessor"/>s</param>
 /// <param name="jsonSerializer">The service used to serialize/deserialize to/from JSON</param>
 /// <param name="options">The service used to access the current <see cref="ApplicationOptions"/></param>
 /// <param name="activity">The <see cref="V1WorkflowActivity"/> to process</param>
 /// <param name="state">The <see cref="ParallelStateDefinition"/> that defines the <see cref="BranchDefinition"/> to process</param>
 /// <param name="branch">The <see cref="BranchDefinition"/> to process</param>
 public BranchProcessor(ILoggerFactory loggerFactory, IWorkflowRuntimeContext context, IWorkflowActivityProcessorFactory activityProcessorFactory,
                        IJsonSerializer jsonSerializer, IOptions <ApplicationOptions> options, V1WorkflowActivity activity, ParallelStateDefinition state, BranchDefinition branch)
     : base(loggerFactory, context, activityProcessorFactory, options, activity)
 {
     this.JsonSerializer = jsonSerializer;
     this.State          = state;
     this.Branch         = branch;
 }
예제 #30
0
 /// <summary>
 /// Initializes a new <see cref="ODataFunctionProcessor"/>
 /// </summary>
 /// <param name="serviceProvider">The current <see cref="IServiceProvider"/></param>
 /// <param name="loggerFactory">The service used to create <see cref="ILogger"/>s</param>
 /// <param name="context">The current <see cref="IWorkflowRuntimeContext"/></param>
 /// <param name="activityProcessorFactory">The service used to create <see cref="IWorkflowActivityProcessor"/>s</param>
 /// <param name="httpClientFactory">The service used to create <see cref="System.Net.Http.HttpClient"/>s</param>
 /// <param name="serializerProvider">The service used to provide <see cref="ISerializer"/>s</param>
 /// <param name="oauth2TokenManager">The service used to manahge <see cref="OAuth2Token"/>s</param>
 /// <param name="options">The service used to access the current <see cref="ApplicationOptions"/></param>
 /// <param name="activity">The <see cref="V1WorkflowActivity"/> to process</param>
 /// <param name="action">The <see cref="ActionDefinition"/> to process</param>
 /// <param name="function">The <see cref="FunctionDefinition"/> to process</param>
 public ODataFunctionProcessor(IServiceProvider serviceProvider, ILoggerFactory loggerFactory, IWorkflowRuntimeContext context, IWorkflowActivityProcessorFactory activityProcessorFactory,
                               IHttpClientFactory httpClientFactory, ISerializerProvider serializerProvider, IOptions <ApplicationOptions> options, V1WorkflowActivity activity,
                               ActionDefinition action, FunctionDefinition function)
     : base(serviceProvider, loggerFactory, context, activityProcessorFactory, options, activity, action, function)
 {
     this.HttpClient         = httpClientFactory.CreateClient();
     this.SerializerProvider = serializerProvider;
 }